refactor: move notification domain to lib/notification/
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
31
frontend/src/lib/notification/notifications.ts
Normal file
31
frontend/src/lib/notification/notifications.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user