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

43 lines
1.1 KiB
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-04-16 11:43:55 -07:00
export type NotificationType = ''
2022-03-31 15:00:31 -07:00
| 'follow'
| 'follow_request'
| 'mention'
| 'reblog'
| 'favourite'
| 'poll'
| 'status'
| 'move'
| 'pleroma:chat_mention'
| 'pleroma:emoji_reaction';
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: '' as NotificationType,
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
};