From: Michael Tremer Date: Fri, 19 May 2023 17:38:22 +0000 (+0000) Subject: users: Open linked URL when user clicks notifications X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=320b65cf79d326b3f66b7e448a3ecf7f894ab1ca;p=pbs.git users: Open linked URL when user clicks notifications Signed-off-by: Michael Tremer --- diff --git a/src/static/js/notification-worker.js b/src/static/js/notification-worker.js index 1610b478..d80f24b1 100644 --- a/src/static/js/notification-worker.js +++ b/src/static/js/notification-worker.js @@ -1,5 +1,8 @@ 'use strict'; +/* + Handle an incoming push notification +*/ self.addEventListener("push", function(event) { var data = {}; @@ -10,6 +13,9 @@ self.addEventListener("push", function(event) { // Nothing } + // Pass the data on for follow-up events + data.data = data; + // Log what we have received console.debug("Push notification has been received: " + data); @@ -29,9 +35,14 @@ self.addEventListener("notificationclick", function(event) { // Close the notification event.notification.close(); - event.waitUntil( - clients.openWindow('https://developers.google.com/web/') - ); + const url = event.notification.data.url; + + // Open the URL if any + if (url) { + event.waitUntil( + clients.openWindow(url) + ); + } }); // pushsubscriptionchange Handle this?