pleroma/app/soapbox/reducers/custom_emojis.js

24 lines
820 B
JavaScript
Raw Normal View History

import { List as ImmutableList, fromJS } from 'immutable';
2020-03-27 13:59:38 -07:00
import { CUSTOM_EMOJIS_FETCH_SUCCESS } from '../actions/custom_emojis';
import { emojis as emojiData } from 'soapbox/features/emoji/emoji_mart_data_light';
2020-03-27 13:59:38 -07:00
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];
});
};
2020-03-27 13:59:38 -07:00
export default function custom_emojis(state = initialState, action) {
if (action.type === CUSTOM_EMOJIS_FETCH_SUCCESS) {
return importEmojis(state, action.custom_emojis);
2020-03-27 13:59:38 -07:00
}
return state;
};