From 25d77d513244a19cf0cf7cf39bc48c2826cd5676 Mon Sep 17 00:00:00 2001 From: Kris Hu Date: Mon, 14 Jul 2025 15:08:11 +0800 Subject: [PATCH] fix(push): use unique tag for push notifications --- src/sw.ts | 4 ++-- src/sw/pushNotification.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sw.ts b/src/sw.ts index 7a95dd8c..a58d60c8 100644 --- a/src/sw.ts +++ b/src/sw.ts @@ -145,7 +145,7 @@ const onPushNotification = async (event: PushEvent) => { self.navigator.setAppBadge(pushData.unread); if (pushData.unread == 0) { - self.registration.getNotifications({ tag: "Cinny" }) + self.registration.getNotifications() .then((notifications) => notifications .forEach((notification) => notification.close())); await navigator.clearAppBadge(); @@ -158,7 +158,7 @@ const onPushNotification = async (event: PushEvent) => { // Likely Firefox/Gecko-based and doesn't support badging API } - handlePushNotificationPushData(pushData); + await handlePushNotificationPushData(pushData); }; self.addEventListener('push', (event: PushEvent) => event.waitUntil(onPushNotification(event))); diff --git a/src/sw/pushNotification.ts b/src/sw/pushNotification.ts index cbcd21b2..f1331ff5 100644 --- a/src/sw/pushNotification.ts +++ b/src/sw/pushNotification.ts @@ -9,13 +9,13 @@ export const usePushNotifications = (self: ServiceWorkerGlobalScope) => { title: string, body: string, data: any, - silent: boolean = false + silent: boolean | null = null ) => { await self.registration.showNotification(title, { body, icon: DEFAULT_NOTIFICATION_ICON, badge: DEFAULT_NOTIFICATION_BADGE, - tag: "Cinny", + tag: data?.event_id ?? "Cinny", silent, data });