diff options
| -rw-r--r-- | src/service-worker.ts | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/service-worker.ts b/src/service-worker.ts index d7629073..21de63a2 100644 --- a/src/service-worker.ts +++ b/src/service-worker.ts @@ -114,7 +114,9 @@ sw.addEventListener('push', async (event: PushEvent) => { sw.registration.showNotification('due.moe', { body: `${recentNotifications[0].user.name}${recentNotifications[0].context}`, - icon: recentNotifications[0].user.avatar.large || '/favicon-196x196.png' + icon: recentNotifications[0].user.avatar.large || '/favicon-196x196.png', + // Ref. https://stackoverflow.com/a/50805868/14452787 + tag: 'notification-1' }); return; @@ -123,11 +125,17 @@ sw.addEventListener('push', async (event: PushEvent) => { console.error(error); } - event.waitUntil( - new Promise(() => { - // - }) - ); + // Ref. https://github.com/firebase/quickstart-js/issues/126#issuecomment-504081087 + return new Promise((resolve) => { + (resolve as unknown as () => void)(); + setTimeout(() => { + sw.registration.getNotifications().then((notifications) => { + notifications.forEach((notification) => { + if (notification.tag !== 'notification') notification.close(); + }); + }); + }, 10); + }); }); sw.addEventListener('notificationclick', (event: NotificationEvent) => { |