From 2ef977a2049de6b84a93f6e6347052f5aa57b908 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 16 Jun 2021 16:48:23 -0500 Subject: [PATCH] Skip custom emojis when they match a Unicode emoji's shortcode --- app/soapbox/reducers/custom_emojis.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/soapbox/reducers/custom_emojis.js b/app/soapbox/reducers/custom_emojis.js index d2c801ade..75f8f2136 100644 --- a/app/soapbox/reducers/custom_emojis.js +++ b/app/soapbox/reducers/custom_emojis.js @@ -1,14 +1,22 @@ -import { List as ImmutableList, fromJS as ConvertToImmutable } from 'immutable'; +import { List as ImmutableList, fromJS } from 'immutable'; import { CUSTOM_EMOJIS_FETCH_SUCCESS } from '../actions/custom_emojis'; -import { search as emojiSearch } from '../features/emoji/emoji_mart_search_light'; -import { buildCustomEmojis } from '../features/emoji/emoji'; +import { emojis as emojiData } from 'soapbox/features/emoji/emoji_mart_data_light'; -const initialState = ImmutableList([]); +const initialState = ImmutableList(); + +const importEmojis = (state, emojis) => { + return fromJS(emojis).filter(emoji => { + // If a custom emoji has the shortcode of a Unicode emoji, skip it. + // Otherwise it breaks EmojiMart. + // https://gitlab.com/soapbox-pub/soapbox-fe/-/issues/610 + const shortcode = emoji.get('shortcode', '').toLowerCase(); + return !emojiData[shortcode]; + }); +}; export default function custom_emojis(state = initialState, action) { - if(action.type === CUSTOM_EMOJIS_FETCH_SUCCESS) { - state = ConvertToImmutable(action.custom_emojis); - emojiSearch('', { custom: buildCustomEmojis(state) }); + if (action.type === CUSTOM_EMOJIS_FETCH_SUCCESS) { + return importEmojis(state, action.custom_emojis); } return state;