From c36f9ac37b8bbdeb4def7a20ba8ea6d6b7ad12d5 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Tue, 16 Jan 2024 17:22:44 +0100 Subject: [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 --- internal/db/bundb/account.go | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'internal/db/bundb/account.go') diff --git a/internal/db/bundb/account.go b/internal/db/bundb/account.go index 43e5055e1..fdee8cb76 100644 --- a/internal/db/bundb/account.go +++ b/internal/db/bundb/account.go @@ -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( -- cgit v1.2.3