[feature] Account alias / move API + db models (#2518)

* [feature] Account alias / move API + db models

* go fmt

* fix little cherry-pick issues

* update error checking, formatting

* add and use new util functions to simplify alias logic
This commit is contained in:
tobi 2024-01-16 17:22:44 +01:00 committed by GitHub
commit c36f9ac37b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 1243 additions and 39 deletions

View file

@ -254,7 +254,7 @@ func (a *accountDB) getAccount(ctx context.Context, lookup string, dbQuery func(
func (a *accountDB) PopulateAccount(ctx context.Context, account *gtsmodel.Account) error {
var (
err error
errs = gtserror.NewMultiError(3)
errs = gtserror.NewMultiError(5)
)
if account.AvatarMediaAttachment == nil && account.AvatarMediaAttachmentID != "" {
@ -279,6 +279,37 @@ func (a *accountDB) PopulateAccount(ctx context.Context, account *gtsmodel.Accou
}
}
if !account.AlsoKnownAsPopulated() {
// Account alsoKnownAs accounts are
// out-of-date with URIs, repopulate.
alsoKnownAs := make([]*gtsmodel.Account, 0)
for _, uri := range account.AlsoKnownAsURIs {
akaAcct, err := a.state.DB.GetAccountByURI(
gtscontext.SetBarebones(ctx),
uri,
)
if err != nil {
errs.Appendf("error populating also known as account %s: %w", uri, err)
continue
}
alsoKnownAs = append(alsoKnownAs, akaAcct)
}
account.AlsoKnownAs = alsoKnownAs
}
if account.MovedTo == nil && account.MovedToURI != "" {
// Account movedTo is not set, fetch from database.
account.MovedTo, err = a.state.DB.GetAccountByURI(
gtscontext.SetBarebones(ctx),
account.MovedToURI,
)
if err != nil {
errs.Appendf("error populating moved to account: %w", err)
}
}
if !account.EmojisPopulated() {
// Account emojis are out-of-date with IDs, repopulate.
account.Emojis, err = a.state.DB.GetEmojisByIDs(