diff options
author | 2022-09-26 11:56:01 +0200 | |
---|---|---|
committer | 2022-09-26 11:56:01 +0200 | |
commit | c4a08292ee44bc731ff90bad18a3f37e5ee8ef22 (patch) | |
tree | 1726f8450ec37f744204a857c3be2bfab17f206c /internal/processing/account | |
parent | [bugfix] more nil checks baybeeeeeeeeeeeeeeeeeeee (#854) (diff) | |
download | gotosocial-c4a08292ee44bc731ff90bad18a3f37e5ee8ef22.tar.xz |
[feature] Show + federate emojis in accounts (#837)
* Start adding account emoji
* get emojis serialized + deserialized nicely
* update tests
* set / retrieve emojis on accounts
* show account emojis in web view
* fetch emojis from db based on ids
* fix typo in test
* lint
* fix pg migration
* update tests
* update emoji checking logic
* update comment
* clarify comments + add some spacing
* tidy up loops a lil (thanks kim)
Diffstat (limited to 'internal/processing/account')
-rw-r--r-- | internal/processing/account/delete.go | 2 | ||||
-rw-r--r-- | internal/processing/account/update.go | 28 |
2 files changed, 30 insertions, 0 deletions
diff --git a/internal/processing/account/delete.go b/internal/processing/account/delete.go index bf7f60d67..3a5a9c622 100644 --- a/internal/processing/account/delete.go +++ b/internal/processing/account/delete.go @@ -259,6 +259,8 @@ selectStatusesLoop: account.HeaderMediaAttachmentID = "" account.HeaderRemoteURL = "" account.Reason = "" + account.Emojis = []*gtsmodel.Emoji{} + account.EmojiIDs = []string{} account.Fields = []gtsmodel.Field{} hideCollections := true account.HideCollections = &hideCollections diff --git a/internal/processing/account/update.go b/internal/processing/account/update.go index 47c4a2b4b..eddaeab27 100644 --- a/internal/processing/account/update.go +++ b/internal/processing/account/update.go @@ -27,6 +27,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/ap" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/config" + "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/log" @@ -46,11 +47,14 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form account.Bot = form.Bot } + var updateEmojis bool + if form.DisplayName != nil { if err := validate.DisplayName(*form.DisplayName); err != nil { return nil, gtserror.NewErrorBadRequest(err) } account.DisplayName = text.SanitizePlaintext(*form.DisplayName) + updateEmojis = true } if form.Note != nil { @@ -69,6 +73,30 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form // Set updated HTML-ified note account.Note = note + updateEmojis = true + } + + if updateEmojis { + // account emojis -- treat the sanitized display name and raw + // note like one long text for the purposes of deriving emojis + accountEmojiShortcodes := util.DeriveEmojisFromText(account.DisplayName + "\n\n" + account.NoteRaw) + account.Emojis = make([]*gtsmodel.Emoji, 0, len(accountEmojiShortcodes)) + account.EmojiIDs = make([]string, 0, len(accountEmojiShortcodes)) + + for _, shortcode := range accountEmojiShortcodes { + emoji, err := p.db.GetEmojiByShortcodeDomain(ctx, shortcode, "") + if err != nil { + if err != db.ErrNoEntries { + log.Errorf("error getting local emoji with shortcode %s: %s", shortcode, err) + } + continue + } + + if *emoji.VisibleInPicker && !*emoji.Disabled { + account.Emojis = append(account.Emojis, emoji) + account.EmojiIDs = append(account.EmojiIDs, emoji.ID) + } + } } if form.Avatar != nil && form.Avatar.Size != 0 { |