]> git.ipfire.org Git - pbs.git/commitdiff
users: Open linked URL when user clicks notifications
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 May 2023 17:38:22 +0000 (17:38 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 May 2023 17:38:22 +0000 (17:38 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/static/js/notification-worker.js

index 1610b478eed4642e80a0fd4a36a69b8e33481dfc..d80f24b1b86c71bb32b59c89f13d8e2f8cd79261 100644 (file)
@@ -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?