summaryrefslogtreecommitdiff
path: root/internal/processing/account/relationships.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-04-02 11:42:24 +0200
committerLibravatar GitHub <noreply@github.com>2024-04-02 10:42:24 +0100
commitf05874be3095d3fb3cefd1a92b3c35fe3ae3bf28 (patch)
tree52f1616259b51d0a8a94a786278b9c0aa5ab2298 /internal/processing/account/relationships.go
parent[feature] Add `enable` command to mirror existing `disable` command; update d... (diff)
downloadgotosocial-f05874be3095d3fb3cefd1a92b3c35fe3ae3bf28.tar.xz
[feature] Option to hide followers/following (#2788)
Diffstat (limited to 'internal/processing/account/relationships.go')
-rw-r--r--internal/processing/account/relationships.go32
1 files changed, 30 insertions, 2 deletions
diff --git a/internal/processing/account/relationships.go b/internal/processing/account/relationships.go
index b9e9086c9..53d2ee3c7 100644
--- a/internal/processing/account/relationships.go
+++ b/internal/processing/account/relationships.go
@@ -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) {