diff --git a/controllers/emoji.go b/controllers/emoji.go index b95e279dc..11f8db7ef 100644 --- a/controllers/emoji.go +++ b/controllers/emoji.go @@ -14,8 +14,10 @@ import ( log "github.com/sirupsen/logrus" ) -var emojiCache = make([]models.CustomEmoji, 0) -var emojiCacheTimestamp time.Time +var ( + emojiCache = make([]models.CustomEmoji, 0) + emojiCacheTimestamp time.Time +) // getCustomEmojiList returns a list of custom emoji either from the cache or from the emoji directory. func getCustomEmojiList() []models.CustomEmoji { @@ -38,7 +40,7 @@ func getCustomEmojiList() []models.CustomEmoji { for _, f := range files { name := strings.TrimSuffix(f.Name(), path.Ext(f.Name())) emojiPath := filepath.Join(config.EmojiDir, f.Name()) - singleEmoji := models.CustomEmoji{Name: name, Emoji: emojiPath} + singleEmoji := models.CustomEmoji{Name: name, URL: emojiPath} emojiCache = append(emojiCache, singleEmoji) } diff --git a/models/emoji.go b/models/emoji.go index f2029f0b3..16ea6ae0e 100644 --- a/models/emoji.go +++ b/models/emoji.go @@ -2,6 +2,6 @@ package models // CustomEmoji represents an image that can be used in chat as a custom emoji. type CustomEmoji struct { - Name string `json:"name"` - Emoji string `json:"emoji"` + Name string `json:"name"` + URL string `json:"url"` } diff --git a/web/components/chat/ChatTextField/ChatTextField.tsx b/web/components/chat/ChatTextField/ChatTextField.tsx index 38859339e..d35ad1f8b 100644 --- a/web/components/chat/ChatTextField/ChatTextField.tsx +++ b/web/components/chat/ChatTextField/ChatTextField.tsx @@ -120,16 +120,17 @@ export default function ChatTextField(props: Props) { const handleChange = () => {}; - const handleEmojiSelect = emoji => { - console.log(emoji); - if (!emoji.native) { + const handleEmojiSelect = e => { + ReactEditor.focus(editor); + + if (e.url) { // Custom emoji - const { src } = emoji; - insertImage(editor, src); + const { url } = e; + insertImage(editor, url); } else { // Native emoji - const { native } = emoji; - Transforms.insertText(editor, native); + const { emoji } = e; + Transforms.insertText(editor, emoji); } }; @@ -153,6 +154,7 @@ export default function ChatTextField(props: Props) { renderElement={p => } placeholder="Chat message goes here..." style={{ width: '100%' }} + autoFocus />