bigbuffet-rw/app/soapbox/normalizers/announcement_reaction.ts
marcin mikołajczak b3b6a7e4bc Announcements
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2022-07-07 23:10:09 +02:00

22 lines
822 B
TypeScript

/**
* Announcement reaction normalizer:
* Converts API announcement emoji reactions into our internal format.
* @see {@link https://docs.joinmastodon.org/entities/announcementreaction/}
*/
import { Map as ImmutableMap, Record as ImmutableRecord, fromJS } from 'immutable';
// https://docs.joinmastodon.org/entities/announcement/
export const AnnouncementReactionRecord = ImmutableRecord({
name: '',
count: 0,
me: false,
url: null as string | null,
static_url: null as string | null,
announcement_id: '',
});
export const normalizeAnnouncementReaction = (announcementReaction: Record<string, any>, announcementId?: string) => {
return AnnouncementReactionRecord(ImmutableMap(fromJS(announcementReaction)).withMutations(reaction => {
reaction.set('announcement_id', announcementId as any);
}));
};