2021-05-27 14:06:24 +00:00
|
|
|
package federatingdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/go-fed/activity/streams/vocab"
|
|
|
|
"github.com/sirupsen/logrus"
|
2021-09-28 14:19:13 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
2021-05-27 14:06:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Following obtains the Following 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) Following(ctx context.Context, actorIRI *url.URL) (following 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": "Following",
|
|
|
|
"id": actorIRI,
|
2021-05-27 14:06:24 +00:00
|
|
|
},
|
|
|
|
)
|
2021-10-04 13:24:19 +00:00
|
|
|
l.Debug("entering Following")
|
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
|
|
|
acctFollowing, err := f.db.GetAccountFollows(ctx, acct.ID)
|
2021-08-20 10:26:56 +00:00
|
|
|
if err != nil {
|
2021-10-04 13:24:19 +00:00
|
|
|
return nil, fmt.Errorf("Following: db error getting following 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 acctFollowing {
|
2021-10-04 13:24:19 +00:00
|
|
|
if follow.TargetAccount == nil {
|
|
|
|
a, err := f.db.GetAccountByID(ctx, follow.TargetAccountID)
|
2021-08-25 13:34:33 +00:00
|
|
|
if err != nil {
|
2021-10-04 13:24:19 +00:00
|
|
|
errWrapped := fmt.Errorf("Following: db error getting account id %s: %s", follow.TargetAccountID, 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.TargetAccount = a
|
2021-05-27 14:06:24 +00:00
|
|
|
}
|
2021-10-04 13:24:19 +00:00
|
|
|
u, err := url.Parse(follow.TargetAccount.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
|
|
|
}
|