From 4cd00d546c495b085487d11f2fe2c4928600dc10 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Mon, 14 Nov 2022 23:47:27 +0100 Subject: [feature] Allow newly uploaded emojis to be placed in categories (#939) * [feature] Add emoji categories GET Serialize emojis in appropriate categories; make it possible to get categories via the admin API * [feature] Create (or use existing) category for new emoji uploads * fix lint issue * update misleading line in swagger docs --- internal/typeutils/internaltofrontend.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'internal/typeutils/internaltofrontend.go') diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index b2e2279bb..ac834f78d 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -356,12 +356,24 @@ func (c *converter) MentionToAPIMention(ctx context.Context, m *gtsmodel.Mention } func (c *converter) EmojiToAPIEmoji(ctx context.Context, e *gtsmodel.Emoji) (model.Emoji, error) { + var category string + if e.CategoryID != "" { + if e.Category == nil { + var err error + e.Category, err = c.db.GetEmojiCategory(ctx, e.CategoryID) + if err != nil { + return model.Emoji{}, err + } + } + category = e.Category.Name + } + return model.Emoji{ Shortcode: e.Shortcode, URL: e.ImageURL, StaticURL: e.ImageStaticURL, VisibleInPicker: *e.VisibleInPicker, - Category: e.CategoryID, + Category: category, }, nil } @@ -383,6 +395,13 @@ func (c *converter) EmojiToAdminAPIEmoji(ctx context.Context, e *gtsmodel.Emoji) }, nil } +func (c *converter) EmojiCategoryToAPIEmojiCategory(ctx context.Context, category *gtsmodel.EmojiCategory) (*model.EmojiCategory, error) { + return &model.EmojiCategory{ + ID: category.ID, + Name: category.Name, + }, nil +} + func (c *converter) TagToAPITag(ctx context.Context, t *gtsmodel.Tag) (model.Tag, error) { return model.Tag{ Name: t.Name, -- cgit v1.2.3