/** * Notification normalizer: * Converts API notifications into our internal format. * @see {@link https://docs.joinmastodon.org/entities/notification/} */ import { Map as ImmutableMap, Record as ImmutableRecord, fromJS, } from 'immutable'; import type { Account, Status, EmbeddedEntity } from 'soapbox/types/entities'; type NotificationType = '' | 'follow' | 'follow_request' | 'mention' | 'reblog' | 'favourite' | 'poll' | 'status' | 'move' | 'pleroma:chat_mention' | 'pleroma:emoji_reaction'; // https://docs.joinmastodon.org/entities/notification/ export const NotificationRecord = ImmutableRecord({ account: null as EmbeddedEntity, chat_message: null as ImmutableMap | string | null, // pleroma:chat_mention created_at: new Date(), emoji: null as string | null, // pleroma:emoji_reaction id: '', status: null as EmbeddedEntity, target: null as EmbeddedEntity, // move type: '' as NotificationType, }); export const normalizeNotification = (notification: Record) => { return NotificationRecord( ImmutableMap(fromJS(notification)), ); };