import type { RecordOf, List as ImmutableList } from 'immutable'; import { Record as ImmutableRecord, isList } from 'immutable'; import type { ApiCustomEmojiJSON } from 'mastodon/api_types/custom_emoji'; type CustomEmojiShape = Required; // no changes from server shape export type CustomEmoji = RecordOf; export const CustomEmojiFactory = ImmutableRecord({ shortcode: '', static_url: '', url: '', category: '', visible_in_picker: false, width: 32, height: 32, sensitive: false, aliases: [], license: '', }); export type EmojiMap = Record; export function makeEmojiMap( emojis: ApiCustomEmojiJSON[] | ImmutableList, ) { if (isList(emojis)) { return emojis.reduce((obj, emoji) => { obj[`:${emoji.shortcode}:`] = emoji.toJS() as ApiCustomEmojiJSON; return obj; }, {}); } else return emojis.reduce((obj, emoji) => { obj[`:${emoji.shortcode}:`] = emoji; return obj; }, {}); }