aboutsummaryrefslogtreecommitdiff
path: root/src/service-worker.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/service-worker.ts')
-rw-r--r--src/service-worker.ts9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/service-worker.ts b/src/service-worker.ts
index 2f70ced2..360ade75 100644
--- a/src/service-worker.ts
+++ b/src/service-worker.ts
@@ -5,7 +5,7 @@
import { build, files, version } from '$service-worker';
import { database } from './lib/Database/IDB/user';
-import { notifications } from './lib/Data/AniList/notifications';
+import { isNotificationQueued, notifications, updateLastNotificationID } from './lib/Data/AniList/notifications';
const sw = self as unknown as ServiceWorkerGlobalScope;
const CACHE = `cache-${version}`;
@@ -82,12 +82,9 @@ sw.addEventListener('push', async (event: PushEvent) => {
if (
recentNotifications &&
- recentNotifications.length > 0 &&
- (recentNotifications[0].id > (user.lastNotificationID as number) ||
- new Date(recentNotifications[0].createdAt * 1000).getTime() + 30000 >
- new Date().getTime())
+ isNotificationQueued(recentNotifications, user.lastNotificationID)
) {
- await database.users.update(user.id, { lastNotificationID: recentNotifications[0].id });
+ await updateLastNotificationID(user.id, recentNotifications)
await sw.registration.showNotification('due.moe', {
body: `${recentNotifications[0].user.name}${recentNotifications[0].context}`,
icon: recentNotifications[0].user.avatar.large || '/favicon-196x196.png',