mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-12-23 10:42:12 +00:00
b4288f3c47
* start messing about with timeline manager * i have no idea what i'm doing * i continue to not know what i'm doing * it's coming along * bit more progress * update timeline with new posts as they come in * lint and fmt * Select accounts where empty string * restructure a bunch, get unfaves working * moving stuff around * federate status deletes properly * mention regex better but not 100% there * fix regex * some more hacking away at the timeline code phew * fix up some little things * i can't even * more timeline stuff * move to ulid * fiddley * some lil fixes for kibou compatibility * timelines working pretty alright! * tidy + lint
66 lines
2.2 KiB
Go
66 lines
2.2 KiB
Go
package federatingdb
|
|
|
|
import (
|
|
"context"
|
|
"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
|
|
// given id.
|
|
//
|
|
// If modified, the library will then call Update.
|
|
//
|
|
// The library makes this call only after acquiring a lock first.
|
|
func (f *federatingDB) Followers(c context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error) {
|
|
l := f.log.WithFields(
|
|
logrus.Fields{
|
|
"func": "Followers",
|
|
"actorIRI": actorIRI.String(),
|
|
},
|
|
)
|
|
l.Debugf("entering FOLLOWERS function with actorIRI %s", actorIRI.String())
|
|
|
|
acct := >smodel.Account{}
|
|
|
|
if util.IsUserPath(actorIRI) {
|
|
if err := f.db.GetWhere([]db.Where{{Key: "uri", Value: actorIRI.String()}}, acct); err != nil {
|
|
return nil, fmt.Errorf("db error getting account with uri %s: %s", actorIRI.String(), err)
|
|
}
|
|
} else if util.IsFollowersPath(actorIRI) {
|
|
if err := f.db.GetWhere([]db.Where{{Key: "followers_uri", Value: actorIRI.String()}}, acct); err != nil {
|
|
return nil, fmt.Errorf("db error getting account with followers uri %s: %s", actorIRI.String(), err)
|
|
}
|
|
} else {
|
|
return nil, fmt.Errorf("could not parse actor IRI %s as users or followers path", actorIRI.String())
|
|
}
|
|
|
|
acctFollowers := []gtsmodel.Follow{}
|
|
if err := f.db.GetFollowersByAccountID(acct.ID, &acctFollowers, false); err != nil {
|
|
return nil, fmt.Errorf("db error getting followers for account id %s: %s", acct.ID, err)
|
|
}
|
|
|
|
followers = streams.NewActivityStreamsCollection()
|
|
items := streams.NewActivityStreamsItemsProperty()
|
|
for _, follow := range acctFollowers {
|
|
gtsFollower := >smodel.Account{}
|
|
if err := f.db.GetByID(follow.AccountID, gtsFollower); err != nil {
|
|
return nil, fmt.Errorf("db error getting account id %s: %s", follow.AccountID, err)
|
|
}
|
|
uri, err := url.Parse(gtsFollower.URI)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error parsing %s as url: %s", gtsFollower.URI, err)
|
|
}
|
|
items.AppendIRI(uri)
|
|
}
|
|
followers.SetActivityStreamsItems(items)
|
|
return
|
|
}
|