summaryrefslogtreecommitdiff
path: root/internal/processing/account/relationships.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/processing/account/relationships.go')
-rw-r--r--internal/processing/account/relationships.go39
1 files changed, 33 insertions, 6 deletions
diff --git a/internal/processing/account/relationships.go b/internal/processing/account/relationships.go
index 4afe36afe..d12d989ef 100644
--- a/internal/processing/account/relationships.go
+++ b/internal/processing/account/relationships.go
@@ -31,7 +31,7 @@ import (
// FollowersGet fetches a list of the target account's followers.
func (p *Processor) FollowersGet(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) ([]apimodel.Account, gtserror.WithCode) {
- if blocked, err := p.state.DB.IsBlocked(ctx, requestingAccount.ID, targetAccountID, true); err != nil {
+ if blocked, err := p.state.DB.IsEitherBlocked(ctx, requestingAccount.ID, targetAccountID); err != nil {
err = fmt.Errorf("FollowersGet: db error checking block: %w", err)
return nil, gtserror.NewErrorInternalError(err)
} else if blocked {
@@ -39,7 +39,7 @@ func (p *Processor) FollowersGet(ctx context.Context, requestingAccount *gtsmode
return nil, gtserror.NewErrorNotFound(err)
}
- follows, err := p.state.DB.GetFollows(ctx, "", targetAccountID)
+ follows, err := p.state.DB.GetAccountFollowers(ctx, targetAccountID)
if err != nil {
if !errors.Is(err, db.ErrNoEntries) {
err = fmt.Errorf("FollowersGet: db error getting followers: %w", err)
@@ -53,7 +53,7 @@ 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) ([]apimodel.Account, gtserror.WithCode) {
- if blocked, err := p.state.DB.IsBlocked(ctx, requestingAccount.ID, targetAccountID, true); err != nil {
+ if blocked, err := p.state.DB.IsEitherBlocked(ctx, requestingAccount.ID, targetAccountID); err != nil {
err = fmt.Errorf("FollowingGet: db error checking block: %w", err)
return nil, gtserror.NewErrorInternalError(err)
} else if blocked {
@@ -61,7 +61,7 @@ func (p *Processor) FollowingGet(ctx context.Context, requestingAccount *gtsmode
return nil, gtserror.NewErrorNotFound(err)
}
- follows, err := p.state.DB.GetFollows(ctx, targetAccountID, "")
+ follows, err := p.state.DB.GetAccountFollows(ctx, targetAccountID)
if err != nil {
if !errors.Is(err, db.ErrNoEntries) {
err = fmt.Errorf("FollowingGet: db error getting followers: %w", err)
@@ -70,7 +70,7 @@ func (p *Processor) FollowingGet(ctx context.Context, requestingAccount *gtsmode
return []apimodel.Account{}, nil
}
- return p.accountsFromFollows(ctx, follows, requestingAccount.ID)
+ return p.targetAccountsFromFollows(ctx, follows, requestingAccount.ID)
}
// RelationshipGet returns a relationship model describing the relationship of the targetAccount to the Authed account.
@@ -101,7 +101,7 @@ func (p *Processor) accountsFromFollows(ctx context.Context, follows []*gtsmodel
continue
}
- if blocked, err := p.state.DB.IsBlocked(ctx, requestingAccountID, follow.AccountID, true); err != nil {
+ if blocked, err := p.state.DB.IsEitherBlocked(ctx, requestingAccountID, follow.AccountID); err != nil {
err = fmt.Errorf("accountsFromFollows: db error checking block: %w", err)
return nil, gtserror.NewErrorInternalError(err)
} else if blocked {
@@ -113,8 +113,35 @@ func (p *Processor) accountsFromFollows(ctx context.Context, follows []*gtsmodel
err = fmt.Errorf("accountsFromFollows: error converting account to api account: %w", err)
return nil, gtserror.NewErrorInternalError(err)
}
+
accounts = append(accounts, *account)
}
+ return accounts, nil
+}
+func (p *Processor) targetAccountsFromFollows(ctx context.Context, follows []*gtsmodel.Follow, requestingAccountID string) ([]apimodel.Account, gtserror.WithCode) {
+ accounts := make([]apimodel.Account, 0, len(follows))
+ for _, follow := range follows {
+ if follow.TargetAccount == nil {
+ // No account set for some reason; just skip.
+ log.WithContext(ctx).WithField("follow", follow).Warn("follow had no associated target account")
+ continue
+ }
+
+ if blocked, err := p.state.DB.IsEitherBlocked(ctx, requestingAccountID, follow.TargetAccountID); err != nil {
+ err = fmt.Errorf("targetAccountsFromFollows: db error checking block: %w", err)
+ return nil, gtserror.NewErrorInternalError(err)
+ } else if blocked {
+ continue
+ }
+
+ account, err := p.tc.AccountToAPIAccountPublic(ctx, follow.TargetAccount)
+ if err != nil {
+ err = fmt.Errorf("targetAccountsFromFollows: error converting account to api account: %w", err)
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+
+ accounts = append(accounts, *account)
+ }
return accounts, nil
}