diff options
Diffstat (limited to 'internal/federation/federatingdb/followers.go')
| -rw-r--r-- | internal/federation/federatingdb/followers.go | 47 |
1 files changed, 16 insertions, 31 deletions
diff --git a/internal/federation/federatingdb/followers.go b/internal/federation/federatingdb/followers.go index 69c68b8b9..61c5d4287 100644 --- a/internal/federation/federatingdb/followers.go +++ b/internal/federation/federatingdb/followers.go @@ -5,12 +5,9 @@ import ( "fmt" "net/url" - "github.com/go-fed/activity/streams" "github.com/go-fed/activity/streams/vocab" "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/db" - "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" - "github.com/superseriousbusiness/gotosocial/internal/util" ) // Followers obtains the Followers Collection for an actor with the @@ -22,39 +19,28 @@ import ( func (f *federatingDB) Followers(ctx context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error) { l := f.log.WithFields( logrus.Fields{ - "func": "Followers", - "actorIRI": actorIRI.String(), + "func": "Followers", + "id": actorIRI, }, ) - l.Debugf("entering FOLLOWERS function with actorIRI %s", actorIRI.String()) + l.Debug("entering Followers") - acct := >smodel.Account{} - - if util.IsUserPath(actorIRI) { - acct, err = f.db.GetAccountByURI(ctx, actorIRI.String()) - if err != nil { - return nil, fmt.Errorf("FOLLOWERS: db error getting account with uri %s: %s", actorIRI.String(), err) - } - } else if util.IsFollowersPath(actorIRI) { - if err := f.db.GetWhere(ctx, []db.Where{{Key: "followers_uri", Value: actorIRI.String()}}, acct); err != nil { - return nil, fmt.Errorf("FOLLOWERS: db error getting account with followers uri %s: %s", actorIRI.String(), err) - } - } else { - return nil, fmt.Errorf("FOLLOWERS: could not parse actor IRI %s as users or followers path", actorIRI.String()) + acct, err := f.getAccountForIRI(ctx, actorIRI) + if err != nil { + return nil, err } acctFollowers, err := f.db.GetAccountFollowedBy(ctx, acct.ID, false) if err != nil { - return nil, fmt.Errorf("FOLLOWERS: db error getting followers for account id %s: %s", acct.ID, err) + return nil, fmt.Errorf("Followers: db error getting followers for account id %s: %s", acct.ID, err) } - followers = streams.NewActivityStreamsCollection() - items := streams.NewActivityStreamsItemsProperty() + iris := []*url.URL{} for _, follow := range acctFollowers { if follow.Account == nil { - followAccount, err := f.db.GetAccountByID(ctx, follow.AccountID) + a, err := f.db.GetAccountByID(ctx, follow.AccountID) if err != nil { - errWrapped := fmt.Errorf("FOLLOWERS: db error getting account id %s: %s", follow.AccountID, err) + errWrapped := fmt.Errorf("Followers: db error getting account id %s: %s", follow.AccountID, err) if err == db.ErrNoEntries { // no entry for this account id so it's probably been deleted and we haven't caught up yet l.Error(errWrapped) @@ -64,15 +50,14 @@ func (f *federatingDB) Followers(ctx context.Context, actorIRI *url.URL) (follow return nil, errWrapped } } - follow.Account = followAccount + follow.Account = a } - - uri, err := url.Parse(follow.Account.URI) + u, err := url.Parse(follow.Account.URI) if err != nil { - return nil, fmt.Errorf("FOLLOWERS: error parsing %s as url: %s", follow.Account.URI, err) + return nil, err } - items.AppendIRI(uri) + iris = append(iris, u) } - followers.SetActivityStreamsItems(items) - return + + return f.collectIRIs(ctx, iris) } |
