Files
Messenger/web/public/notifications-sw.js
benya 4fe89ce89a
Some checks failed
CI / test (push) Failing after 21s
feat(web): service-worker notifications and composer/scroll UX fixes
- register notifications service worker and handle click-to-open chat/message

- route realtime notifications through service worker with fallback

- support ?chat=&message= deep-link navigation in chats page

- enforce 1s minimum voice message length

- lift scroll-to-bottom button to avoid overlap with composer action
2026-03-08 11:33:58 +03:00

34 lines
953 B
JavaScript

self.addEventListener("install", (event) => {
event.waitUntil(self.skipWaiting());
});
self.addEventListener("activate", (event) => {
event.waitUntil(self.clients.claim());
});
self.addEventListener("notificationclick", (event) => {
event.notification.close();
const data = event.notification.data || {};
const targetPath = typeof data.url === "string" ? data.url : "/";
const targetUrl = new URL(targetPath, self.location.origin).toString();
event.waitUntil(
self.clients.matchAll({ type: "window", includeUncontrolled: true }).then(async (clientList) => {
if (clientList.length > 0) {
const client = clientList[0];
if ("navigate" in client) {
await client.navigate(targetUrl);
}
if ("focus" in client) {
await client.focus();
}
return;
}
if (self.clients.openWindow) {
await self.clients.openWindow(targetUrl);
}
})
);
});