2021-05-27 15:06:24 +01: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-09-28 15:19:13 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
2021-05-27 15:06:24 +01: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 14:34:33 +01:00
|
|
|
func (f *federatingDB) Following(ctx context.Context, actorIRI *url.URL) (following vocab.ActivityStreamsCollection, err error) {
|
2021-10-11 13:37:33 +01:00
|
|
|
l := logrus.WithFields(
|
2021-05-27 15:06:24 +01:00
|
|
|
logrus.Fields{
|
2021-10-04 14:24:19 +01:00
|
|
|
"func": "Following",
|
|
|
|
"id": actorIRI,
|
2021-05-27 15:06:24 +01:00
|
|
|
},
|
|
|
|
)
|
2021-10-04 14:24:19 +01:00
|
|
|
l.Debug("entering Following")
|
2021-05-27 15:06:24 +01:00
|
|
|
|
2021-10-04 14:24:19 +01:00
|
|
|
acct, err := f.getAccountForIRI(ctx, actorIRI)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2021-05-27 15:06:24 +01:00
|
|
|
}
|
|
|
|
|
2021-08-25 14:34:33 +01:00
|
|
|
acctFollowing, err := f.db.GetAccountFollows(ctx, acct.ID)
|
2021-08-20 11:26:56 +01:00
|
|
|
if err != nil {
|
2021-10-04 14:24:19 +01:00
|
|
|
return nil, fmt.Errorf("Following: db error getting following for account id %s: %s", acct.ID, err)
|
2021-05-27 15:06:24 +01:00
|
|
|
}
|
|
|
|
|
2021-10-04 14:24:19 +01:00
|
|
|
iris := []*url.URL{}
|
2021-05-27 15:06:24 +01:00
|
|
|
for _, follow := range acctFollowing {
|
2021-10-04 14:24:19 +01:00
|
|
|
if follow.TargetAccount == nil {
|
|
|
|
a, err := f.db.GetAccountByID(ctx, follow.TargetAccountID)
|
2021-08-25 14:34:33 +01:00
|
|
|
if err != nil {
|
2021-10-04 14:24:19 +01:00
|
|
|
errWrapped := fmt.Errorf("Following: db error getting account id %s: %s", follow.TargetAccountID, err)
|
2021-09-28 15:19:13 +01: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 14:34:33 +01:00
|
|
|
}
|
2021-10-04 14:24:19 +01:00
|
|
|
follow.TargetAccount = a
|
2021-05-27 15:06:24 +01:00
|
|
|
}
|
2021-10-04 14:24:19 +01:00
|
|
|
u, err := url.Parse(follow.TargetAccount.URI)
|
2021-05-27 15:06:24 +01:00
|
|
|
if err != nil {
|
2021-10-04 14:24:19 +01:00
|
|
|
return nil, err
|
2021-05-27 15:06:24 +01:00
|
|
|
}
|
2021-10-04 14:24:19 +01:00
|
|
|
iris = append(iris, u)
|
2021-05-27 15:06:24 +01:00
|
|
|
}
|
2021-10-04 14:24:19 +01:00
|
|
|
|
|
|
|
return f.collectIRIs(ctx, iris)
|
2021-05-27 15:06:24 +01:00
|
|
|
}
|