From f79d4a33301ac7d170b53e626e00d21a11a70d20 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 21 Oct 2021 17:09:02 -0500 Subject: [PATCH] Push notifications: switch to serviceWorkerRegistration.showNotification() --- app/soapbox/actions/notifications.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/soapbox/actions/notifications.js b/app/soapbox/actions/notifications.js index 9e569625c..9745d7e81 100644 --- a/app/soapbox/actions/notifications.js +++ b/app/soapbox/actions/notifications.js @@ -102,16 +102,17 @@ export function updateNotificationsQueue(notification, intlMessages, intlLocale, // Desktop notifications try { - if (typeof window.Notification !== 'undefined' && showAlert && !filtered) { + if (showAlert && !filtered) { const title = new IntlMessageFormat(intlMessages[`notification.${notification.type}`], intlLocale).format({ name: notification.account.display_name.length > 0 ? notification.account.display_name : notification.account.username }); const body = (notification.status && notification.status.spoiler_text.length > 0) ? notification.status.spoiler_text : unescapeHTML(notification.status ? notification.status.content : ''); - const notify = new Notification(title, { body, icon: notification.account.avatar, tag: notification.id }); - - notify.addEventListener('click', () => { - window.focus(); - notify.close(); - }); + navigator.serviceWorker.ready.then(serviceWorkerRegistration => { + serviceWorkerRegistration.showNotification(title, { + body, + icon: notification.account.avatar, + tag: notification.id, + }); + }).catch(console.error); } } catch(e) { console.warn(e);