From 2113ad0205e18770e1837f0efdce45c0f96bfbbd Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Wed, 14 Nov 2018 11:54:50 -0500 Subject: [PATCH] MM-13021 Fix warning logged when getting metadata for post without emojis (#9832) --- app/post_metadata.go | 4 ++++ app/post_metadata_test.go | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/post_metadata.go b/app/post_metadata.go index a1cc43b0c3..b66b2a437a 100644 --- a/app/post_metadata.go +++ b/app/post_metadata.go @@ -232,6 +232,10 @@ func (a *App) getCustomEmojisForPost(post *model.Post, reactions []*model.Reacti names := getEmojiNamesForPost(post, reactions) + if len(names) == 0 { + return []*model.Emoji{}, nil + } + return a.GetMultipleEmojiByName(names) } diff --git a/app/post_metadata_test.go b/app/post_metadata_test.go index 0aa19e5709..c71e5b64b3 100644 --- a/app/post_metadata_test.go +++ b/app/post_metadata_test.go @@ -663,6 +663,17 @@ func TestGetCustomEmojisForPost(t *testing.T) { assert.Nil(t, err, "failed to get emojis for post") assert.ElementsMatch(t, emojisForPost, []*model.Emoji{emojis[0]}, "received incorrect emojis") }) + + t.Run("with no emojis", func(t *testing.T) { + post := &model.Post{ + Message: "this post is boring", + Props: map[string]interface{}{}, + } + + emojisForPost, err := th.App.getCustomEmojisForPost(post, nil) + assert.Nil(t, err, "failed to get emojis for post") + assert.ElementsMatch(t, emojisForPost, []*model.Emoji{}, "should have received no emojis") + }) } func TestGetFirstLinkAndImages(t *testing.T) {