Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clearing custom emojis from index and pool when necessary #172

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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