diff --git a/pages/settings/settings.pixy b/pages/settings/settings.pixy index 876347b7..f4b745d6 100644 --- a/pages/settings/settings.pixy +++ b/pages/settings/settings.pixy @@ -43,6 +43,8 @@ component Settings(user *arn.User) button.action(data-action="testNotification", data-trigger="click") Icon("paper-plane") span Send test notification + + p Notifications are currently used for forum replies only. .widget.mountable h3.widget-title diff --git a/sw/service-worker.ts b/sw/service-worker.ts index 70f4c6af..47867d4b 100644 --- a/sw/service-worker.ts +++ b/sw/service-worker.ts @@ -145,7 +145,8 @@ self.addEventListener("push", (evt: PushEvent) => { (self as any).registration.showNotification(payload.title, { body: payload.message, icon: payload.icon, - image: payload.image + image: payload.image, + data: payload.link }) ) }) @@ -155,12 +156,18 @@ self.addEventListener("pushsubscriptionchange", (evt: any) => { }) self.addEventListener("notificationclick", (evt: NotificationEvent) => { - console.log(evt) - - evt.notification.close() + let notification = evt.notification + notification.close() evt.waitUntil( (self as any).clients.matchAll().then(function(clientList) { + // If we have a link, use that link to open a new window. + let url = notification.data + + if(url) { + return (self as any).clients.openWindow(url) + } + // If there is at least one client, focus it. if(clientList.length > 0) { return clientList[0].focus()