2021-05-27 14:06:24 +00:00
|
|
|
package federatingdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
2021-11-13 16:29:43 +00:00
|
|
|
"github.com/superseriousbusiness/activity/streams/vocab"
|
2021-05-27 14:06:24 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Followers obtains the Followers Collection for an actor with the
|
|
|
|
// given id.
|
|
|
|
//
|
|
|
|
// If modified, the library will then call Update.
|
|
|
|
//
|
|
|
|
// The library makes this call only after acquiring a lock first.
|
2021-08-25 13:34:33 +00:00
|
|
|
func (f *federatingDB) Followers(ctx context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error) {
|
2021-10-11 12:37:33 +00:00
|
|
|
l := logrus.WithFields(
|
2021-05-27 14:06:24 +00:00
|
|
|
logrus.Fields{
|
2021-10-04 13:24:19 +00:00
|
|
|
"func": "Followers",
|
|
|
|
"id": actorIRI,
|
2021-05-27 14:06:24 +00:00
|
|
|
},
|
|
|
|
)
|
2021-10-04 13:24:19 +00:00
|
|
|
l.Debug("entering Followers")
|
2021-05-27 14:06:24 +00:00
|
|
|
|
2021-10-04 13:24:19 +00:00
|
|
|
acct, err := f.getAccountForIRI(ctx, actorIRI)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2021-05-27 14:06:24 +00:00
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
acctFollowers, err := f.db.GetAccountFollowedBy(ctx, acct.ID, false)
|
2021-08-20 10:26:56 +00:00
|
|
|
if err != nil {
|
2021-10-04 13:24:19 +00:00
|
|
|
return nil, fmt.Errorf("Followers: db error getting followers for account id %s: %s", acct.ID, err)
|
2021-05-27 14:06:24 +00:00
|
|
|
}
|
|
|
|
|
2021-10-04 13:24:19 +00:00
|
|
|
iris := []*url.URL{}
|
2021-05-27 14:06:24 +00:00
|
|
|
for _, follow := range acctFollowers {
|
2021-08-25 13:34:33 +00:00
|
|
|
if follow.Account == nil {
|
2021-10-04 13:24:19 +00:00
|
|
|
a, err := f.db.GetAccountByID(ctx, follow.AccountID)
|
2021-08-25 13:34:33 +00:00
|
|
|
if err != nil {
|
2021-10-04 13:24:19 +00:00
|
|
|
errWrapped := fmt.Errorf("Followers: db error getting account id %s: %s", follow.AccountID, err)
|
2021-09-28 14:19:13 +00:00
|
|
|
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)
|
|
|
|
continue
|
|
|
|
} else {
|
|
|
|
// proper error
|
|
|
|
return nil, errWrapped
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
}
|
2021-10-04 13:24:19 +00:00
|
|
|
follow.Account = a
|
2021-05-27 14:06:24 +00:00
|
|
|
}
|
2021-10-04 13:24:19 +00:00
|
|
|
u, err := url.Parse(follow.Account.URI)
|
2021-05-27 14:06:24 +00:00
|
|
|
if err != nil {
|
2021-10-04 13:24:19 +00:00
|
|
|
return nil, err
|
2021-05-27 14:06:24 +00:00
|
|
|
}
|
2021-10-04 13:24:19 +00:00
|
|
|
iris = append(iris, u)
|
2021-05-27 14:06:24 +00:00
|
|
|
}
|
2021-10-04 13:24:19 +00:00
|
|
|
|
|
|
|
return f.collectIRIs(ctx, iris)
|
2021-05-27 14:06:24 +00:00
|
|
|
}
|