From b59b6c132d9912fcee0af4d91e984d530c2b68d5 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Wed, 13 Dec 2023 22:35:19 +0200 Subject: [PATCH] undo all that crap --- src/sw.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/sw.js b/src/sw.js index 8a54e20c1..86f6e6949 100644 --- a/src/sw.js +++ b/src/sw.js @@ -59,19 +59,24 @@ const setSettings = async () => { } const showPushNotification = async (event) => { - // const activeClients = await getWindowClients() + const activeClients = await getWindowClients() await setSettings() // Only show push notifications if all tabs/windows are closed - const data = event.data.json() + if (activeClients.length === 0) { + const data = event.data.json() - const url = `${self.registration.scope}api/v1/notifications/${data.notification_id}` - const notification = await fetch(url, { headers: { Authorization: 'Bearer ' + data.access_token } }) - const notificationJson = await notification.json() - const parsedNotification = parseNotification(notificationJson) + const url = `${self.registration.scope}api/v1/notifications/${data.notification_id}` + const notification = await fetch(url, { headers: { Authorization: 'Bearer ' + data.access_token } }) + const notificationJson = await notification.json() + const parsedNotification = parseNotification(notificationJson) - const res = prepareNotificationObject(parsedNotification, i18n) + const res = prepareNotificationObject(parsedNotification, i18n) - return self.registration.showNotification(res.title, res) + if (state.allowedNotificationTypes.has(parsedNotification.type)) { + return self.registration.showNotification(res.title, res) + } + } + return Promise.resolve() } self.addEventListener('push', async (event) => {