feat(commission) : add push notifications and unread ticket titles
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
self.addEventListener("push", (event) => {
|
||||
if (!event.data) return;
|
||||
const message = event.data.json();
|
||||
event.waitUntil(self.registration.showNotification(message.title, {
|
||||
body: message.body,
|
||||
icon: "/icon.png",
|
||||
tag: message.id,
|
||||
data: { url: message.url },
|
||||
}));
|
||||
});
|
||||
|
||||
self.addEventListener("notificationclick", (event) => {
|
||||
event.notification.close();
|
||||
const url = new URL(event.notification.data.url, self.location.origin);
|
||||
if (url.origin !== self.location.origin) return;
|
||||
event.waitUntil((async () => {
|
||||
const windows = await self.clients.matchAll({ type: "window", includeUncontrolled: true });
|
||||
const existing = windows.find((client) => client.url === url.href);
|
||||
if (existing) return existing.focus();
|
||||
return self.clients.openWindow(url.href);
|
||||
})());
|
||||
});
|
||||
Reference in New Issue
Block a user