diff options
| author | Fuwn <[email protected]> | 2025-01-28 20:59:45 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-01-28 20:59:45 -0800 |
| commit | 4911e3b2d4cc373b3996d2cffe1e469f705ae258 (patch) | |
| tree | b1ff789c201a3f03b808fc73442c84a0f530a1c1 /src/lib/Data | |
| parent | fix(layout): remove invalid local user entries (diff) | |
| download | due.moe-4911e3b2d4cc373b3996d2cffe1e469f705ae258.tar.xz due.moe-4911e3b2d4cc373b3996d2cffe1e469f705ae258.zip | |
feat(notifications): fallback on service-worker-less notifications
Diffstat (limited to 'src/lib/Data')
| -rw-r--r-- | src/lib/Data/AniList/notifications.ts | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/lib/Data/AniList/notifications.ts b/src/lib/Data/AniList/notifications.ts index b21a71e4..3b0a9648 100644 --- a/src/lib/Data/AniList/notifications.ts +++ b/src/lib/Data/AniList/notifications.ts @@ -1,3 +1,5 @@ +import { database } from "$lib/Database/IDB/user"; + export interface Notification { user: { name: string; @@ -16,18 +18,18 @@ export interface Notification { id: number; createdAt: number; type: - | 'FOLLOWING' - | 'ACTIVITY_MESSAGE' - | 'ACTIVITY_MENTION' - | 'ACTIVITY_REPLY' - | 'ACTIVITY_REPLY_SUBSCRIBED' - | 'ACTIVITY_LIKE' - | 'ACTIVITY_REPLY_LIKE' - | 'THREAD_COMMENT_MENTION' - | 'THREAD_COMMENT_REPLY' - | 'THREAD_SUBSCRIBED' - | 'THREAD_COMMENT_LIKE' - | 'THREAD_LIKE'; + | 'FOLLOWING' + | 'ACTIVITY_MESSAGE' + | 'ACTIVITY_MENTION' + | 'ACTIVITY_REPLY' + | 'ACTIVITY_REPLY_SUBSCRIBED' + | 'ACTIVITY_LIKE' + | 'ACTIVITY_REPLY_LIKE' + | 'THREAD_COMMENT_MENTION' + | 'THREAD_COMMENT_REPLY' + | 'THREAD_SUBSCRIBED' + | 'THREAD_COMMENT_LIKE' + | 'THREAD_LIKE'; } export const notifications = async (accessToken: string): Promise<Notification[] | null> => { @@ -76,3 +78,13 @@ export const notifications = async (accessToken: string): Promise<Notification[] return data['data']['Page']['notifications']; }; + +export const isNotificationQueued = (recentNotifications: Notification[] | null, lastNotificationID: number | null) => + recentNotifications && + recentNotifications.length > 0 && + (recentNotifications[0].id > (lastNotificationID as number) || + new Date(recentNotifications[0].createdAt * 1000).getTime() + 30000 > + new Date().getTime()) + +export const updateLastNotificationID = async (userID: number, recentNotifications: Notification[]) => + await database.users.update(userID, { lastNotificationID: recentNotifications[0].id }); |