diff options
author | 2022-09-06 12:42:55 +0200 | |
---|---|---|
committer | 2022-09-06 12:42:55 +0200 | |
commit | a872ddebe67c7b76cbb78667224b393a847834ac (patch) | |
tree | 28b7d0081ee12ab9928eff0aecd6b55d32d8228d /internal/processing/status/util.go | |
parent | [bugfix] Catch json syntax errors in the frontend + display a more helpful me... (diff) | |
download | gotosocial-a872ddebe67c7b76cbb78667224b393a847834ac.tar.xz |
[feature] Custom emoji updates (serve emoji via s2s api, tune db models) (#805)
* migrate emojis
* add get emoji to s2s (federation) API
* add new emoji db + cache functions
* add shortcodeDomain lookup for emojis
* check existing emojis w/cache, not w/constraints
* go fmt
* add putEmoji func
* use new db emoji funcs instead of where
* remove emojistringstotags func
* add unique constraint back in
* fix up broken migration
* update index
Diffstat (limited to 'internal/processing/status/util.go')
-rw-r--r-- | internal/processing/status/util.go | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/internal/processing/status/util.go b/internal/processing/status/util.go index 13c5b958f..880de1db3 100644 --- a/internal/processing/status/util.go +++ b/internal/processing/status/util.go @@ -249,18 +249,27 @@ func (p *processor) ProcessTags(ctx context.Context, form *apimodel.AdvancedStat } func (p *processor) ProcessEmojis(ctx context.Context, form *apimodel.AdvancedStatusCreateForm, accountID string, status *gtsmodel.Status) error { - gtsEmojis, err := p.db.EmojiStringsToEmojis(ctx, util.DeriveEmojisFromText(form.Status)) - if err != nil { - return fmt.Errorf("error generating emojis from status: %s", err) - } - emojis := make([]string, 0, len(gtsEmojis)) - for _, e := range gtsEmojis { - emojis = append(emojis, e.ID) + // for each emoji shortcode in the text, check if it's an enabled + // emoji on this instance, and if so, add it to the status + emojiShortcodes := util.DeriveEmojisFromText(form.Status) + status.Emojis = make([]*gtsmodel.Emoji, 0, len(emojiShortcodes)) + status.EmojiIDs = make([]string, 0, len(emojiShortcodes)) + + for _, shortcode := range emojiShortcodes { + 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 { + status.Emojis = append(status.Emojis, emoji) + status.EmojiIDs = append(status.EmojiIDs, emoji.ID) + } } - // add full populated gts emojis to the status for passing them around conveniently - status.Emojis = gtsEmojis - // add just the ids of the used emojis to the status for putting in the db - status.EmojiIDs = emojis + return nil } |