bigbuffet-rw/app/soapbox/normalizers/notification.ts

32 lines
998 B
TypeScript
Raw Normal View History

2022-03-12 13:01:00 -08:00
/**
* Notification normalizer:
* Converts API notifications into our internal format.
* @see {@link https://docs.joinmastodon.org/entities/notification/}
*/
2022-03-11 10:13:36 -08:00
import {
Map as ImmutableMap,
Record as ImmutableRecord,
2022-03-16 19:33:09 -07:00
fromJS,
2022-03-11 10:13:36 -08:00
} from 'immutable';
2022-03-31 15:00:31 -07:00
import type { Account, Status, EmbeddedEntity } from 'soapbox/types/entities';
2022-03-11 10:13:36 -08:00
// https://docs.joinmastodon.org/entities/notification/
2022-03-16 19:15:38 -07:00
export const NotificationRecord = ImmutableRecord({
2022-03-31 15:00:31 -07:00
account: null as EmbeddedEntity<Account>,
chat_message: null as ImmutableMap<string, any> | string | null, // pleroma:chat_mention
2022-03-11 10:13:36 -08:00
created_at: new Date(),
2022-03-31 15:00:31 -07:00
emoji: null as string | null, // pleroma:emoji_reaction
2022-03-11 10:13:36 -08:00
id: '',
2022-03-31 15:00:31 -07:00
status: null as EmbeddedEntity<Status>,
target: null as EmbeddedEntity<Account>, // move
type: '',
2022-05-24 13:49:59 -07:00
total_count: null as number | null, // grouped notifications
2022-03-11 10:13:36 -08:00
});
2022-03-16 19:33:09 -07:00
export const normalizeNotification = (notification: Record<string, any>) => {
return NotificationRecord(
ImmutableMap(fromJS(notification)),
);
2022-03-11 10:13:36 -08:00
};