2022-06-12 11:15:34 -07:00
|
|
|
import { List as ImmutableList, Map as ImmutableMap, fromJS } from 'immutable';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-07-04 13:30:35 -07:00
|
|
|
import { buildCustomEmojis } from 'soapbox/features/emoji';
|
|
|
|
import { addCustomToPool } from 'soapbox/features/emoji/search';
|
|
|
|
// import emojiData from 'soapbox/features/emoji/data';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-01-10 14:01:24 -08:00
|
|
|
import { CUSTOM_EMOJIS_FETCH_SUCCESS } from '../actions/custom_emojis';
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-06-12 11:15:34 -07:00
|
|
|
import type { AnyAction } from 'redux';
|
|
|
|
import type { APIEntity } from 'soapbox/types/entities';
|
|
|
|
|
2021-06-16 14:48:23 -07:00
|
|
|
const initialState = ImmutableList();
|
|
|
|
|
2021-06-16 15:39:03 -07:00
|
|
|
// Populate custom emojis for composer autosuggest
|
2022-06-12 11:15:34 -07:00
|
|
|
const autosuggestPopulate = (emojis: ImmutableList<ImmutableMap<string, string>>) => {
|
2021-06-16 15:39:03 -07:00
|
|
|
addCustomToPool(buildCustomEmojis(emojis));
|
|
|
|
};
|
|
|
|
|
2022-06-12 11:15:34 -07:00
|
|
|
const importEmojis = (customEmojis: APIEntity[]) => {
|
2022-07-04 13:30:35 -07:00
|
|
|
// const emojis = (fromJS(customEmojis)).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.emojis[shortcode];
|
|
|
|
// });
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
const emojis = fromJS(customEmojis);
|
|
|
|
|
|
|
|
// @ts-ignore
|
2021-06-16 15:39:03 -07:00
|
|
|
autosuggestPopulate(emojis);
|
|
|
|
return emojis;
|
2021-06-16 14:48:23 -07:00
|
|
|
};
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-06-12 11:15:34 -07:00
|
|
|
export default function custom_emojis(state = initialState, action: AnyAction) {
|
2021-06-16 14:48:23 -07:00
|
|
|
if (action.type === CUSTOM_EMOJIS_FETCH_SUCCESS) {
|
2022-06-12 11:15:34 -07:00
|
|
|
return importEmojis(action.custom_emojis);
|
2020-03-27 13:59:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
2021-08-03 12:22:51 -07:00
|
|
|
}
|