mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-18 10:37:29 -06:00
[feature] Option to hide followers/following (#2788)
This commit is contained in:
parent
29972e2c93
commit
f05874be30
19 changed files with 322 additions and 83 deletions
|
|
@ -31,11 +31,25 @@ import (
|
|||
// FollowersGet fetches a list of the target account's followers.
|
||||
func (p *Processor) FollowersGet(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string, page *paging.Page) (*apimodel.PageableResponse, gtserror.WithCode) {
|
||||
// Fetch target account to check it exists, and visibility of requester->target.
|
||||
_, errWithCode := p.c.GetVisibleTargetAccount(ctx, requestingAccount, targetAccountID)
|
||||
targetAccount, errWithCode := p.c.GetVisibleTargetAccount(ctx, requestingAccount, targetAccountID)
|
||||
if errWithCode != nil {
|
||||
return nil, errWithCode
|
||||
}
|
||||
|
||||
if targetAccount.IsInstance() {
|
||||
// Instance accounts can't follow/be followed.
|
||||
return paging.EmptyResponse(), nil
|
||||
}
|
||||
|
||||
// If account isn't requesting its own followers list,
|
||||
// but instead the list for a local account that has
|
||||
// hide_followers set, just return an empty array.
|
||||
if targetAccountID != requestingAccount.ID &&
|
||||
targetAccount.IsLocal() &&
|
||||
*targetAccount.Settings.HideCollections {
|
||||
return paging.EmptyResponse(), nil
|
||||
}
|
||||
|
||||
follows, err := p.state.DB.GetAccountFollowers(ctx, targetAccountID, page)
|
||||
if err != nil && !errors.Is(err, db.ErrNoEntries) {
|
||||
err = gtserror.Newf("db error getting followers: %w", err)
|
||||
|
|
@ -76,11 +90,25 @@ func (p *Processor) FollowersGet(ctx context.Context, requestingAccount *gtsmode
|
|||
// FollowingGet fetches a list of the accounts that target account is following.
|
||||
func (p *Processor) FollowingGet(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string, page *paging.Page) (*apimodel.PageableResponse, gtserror.WithCode) {
|
||||
// Fetch target account to check it exists, and visibility of requester->target.
|
||||
_, errWithCode := p.c.GetVisibleTargetAccount(ctx, requestingAccount, targetAccountID)
|
||||
targetAccount, errWithCode := p.c.GetVisibleTargetAccount(ctx, requestingAccount, targetAccountID)
|
||||
if errWithCode != nil {
|
||||
return nil, errWithCode
|
||||
}
|
||||
|
||||
if targetAccount.IsInstance() {
|
||||
// Instance accounts can't follow/be followed.
|
||||
return paging.EmptyResponse(), nil
|
||||
}
|
||||
|
||||
// If account isn't requesting its own following list,
|
||||
// but instead the list for a local account that has
|
||||
// hide_followers set, just return an empty array.
|
||||
if targetAccountID != requestingAccount.ID &&
|
||||
targetAccount.IsLocal() &&
|
||||
*targetAccount.Settings.HideCollections {
|
||||
return paging.EmptyResponse(), nil
|
||||
}
|
||||
|
||||
// Fetch known accounts that follow given target account ID.
|
||||
follows, err := p.state.DB.GetAccountFollows(ctx, targetAccountID, page)
|
||||
if err != nil && !errors.Is(err, db.ErrNoEntries) {
|
||||
|
|
|
|||
|
|
@ -284,6 +284,10 @@ func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, form
|
|||
account.Settings.EnableRSS = form.EnableRSS
|
||||
}
|
||||
|
||||
if form.HideCollections != nil {
|
||||
account.Settings.HideCollections = form.HideCollections
|
||||
}
|
||||
|
||||
if err := p.state.DB.UpdateAccount(ctx, account); err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(fmt.Errorf("could not update account %s: %s", account.ID, err))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,15 +140,25 @@ func (p *Processor) FollowersGet(ctx context.Context, requestedUser string, page
|
|||
params.ID = collectionID
|
||||
params.Total = total
|
||||
|
||||
if page == nil {
|
||||
switch {
|
||||
|
||||
case receiver.IsInstance() ||
|
||||
*receiver.Settings.HideCollections:
|
||||
// Instance account (can't follow/be followed),
|
||||
// or an account that hides followers/following.
|
||||
// Respect this by just returning totalItems.
|
||||
obj = ap.NewASOrderedCollection(params)
|
||||
|
||||
case page == nil:
|
||||
// i.e. paging disabled, return collection
|
||||
// that links to first page (i.e. path below).
|
||||
params.First = new(paging.Page)
|
||||
params.Query = make(url.Values, 1)
|
||||
params.Query.Set("limit", "40") // enables paging
|
||||
obj = ap.NewASOrderedCollection(params)
|
||||
} else {
|
||||
// i.e. paging enabled
|
||||
|
||||
default:
|
||||
// i.e. paging enabled
|
||||
// Get the request page of full follower objects with attached accounts.
|
||||
followers, err := p.state.DB.GetAccountFollowers(ctx, receiver.ID, page)
|
||||
if err != nil {
|
||||
|
|
@ -239,15 +249,24 @@ func (p *Processor) FollowingGet(ctx context.Context, requestedUser string, page
|
|||
params.ID = collectionID
|
||||
params.Total = total
|
||||
|
||||
if page == nil {
|
||||
switch {
|
||||
case receiver.IsInstance() ||
|
||||
*receiver.Settings.HideCollections:
|
||||
// Instance account (can't follow/be followed),
|
||||
// or an account that hides followers/following.
|
||||
// Respect this by just returning totalItems.
|
||||
obj = ap.NewASOrderedCollection(params)
|
||||
|
||||
case page == nil:
|
||||
// i.e. paging disabled, return collection
|
||||
// that links to first page (i.e. path below).
|
||||
params.First = new(paging.Page)
|
||||
params.Query = make(url.Values, 1)
|
||||
params.Query.Set("limit", "40") // enables paging
|
||||
obj = ap.NewASOrderedCollection(params)
|
||||
} else {
|
||||
// i.e. paging enabled
|
||||
|
||||
default:
|
||||
// i.e. paging enabled
|
||||
// Get the request page of full follower objects with attached accounts.
|
||||
follows, err := p.state.DB.GetAccountFollows(ctx, receiver.ID, page)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -156,6 +156,7 @@ func (p *Processor) StatusRepliesGet(
|
|||
if page == nil {
|
||||
// i.e. paging disabled, return collection
|
||||
// that links to first page (i.e. path below).
|
||||
params.First = new(paging.Page)
|
||||
params.Query = make(url.Values, 1)
|
||||
params.Query.Set("limit", "20") // enables paging
|
||||
obj = ap.NewASOrderedCollection(params)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue