Skip to content

Commit

Permalink
Merge pull request #172 from vcervellera-turbulent/bf/custom-emojis-c…
Browse files Browse the repository at this point in the history
…ontamination

Clearing custom emojis from index and pool when necessary
  • Loading branch information
EtienneLem committed Mar 27, 2018
2 parents 6bd17d3 + bf8ffe5 commit 933ea29
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/utils/emoji-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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]

Expand All @@ -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 = [])
Expand Down

0 comments on commit 933ea29

Please sign in to comment.