summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/emoji/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/emoji/index.js')
-rw-r--r--app/assets/javascripts/emoji/index.js29
1 files changed, 19 insertions, 10 deletions
diff --git a/app/assets/javascripts/emoji/index.js b/app/assets/javascripts/emoji/index.js
index 478e3f6aed9..b507792cc91 100644
--- a/app/assets/javascripts/emoji/index.js
+++ b/app/assets/javascripts/emoji/index.js
@@ -1,26 +1,31 @@
import { escape, minBy } from 'lodash';
+import emojiRegexFactory from 'emoji-regex';
import emojiAliases from 'emojis/aliases.json';
-import { sanitize } from '~/lib/dompurify';
import AccessorUtilities from '../lib/utils/accessor';
import axios from '../lib/utils/axios_utils';
-import { CATEGORY_ICON_MAP, FREQUENTLY_USED_KEY } from './constants';
+import { CACHE_KEY, CACHE_VERSION_KEY, CATEGORY_ICON_MAP, FREQUENTLY_USED_KEY } from './constants';
let emojiMap = null;
let validEmojiNames = null;
export const FALLBACK_EMOJI_KEY = 'grey_question';
// Keep the version in sync with `lib/gitlab/emoji.rb`
-export const EMOJI_VERSION = '1';
+export const EMOJI_VERSION = '2';
const isLocalStorageAvailable = AccessorUtilities.canUseLocalStorage();
async function loadEmoji() {
if (
isLocalStorageAvailable &&
- window.localStorage.getItem('gl-emoji-map-version') === EMOJI_VERSION &&
- window.localStorage.getItem('gl-emoji-map')
+ window.localStorage.getItem(CACHE_VERSION_KEY) === EMOJI_VERSION &&
+ window.localStorage.getItem(CACHE_KEY)
) {
- return JSON.parse(window.localStorage.getItem('gl-emoji-map'));
+ const emojis = JSON.parse(window.localStorage.getItem(CACHE_KEY));
+ // Workaround because the pride flag is broken in EMOJI_VERSION = '1'
+ if (emojis.gay_pride_flag) {
+ emojis.gay_pride_flag.e = '🏳️‍🌈';
+ }
+ return emojis;
}
// We load the JSON file direct from the server
@@ -29,15 +34,19 @@ async function loadEmoji() {
const { data } = await axios.get(
`${gon.relative_url_root || ''}/-/emojis/${EMOJI_VERSION}/emojis.json`,
);
- window.localStorage.setItem('gl-emoji-map-version', EMOJI_VERSION);
- window.localStorage.setItem('gl-emoji-map', JSON.stringify(data));
+ window.localStorage.setItem(CACHE_VERSION_KEY, EMOJI_VERSION);
+ window.localStorage.setItem(CACHE_KEY, JSON.stringify(data));
return data;
}
async function loadEmojiWithNames() {
- return Object.entries(await loadEmoji()).reduce((acc, [key, value]) => {
- acc[key] = { ...value, name: key, e: sanitize(value.e) };
+ const emojiRegex = emojiRegexFactory();
+ return Object.entries(await loadEmoji()).reduce((acc, [key, value]) => {
+ // Filter out entries which aren't emojis
+ if (value.e.match(emojiRegex)?.[0] === value.e) {
+ acc[key] = { ...value, name: key };
+ }
return acc;
}, {});
}