diff --git a/public/service_worker.js b/public/service_worker.js index f9fa4973..7b903ecd 100644 --- a/public/service_worker.js +++ b/public/service_worker.js @@ -4,9 +4,19 @@ self.addEventListener('push', function (event) { console.log(event.data); event.waitUntil(self.registration.showNotification(notification.title, { - body: notification.body + body: notification.body, + tag: notification.type })); } else { console.error("Push event received, but it didn't contain any data.", event); } }); + +self.addEventListener('notificationclick', async event => { + if (event.notification.tag === 'inbox') { + event.preventDefault(); + return clients.openWindow("/inbox", "_blank"); + } else { + console.warn(`Unhandled notification tag: ${event.notification.tag}`); + } +});