aboutsummaryrefslogtreecommitdiff
path: root/src/main/resources
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-02-01 00:32:11 +0300
committerGravatar Vitaly Takmazov2023-02-01 00:32:35 +0300
commit91ba81156e85856a29f6e0aae9a8eb2756f602ba (patch)
treef63ff36a46bfdceff16c89ef4c361ce8e765c1a9 /src/main/resources
parentcd9f0535f2e52db986f40aff179731ab608d1d1f (diff)
WebPush: open specified thread from the notification
Diffstat (limited to 'src/main/resources')
-rw-r--r--src/main/resources/static/sw.js22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/main/resources/static/sw.js b/src/main/resources/static/sw.js
index 055fcf64..0520bcc1 100644
--- a/src/main/resources/static/sw.js
+++ b/src/main/resources/static/sw.js
@@ -4,10 +4,10 @@
var sw = /** @type {ServiceWorkerGlobalScope & typeof self} */ (self);
sw.addEventListener('install', function() {
- sw.skipWaiting();
+ sw.skipWaiting();
});
sw.addEventListener('activate', function() {
- sw.clients.claim();
+ sw.clients.claim();
});
sw.addEventListener('push', function(evt) {
if (evt.data) {
@@ -16,7 +16,9 @@ sw.addEventListener('push', function(evt) {
if (data.body) {
sw.registration.showNotification(data.title, {
body: data.body,
- icon: data.custom.message.user.avatar
+ icon: data.custom.message.user.avatar,
+ tag: data.tag,
+ data: data.custom.message
});
}
}
@@ -24,10 +26,22 @@ sw.addEventListener('push', function(evt) {
sw.addEventListener('notificationclick', function(evt) {
evt.waitUntil(
sw.clients.matchAll().then(function(clientList) {
+ const message = evt.notification.data;
+ const url = message.mid
+ ? message.rid
+ ? `https://juick.com/m/${message.mid}#${message.rid}`
+ : `https://juick.com/m/${message.mid}`
+ : 'https://juick.com/pm/inbox';
if (clientList.length > 0) {
+ for (var i = 0; i < clientList.length; i++) {
+ if (clientList[i].url === url) {
+ return clientList[i].focus();
+ }
+ }
+ clientList[0].navigate(url);
return clientList[0].focus();
}
- return sw.clients.openWindow('https://juick.com/');
+ return sw.clients.openWindow(url);
})
);
});