From bf8ffe54132c74a6fb58b5014707a17e27a484ff Mon Sep 17 00:00:00 2001 From: vcervellera Date: Mon, 12 Mar 2018 13:35:38 -0400 Subject: [PATCH] Clearing custom emojis from index and pool when necessary --- src/utils/emoji-index.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/utils/emoji-index.js b/src/utils/emoji-index.js index ddac03f14..f4de0a2a7 100644 --- a/src/utils/emoji-index.js +++ b/src/utils/emoji-index.js @@ -5,6 +5,7 @@ var originalPool = {} var index = {} var emojisList = {} var emoticonsList = {} +var customEmojisList = [] for (let emoji in data.emojis) { let emojiData = data.emojis[emoji], @@ -25,7 +26,18 @@ for (let emoji in data.emojis) { originalPool[id] = emojiData } +function clearCustomEmojis(pool) { + customEmojisList.forEach(emoji => { + let emojiId = emoji.id || emoji.short_names[0] + + delete pool[emojiId] + delete emojisList[emojiId] + }) +} + function addCustomToPool(custom, pool) { + if (customEmojisList.length) clearCustomEmojis(pool) + custom.forEach(emoji => { let emojiId = emoji.id || emoji.short_names[0] @@ -34,13 +46,16 @@ function addCustomToPool(custom, pool) { emojisList[emojiId] = getSanitizedData(emoji) } }) + + customEmojisList = custom + index = {} } function search( value, { emojisToShowFilter, maxResults, include, exclude, custom = [] } = {} ) { - addCustomToPool(custom, originalPool) + if (customEmojisList != custom) addCustomToPool(custom, originalPool) maxResults || (maxResults = 75) include || (include = [])