Page MenuHomePhabricator

D6832.id22923.diff
No OneTemporary

D6832.id22923.diff

diff --git a/web/push-notif/service-worker.js b/web/push-notif/service-worker.js
--- a/web/push-notif/service-worker.js
+++ b/web/push-notif/service-worker.js
@@ -1,9 +1,46 @@
// @flow
+declare class PushMessageData {
+ json(): Object;
+}
+declare class PushEvent extends ExtendableEvent {
+ +data: PushMessageData;
+}
+
+declare var clients: Clients;
+declare function skipWaiting(): Promise<void>;
+
self.addEventListener('install', () => {
- console.log('service worker installed');
+ skipWaiting();
+});
+
+self.addEventListener('activate', (event: ExtendableEvent) => {
+ event.waitUntil(clients.claim());
+});
+
+self.addEventListener('push', (event: PushEvent) => {
+ const data = event.data.json();
+
+ event.waitUntil(
+ (async () => {
+ let body = data.body;
+ if (data.prefix) {
+ body = `${data.prefix} ${body}`;
+ }
+ await self.registration.showNotification(data.title, {
+ body,
+ badge: 'https://web.comm.app/favicon.ico',
+ icon: 'https://web.comm.app/favicon.ico',
+ tag: data.id,
+ data: {
+ unreadCount: data.unreadCount,
+ threadID: data.threadID,
+ },
+ });
+ })(),
+ );
});
-self.addEventListener('activate', () => {
- console.log('service worker activated');
+self.addEventListener('notificationclick', (event: NotificationEvent) => {
+ event.notification.close();
});

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 22, 7:29 PM (17 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2692240
Default Alt Text
D6832.id22923.diff (1 KB)

Event Timeline