and some more

This commit is contained in:
tsmethurst 2021-08-18 12:41:43 +02:00
commit 896461dec3
16 changed files with 145 additions and 95 deletions

View file

@ -88,8 +88,8 @@ var Confirm cliactions.GTSAction = func(ctx context.Context, c *config.Config, l
return err
}
a := &gtsmodel.Account{}
if err := dbConn.GetLocalAccountByUsername(username, a); err != nil {
a, err := dbConn.GetLocalAccountByUsername(username)
if err != nil {
return err
}
@ -123,8 +123,8 @@ var Promote cliactions.GTSAction = func(ctx context.Context, c *config.Config, l
return err
}
a := &gtsmodel.Account{}
if err := dbConn.GetLocalAccountByUsername(username, a); err != nil {
a, err := dbConn.GetLocalAccountByUsername(username)
if err != nil {
return err
}
@ -155,8 +155,8 @@ var Demote cliactions.GTSAction = func(ctx context.Context, c *config.Config, lo
return err
}
a := &gtsmodel.Account{}
if err := dbConn.GetLocalAccountByUsername(username, a); err != nil {
a, err := dbConn.GetLocalAccountByUsername(username)
if err != nil {
return err
}
@ -187,8 +187,8 @@ var Disable cliactions.GTSAction = func(ctx context.Context, c *config.Config, l
return err
}
a := &gtsmodel.Account{}
if err := dbConn.GetLocalAccountByUsername(username, a); err != nil {
a, err := dbConn.GetLocalAccountByUsername(username)
if err != nil {
return err
}
@ -233,8 +233,8 @@ var Password cliactions.GTSAction = func(ctx context.Context, c *config.Config,
return err
}
a := &gtsmodel.Account{}
if err := dbConn.GetLocalAccountByUsername(username, a); err != nil {
a, err := dbConn.GetLocalAccountByUsername(username)
if err != nil {
return err
}

View file

@ -31,11 +31,14 @@ type Account interface {
// GetAccountByURI returns one account with the given URI, or an error if something goes wrong.
GetAccountByURI(uri string) (*gtsmodel.Account, DBError)
// GetAccountByURL returns one account with the given URL, or an error if something goes wrong.
GetAccountByURL(uri string) (*gtsmodel.Account, DBError)
// GetLocalAccountByUsername is a shortcut for the common action of fetching an account ON THIS INSTANCE
// according to its username, which should be unique.
// The given account pointer will be set to the result of the query, whatever it is.
// In case of no entries, a 'no entries' error will be returned
GetLocalAccountByUsername(username string, account *gtsmodel.Account) DBError
GetLocalAccountByUsername(username string) (*gtsmodel.Account, DBError)
// GetAccountFollowRequests is a shortcut for the common action of fetching a list of follow requests targeting the given account ID.
// The given slice 'followRequests' will be set to the result of the query, whatever it is.

View file

@ -67,6 +67,17 @@ func (a *accountDB) GetAccountByURI(uri string) (*gtsmodel.Account, db.DBError)
return account, err
}
func (a *accountDB) GetAccountByURL(uri string) (*gtsmodel.Account, db.DBError) {
account := &gtsmodel.Account{}
q := a.newAccountQ(account).
Where("account.url = ?", uri)
err := processErrorResponse(q.Select())
return account, err
}
func (a *accountDB) GetInstanceAccount(domain string) (*gtsmodel.Account, db.DBError) {
account := &gtsmodel.Account{}
@ -126,14 +137,16 @@ func (a *accountDB) SetAccountHeaderOrAvatar(mediaAttachment *gtsmodel.MediaAtta
return nil
}
func (a *accountDB) GetLocalAccountByUsername(username string, account *gtsmodel.Account) db.DBError {
if err := a.conn.Model(account).Where("username = ?", username).Where("? IS NULL", pg.Ident("domain")).Select(); err != nil {
if err == pg.ErrNoRows {
return db.ErrNoEntries
}
return err
}
return nil
func (a *accountDB) GetLocalAccountByUsername(username string) (*gtsmodel.Account, db.DBError) {
account := &gtsmodel.Account{}
q := a.newAccountQ(account).
Where("username = ?", username).
Where("? IS NULL", pg.Ident("domain"))
err := processErrorResponse(q.Select())
return account, err
}
func (a *accountDB) GetAccountFollowRequests(accountID string, followRequests *[]gtsmodel.FollowRequest) db.DBError {

View file

@ -82,6 +82,17 @@ func (s *statusDB) GetStatusByURI(uri string) (*gtsmodel.Status, db.DBError) {
return status, err
}
func (s *statusDB) GetStatusByURL(uri string) (*gtsmodel.Status, db.DBError) {
status := &gtsmodel.Status{}
q := s.newStatusQ(status).
Where("LOWER(status.url) = LOWER(?)", uri)
err := processErrorResponse(q.Select())
return status, err
}
func (s *statusDB) PutStatus(status *gtsmodel.Status) db.DBError {
transaction := func(tx *pg.Tx) error {
// create links between this status and any emojis it uses
@ -142,7 +153,7 @@ func (s *statusDB) statusParent(status *gtsmodel.Status, foundStatuses *[]*gtsmo
if onlyDirect {
return
}
s.statusParent(parentStatus, foundStatuses, false)
}

View file

@ -27,6 +27,9 @@ type Status interface {
// GetStatusByURI returns one status from the database, with all rel fields populated (if possible).
GetStatusByURI(uri string) (*gtsmodel.Status, DBError)
// GetStatusByURL returns one status from the database, with all rel fields populated (if possible).
GetStatusByURL(uri string) (*gtsmodel.Status, DBError)
// PutStatus stores one status in the database.
PutStatus(status *gtsmodel.Status) DBError

View file

@ -66,8 +66,8 @@ func (d *deref) GetRemoteStatus(username string, remoteStatusID *url.URL, refres
new := true
// check if we already have the status in our db
maybeStatus := &gtsmodel.Status{}
if err := d.db.GetWhere([]db.Where{{Key: "uri", Value: remoteStatusID.String()}}, maybeStatus); err == nil {
maybeStatus, err := d.db.GetStatusByURI(remoteStatusID.String())
if err == nil {
// we've seen this status before so it's not new
new = false
@ -339,7 +339,7 @@ func (d *deref) populateStatusFields(status *gtsmodel.Status, requestingUsername
m.StatusID = status.ID
m.Status = status
m.OriginAccountID = status.Account.ID
m.OriginAccount = status.Account
m.OriginAccountURI = status.Account.URI

View file

@ -6,7 +6,6 @@ import (
"net/url"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/util"
)
@ -52,10 +51,8 @@ func (f *federatingDB) Delete(ctx context.Context, id *url.URL) error {
// in a delete we only get the URI, we can't know if we have a status or a profile or something else,
// so we have to try a few different things...
where := []db.Where{{Key: "uri", Value: id.String()}}
s := &gtsmodel.Status{}
if err := f.db.GetWhere(where, s); err == nil {
s, err := f.db.GetStatusByURI(id.String())
if err == nil {
// it's a status
l.Debugf("uri is for status with id: %s", s.ID)
if err := f.db.DeleteByID(s.ID, &gtsmodel.Status{}); err != nil {
@ -69,8 +66,8 @@ func (f *federatingDB) Delete(ctx context.Context, id *url.URL) error {
}
}
a := &gtsmodel.Account{}
if err := f.db.GetWhere(where, a); err == nil {
a, err := f.db.GetAccountByURI(id.String())
if err == nil {
// it's an account
l.Debugf("uri is for an account with id: %s", s.ID)
if err := f.db.DeleteByID(a.ID, &gtsmodel.Account{}); err != nil {

View file

@ -8,7 +8,6 @@ import (
"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"
)
@ -28,15 +27,31 @@ func (f *federatingDB) Following(c context.Context, actorIRI *url.URL) (followin
)
l.Debugf("entering FOLLOWING function with actorIRI %s", actorIRI.String())
acct := &gtsmodel.Account{}
var acct *gtsmodel.Account
if util.IsUserPath(actorIRI) {
if err := f.db.GetWhere([]db.Where{{Key: "uri", Value: actorIRI.String()}}, acct); err != nil {
username, err := util.ParseUserPath(actorIRI)
if err != nil {
return nil, fmt.Errorf("FOLLOWING: error parsing user path: %s", err)
}
a, err := f.db.GetLocalAccountByUsername(username)
if err != nil {
return nil, fmt.Errorf("FOLLOWING: db error getting account with uri %s: %s", actorIRI.String(), err)
}
acct = a
} else if util.IsFollowingPath(actorIRI) {
if err := f.db.GetWhere([]db.Where{{Key: "following_uri", Value: actorIRI.String()}}, acct); err != nil {
username, err := util.ParseFollowingPath(actorIRI)
if err != nil {
return nil, fmt.Errorf("FOLLOWING: error parsing following path: %s", err)
}
a, err := f.db.GetLocalAccountByUsername(username)
if err != nil {
return nil, fmt.Errorf("FOLLOWING: db error getting account with following uri %s: %s", actorIRI.String(), err)
}
acct = a
} else {
return nil, fmt.Errorf("FOLLOWING: could not parse actor IRI %s as users or following path", actorIRI.String())
}

View file

@ -54,7 +54,8 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
if err != nil {
return false, fmt.Errorf("error parsing statuses path for url %s: %s", id.String(), err)
}
if err := f.db.GetWhere([]db.Where{{Key: "uri", Value: uid}}, &gtsmodel.Status{}); err != nil {
status, err := f.db.GetStatusByURI(uid)
if err != nil {
if err == db.ErrNoEntries {
// there are no entries for this status
return false, nil
@ -62,8 +63,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
// an actual error happened
return false, fmt.Errorf("database error fetching status with id %s: %s", uid, err)
}
l.Debugf("we own url %s", id.String())
return true, nil
return status.Local, nil
}
if util.IsUserPath(id) {
@ -71,7 +71,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
if err != nil {
return false, fmt.Errorf("error parsing statuses path for url %s: %s", id.String(), err)
}
if err := f.db.GetLocalAccountByUsername(username, &gtsmodel.Account{}); err != nil {
if _, err := f.db.GetLocalAccountByUsername(username); err != nil {
if err == db.ErrNoEntries {
// there are no entries for this username
return false, nil
@ -88,7 +88,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
if err != nil {
return false, fmt.Errorf("error parsing statuses path for url %s: %s", id.String(), err)
}
if err := f.db.GetLocalAccountByUsername(username, &gtsmodel.Account{}); err != nil {
if _, err := f.db.GetLocalAccountByUsername(username); err != nil {
if err == db.ErrNoEntries {
// there are no entries for this username
return false, nil
@ -105,7 +105,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
if err != nil {
return false, fmt.Errorf("error parsing statuses path for url %s: %s", id.String(), err)
}
if err := f.db.GetLocalAccountByUsername(username, &gtsmodel.Account{}); err != nil {
if _, err := f.db.GetLocalAccountByUsername(username); err != nil {
if err == db.ErrNoEntries {
// there are no entries for this username
return false, nil
@ -122,7 +122,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
if err != nil {
return false, fmt.Errorf("error parsing like path for url %s: %s", id.String(), err)
}
if err := f.db.GetLocalAccountByUsername(username, &gtsmodel.Account{}); err != nil {
if _, err := f.db.GetLocalAccountByUsername(username); err != nil {
if err == db.ErrNoEntries {
// there are no entries for this username
return false, nil
@ -147,7 +147,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
if err != nil {
return false, fmt.Errorf("error parsing block path for url %s: %s", id.String(), err)
}
if err := f.db.GetLocalAccountByUsername(username, &gtsmodel.Account{}); err != nil {
if _, err := f.db.GetLocalAccountByUsername(username); err != nil {
if err == db.ErrNoEntries {
// there are no entries for this username
return false, nil

View file

@ -113,8 +113,8 @@ func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr
return nil, false, errors.New("username was empty")
}
requestedAccount := &gtsmodel.Account{}
if err := f.db.GetLocalAccountByUsername(username, requestedAccount); err != nil {
requestedAccount, err := f.db.GetLocalAccountByUsername(username)
if err != nil {
return nil, false, fmt.Errorf("could not fetch requested account with username %s: %s", username, err)
}

View file

@ -231,8 +231,8 @@ func (mh *mediaHandler) ProcessLocalEmoji(emojiBytes []byte, shortcode string) (
// since emoji aren't 'owned' by an account, but we still want to use the same pattern for serving them through the filserver,
// (ie., fileserver/ACCOUNT_ID/etc etc) we need to fetch the INSTANCE ACCOUNT from the database. That is, the account that's created
// with the same username as the instance hostname, which doesn't belong to any particular user.
instanceAccount := &gtsmodel.Account{}
if err := mh.db.GetLocalAccountByUsername(mh.config.Host, instanceAccount); err != nil {
instanceAccount, err := mh.db.GetInstanceAccount("")
if err != nil {
return nil, fmt.Errorf("error fetching instance account: %s", err)
}

View file

@ -36,13 +36,12 @@ import (
func (p *processor) GetFediUser(ctx context.Context, requestedUsername string, requestURL *url.URL) (interface{}, gtserror.WithCode) {
// get the account the request is referring to
requestedAccount := &gtsmodel.Account{}
if err := p.db.GetLocalAccountByUsername(requestedUsername, requestedAccount); err != nil {
requestedAccount, err := p.db.GetLocalAccountByUsername(requestedUsername)
if err != nil {
return nil, gtserror.NewErrorNotFound(fmt.Errorf("database error getting account with username %s: %s", requestedUsername, err))
}
var requestedPerson vocab.ActivityStreamsPerson
var err error
if util.IsPublicKeyPath(requestURL) {
// if it's a public key path, we don't need to authenticate but we'll only serve the bare minimum user profile needed for the public key
requestedPerson, err = p.tc.AccountToASMinimal(requestedAccount)
@ -91,8 +90,8 @@ func (p *processor) GetFediUser(ctx context.Context, requestedUsername string, r
func (p *processor) GetFediFollowers(ctx context.Context, requestedUsername string, requestURL *url.URL) (interface{}, gtserror.WithCode) {
// get the account the request is referring to
requestedAccount := &gtsmodel.Account{}
if err := p.db.GetLocalAccountByUsername(requestedUsername, requestedAccount); err != nil {
requestedAccount, err := p.db.GetLocalAccountByUsername(requestedUsername)
if err != nil {
return nil, gtserror.NewErrorNotFound(fmt.Errorf("database error getting account with username %s: %s", requestedUsername, err))
}
@ -136,8 +135,8 @@ func (p *processor) GetFediFollowers(ctx context.Context, requestedUsername stri
func (p *processor) GetFediFollowing(ctx context.Context, requestedUsername string, requestURL *url.URL) (interface{}, gtserror.WithCode) {
// get the account the request is referring to
requestedAccount := &gtsmodel.Account{}
if err := p.db.GetLocalAccountByUsername(requestedUsername, requestedAccount); err != nil {
requestedAccount, err := p.db.GetLocalAccountByUsername(requestedUsername)
if err != nil {
return nil, gtserror.NewErrorNotFound(fmt.Errorf("database error getting account with username %s: %s", requestedUsername, err))
}
@ -181,8 +180,8 @@ func (p *processor) GetFediFollowing(ctx context.Context, requestedUsername stri
func (p *processor) GetFediStatus(ctx context.Context, requestedUsername string, requestedStatusID string, requestURL *url.URL) (interface{}, gtserror.WithCode) {
// get the account the request is referring to
requestedAccount := &gtsmodel.Account{}
if err := p.db.GetLocalAccountByUsername(requestedUsername, requestedAccount); err != nil {
requestedAccount, err := p.db.GetLocalAccountByUsername(requestedUsername)
if err != nil {
return nil, gtserror.NewErrorNotFound(fmt.Errorf("database error getting account with username %s: %s", requestedUsername, err))
}
@ -241,8 +240,8 @@ func (p *processor) GetFediStatus(ctx context.Context, requestedUsername string,
func (p *processor) GetFediStatusReplies(ctx context.Context, requestedUsername string, requestedStatusID string, page bool, onlyOtherAccounts bool, minID string, requestURL *url.URL) (interface{}, gtserror.WithCode) {
// get the account the request is referring to
requestedAccount := &gtsmodel.Account{}
if err := p.db.GetLocalAccountByUsername(requestedUsername, requestedAccount); err != nil {
requestedAccount, err := p.db.GetLocalAccountByUsername(requestedUsername)
if err != nil {
return nil, gtserror.NewErrorNotFound(fmt.Errorf("database error getting account with username %s: %s", requestedUsername, err))
}
@ -374,8 +373,8 @@ func (p *processor) GetFediStatusReplies(ctx context.Context, requestedUsername
func (p *processor) GetWebfingerAccount(ctx context.Context, requestedUsername string, requestURL *url.URL) (*apimodel.WellKnownResponse, gtserror.WithCode) {
// get the account the request is referring to
requestedAccount := &gtsmodel.Account{}
if err := p.db.GetLocalAccountByUsername(requestedUsername, requestedAccount); err != nil {
requestedAccount, err := p.db.GetLocalAccountByUsername(requestedUsername)
if err != nil {
return nil, gtserror.NewErrorNotFound(fmt.Errorf("database error getting account with username %s: %s", requestedUsername, err))
}

View file

@ -51,8 +51,8 @@ func (p *processor) InstancePatch(form *apimodel.InstanceSettingsUpdateRequest)
}
// fetch the instance account from the db for processing
ia := &gtsmodel.Account{}
if err := p.db.GetLocalAccountByUsername(p.config.Host, ia); err != nil {
ia, err := p.db.GetInstanceAccount("")
if err != nil {
return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error fetching instance account %s: %s", p.config.Host, err))
}
@ -67,8 +67,8 @@ func (p *processor) InstancePatch(form *apimodel.InstanceSettingsUpdateRequest)
// validate & update site contact account if it's set on the form
if form.ContactUsername != nil {
// make sure the account with the given username exists in the db
contactAccount := &gtsmodel.Account{}
if err := p.db.GetLocalAccountByUsername(*form.ContactUsername, contactAccount); err != nil {
contactAccount, err := p.db.GetLocalAccountByUsername(*form.ContactUsername)
if err != nil {
return nil, gtserror.NewErrorBadRequest(err, fmt.Sprintf("account with username %s not retrievable", *form.ContactUsername))
}
// make sure it has a user associated with it

View file

@ -99,11 +99,6 @@ func (p *processor) SearchGet(authed *oauth.Auth, searchQuery *apimodel.SearchQu
}
for _, foundStatus := range foundStatuses {
statusOwner := &gtsmodel.Account{}
if err := p.db.GetByID(foundStatus.AccountID, statusOwner); err != nil {
continue
}
if visible, err := p.filter.StatusVisible(foundStatus, authed.Account); !visible || err != nil {
continue
}
@ -126,12 +121,9 @@ func (p *processor) searchStatusByURI(authed *oauth.Auth, uri *url.URL, resolve
"resolve": resolve,
})
maybeStatus := &gtsmodel.Status{}
if err := p.db.GetWhere([]db.Where{{Key: "uri", Value: uri.String(), CaseInsensitive: true}}, maybeStatus); err == nil {
// we have it and it's a status
if maybeStatus, err := p.db.GetStatusByURI(uri.String()); err == nil {
return maybeStatus, nil
} else if err := p.db.GetWhere([]db.Where{{Key: "url", Value: uri.String(), CaseInsensitive: true}}, maybeStatus); err == nil {
// we have it and it's a status
} else if maybeStatus, err := p.db.GetStatusByURL(uri.String()); err == nil {
return maybeStatus, nil
}
@ -150,14 +142,12 @@ func (p *processor) searchStatusByURI(authed *oauth.Auth, uri *url.URL, resolve
}
func (p *processor) searchAccountByURI(authed *oauth.Auth, uri *url.URL, resolve bool) (*gtsmodel.Account, error) {
maybeAccount := &gtsmodel.Account{}
if err := p.db.GetWhere([]db.Where{{Key: "uri", Value: uri.String(), CaseInsensitive: true}}, maybeAccount); err == nil {
// we have it and it's an account
if maybeAccount, err := p.db.GetAccountByURI(uri.String()); err == nil {
return maybeAccount, nil
} else if err = p.db.GetWhere([]db.Where{{Key: "url", Value: uri.String(), CaseInsensitive: true}}, maybeAccount); err == nil {
// we have it and it's an account
} else if maybeAccount, err := p.db.GetAccountByURL(uri.String()); err == nil {
return maybeAccount, nil
}
if resolve {
// we don't have it locally so try and dereference it
account, _, err := p.federator.GetRemoteAccount(authed.Account.Username, uri, true)
@ -179,7 +169,8 @@ func (p *processor) searchAccountByMention(authed *oauth.Auth, mention string, r
// if it's a local account we can skip a whole bunch of stuff
maybeAcct := &gtsmodel.Account{}
if domain == p.config.Host {
if err = p.db.GetLocalAccountByUsername(username, maybeAcct); err != nil {
maybeAcct, err = p.db.GetLocalAccountByUsername(username)
if err != nil {
return nil, fmt.Errorf("searchAccountByMention: error getting local account by username: %s", err)
}
return maybeAcct, nil

View file

@ -28,7 +28,6 @@ import (
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
// Controller generates transports for use in making federation requests to other servers.
@ -95,14 +94,15 @@ func (c *controller) NewTransportForUsername(username string) (Transport, error)
// We need an account to use to create a transport for dereferecing something.
// If a username has been given, we can fetch the account with that username and use it.
// Otherwise, we can take the instance account and use those credentials to make the request.
ourAccount := &gtsmodel.Account{}
var u string
if username == "" {
u = c.config.Host
} else {
u = username
}
if err := c.db.GetLocalAccountByUsername(u, ourAccount); err != nil {
ourAccount, err := c.db.GetLocalAccountByUsername(u)
if err != nil {
return nil, fmt.Errorf("error getting account %s from db: %s", username, err)
}

View file

@ -23,6 +23,26 @@ func (f *filter) pullRelevantAccountsFromStatus(targetStatus *gtsmodel.Status) (
}
accounts.StatusAuthor = targetStatus.Account
// now get all accounts with IDs that are mentioned in the status
if targetStatus.MentionIDs != nil && targetStatus.Mentions == nil {
mentions, err := f.db.GetMentions(targetStatus.MentionIDs)
if err != nil {
return accounts, fmt.Errorf("PullRelevantAccountsFromStatus: error getting mentions from status: %s", err)
}
targetStatus.Mentions = mentions
}
for _, m := range targetStatus.Mentions {
if m.TargetAccount == nil {
t, err := f.db.GetAccountByID(m.TargetAccountID)
if err != nil {
return accounts, fmt.Errorf("PullRelevantAccountsFromStatus: error getting mentions from status: %s", err)
}
m.TargetAccount = t
}
accounts.MentionedAccounts = append(accounts.MentionedAccounts, m.TargetAccount)
}
// get the replied to account if it's not set on the status already
if targetStatus.InReplyToAccountID != "" && targetStatus.InReplyToAccount == nil {
repliedToAccount, err := f.db.GetAccountByID(targetStatus.InReplyToAccountID)
@ -65,8 +85,9 @@ func (f *filter) pullRelevantAccountsFromStatus(targetStatus *gtsmodel.Status) (
}
targetStatus.BoostOf.InReplyToAccount = boostOfInReplyToAccount
}
accounts.BoostedReplyToAccount = targetStatus.BoostOf.InReplyToAccount
// now get all accounts with IDs that are mentioned in the status
// now get all accounts with IDs that are mentioned in the boosted status
if targetStatus.BoostOf.MentionIDs != nil && targetStatus.BoostOf.Mentions == nil {
mentions, err := f.db.GetMentions(targetStatus.BoostOf.MentionIDs)
if err != nil {
@ -74,20 +95,17 @@ func (f *filter) pullRelevantAccountsFromStatus(targetStatus *gtsmodel.Status) (
}
targetStatus.BoostOf.Mentions = mentions
}
}
// now get all accounts with IDs that are mentioned in the status
for _, mentionID := range targetStatus.MentionIDs {
mention := &gtsmodel.Mention{}
if err := f.db.GetByID(mentionID, mention); err != nil {
return accounts, fmt.Errorf("PullRelevantAccountsFromStatus: error getting mention with id %s: %s", mentionID, err)
for _, m := range targetStatus.BoostOf.Mentions {
if m.TargetAccount == nil {
t, err := f.db.GetAccountByID(m.TargetAccountID)
if err != nil {
return accounts, fmt.Errorf("PullRelevantAccountsFromStatus: error getting mentions from boostOf status: %s", err)
}
m.TargetAccount = t
}
accounts.BoostedMentionedAccounts = append(accounts.BoostedMentionedAccounts, m.TargetAccount)
}
mentionedAccount := &gtsmodel.Account{}
if err := f.db.GetByID(mention.TargetAccountID, mentionedAccount); err != nil {
return accounts, fmt.Errorf("PullRelevantAccountsFromStatus: error getting mentioned account: %s", err)
}
accounts.MentionedAccounts = append(accounts.MentionedAccounts, mentionedAccount)
}
return accounts, nil