2024-08-28 04:41:08 -07:00
|
|
|
import { buildCustomEmojis } from 'pl-fe/features/emoji';
|
|
|
|
import emojiData from 'pl-fe/features/emoji/data';
|
|
|
|
import { addCustomToPool } from 'pl-fe/features/emoji/search';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2024-08-11 01:48:58 -07:00
|
|
|
import { CUSTOM_EMOJIS_FETCH_SUCCESS, type CustomEmojisAction } from '../actions/custom-emojis';
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2024-08-11 01:48:58 -07:00
|
|
|
import type { CustomEmoji } from 'pl-api';
|
2022-06-12 11:15:34 -07:00
|
|
|
|
2024-08-11 01:48:58 -07:00
|
|
|
const initialState: Array<CustomEmoji> = [];
|
2021-06-16 14:48:23 -07:00
|
|
|
|
2021-06-16 15:39:03 -07:00
|
|
|
// Populate custom emojis for composer autosuggest
|
2024-08-11 01:48:58 -07:00
|
|
|
const autosuggestPopulate = (emojis: Array<CustomEmoji>) => {
|
2021-06-16 15:39:03 -07:00
|
|
|
addCustomToPool(buildCustomEmojis(emojis));
|
|
|
|
};
|
|
|
|
|
2024-08-11 01:48:58 -07:00
|
|
|
const importEmojis = (customEmojis: Array<CustomEmoji>) => {
|
|
|
|
const emojis = customEmojis.filter((emoji) => {
|
2022-07-09 09:03:22 -07:00
|
|
|
// If a custom emoji has the shortcode of a Unicode emoji, skip it.
|
|
|
|
// Otherwise it breaks EmojiMart.
|
2022-09-04 13:15:54 -07:00
|
|
|
// https://gitlab.com/soapbox-pub/soapbox/-/issues/610
|
2024-08-11 01:48:58 -07:00
|
|
|
const shortcode = emoji.shortcode.toLowerCase();
|
2022-07-09 09:03:22 -07:00
|
|
|
return !emojiData.emojis[shortcode];
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
2024-08-11 01:48:58 -07:00
|
|
|
const custom_emojis = (state = initialState, action: CustomEmojisAction) => {
|
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;
|
2024-05-12 16:18:04 -07:00
|
|
|
};
|
|
|
|
|
2024-05-13 10:00:42 -07:00
|
|
|
export { custom_emojis as default };
|