Files
familienarchiv/frontend/src/lib/notification/notifications.ts
2026-05-05 14:22:02 +02:00

32 lines
736 B
TypeScript

export type NotificationItem = {
id: string;
type: 'REPLY' | 'MENTION';
documentId: string;
referenceId: string;
annotationId: string | null;
read: boolean;
createdAt: string;
actorName: string;
documentTitle: string | null;
};
export { relativeTime } from '$lib/utils/time';
export function parseNotificationEvent(raw: string): NotificationItem | null {
try {
const parsed = JSON.parse(raw);
if (
typeof parsed.id !== 'string' ||
typeof parsed.documentId !== 'string' ||
typeof parsed.actorName !== 'string' ||
!['REPLY', 'MENTION'].includes(parsed.type)
) {
console.warn('Unexpected SSE payload shape:', parsed);
return null;
}
return parsed as NotificationItem;
} catch {
return null;
}
}