2024-12-10 23:54:07 +01:00
|
|
|
import type { RecordOf, List as ImmutableList } from 'immutable';
|
|
|
|
import { Record as ImmutableRecord, isList } from 'immutable';
|
2023-11-03 16:00:03 +01:00
|
|
|
|
|
|
|
import type { ApiCustomEmojiJSON } from 'flavours/glitch/api_types/custom_emoji';
|
|
|
|
|
|
|
|
type CustomEmojiShape = Required<ApiCustomEmojiJSON>; // no changes from server shape
|
|
|
|
export type CustomEmoji = RecordOf<CustomEmojiShape>;
|
|
|
|
|
2024-12-10 23:54:07 +01:00
|
|
|
export const CustomEmojiFactory = ImmutableRecord<CustomEmojiShape>({
|
2023-11-03 16:00:03 +01:00
|
|
|
shortcode: '',
|
|
|
|
static_url: '',
|
|
|
|
url: '',
|
|
|
|
category: '',
|
|
|
|
visible_in_picker: false,
|
|
|
|
});
|
2024-12-10 23:54:07 +01:00
|
|
|
|
|
|
|
export type EmojiMap = Record<string, ApiCustomEmojiJSON>;
|
|
|
|
|
|
|
|
export function makeEmojiMap(
|
|
|
|
emojis: ApiCustomEmojiJSON[] | ImmutableList<CustomEmoji>,
|
|
|
|
) {
|
|
|
|
if (isList(emojis)) {
|
|
|
|
return emojis.reduce<EmojiMap>((obj, emoji) => {
|
|
|
|
obj[`:${emoji.shortcode}:`] = emoji.toJS();
|
|
|
|
return obj;
|
|
|
|
}, {});
|
|
|
|
} else
|
|
|
|
return emojis.reduce<EmojiMap>((obj, emoji) => {
|
|
|
|
obj[`:${emoji.shortcode}:`] = emoji;
|
|
|
|
return obj;
|
|
|
|
}, {});
|
|
|
|
}
|