2021-05-27 14:06:24 +00:00
|
|
|
package federatingdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
|
2022-07-19 08:47:55 +00:00
|
|
|
"codeberg.org/gruf/go-kv"
|
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"
|
2022-07-19 08:47:55 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/log"
|
2021-05-27 14:06:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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) {
|
2023-02-17 11:02:29 +00:00
|
|
|
l := log.WithContext(ctx).
|
|
|
|
WithFields(kv.Fields{
|
|
|
|
{"id", actorIRI},
|
|
|
|
}...)
|
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
|
|
|
}
|
|
|
|
|
2023-03-01 18:26:53 +00:00
|
|
|
acctFollowers, err := f.state.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 {
|
2023-03-01 18:26:53 +00:00
|
|
|
a, err := f.state.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
|
|
|
}
|