From 5ae3774f19dd53a8d5af0044362375df11e41681 Mon Sep 17 00:00:00 2001 From: binwiederhier Date: Thu, 15 Jan 2026 19:06:05 -0500 Subject: [PATCH] Refine, docs --- web/public/sw.js | 6 ++++++ web/src/app/Notifier.js | 6 +++--- web/src/components/hooks.js | 7 +++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/web/public/sw.js b/web/public/sw.js index db87e7f8..7affd55f 100644 --- a/web/public/sw.js +++ b/web/public/sw.js @@ -163,6 +163,12 @@ const handlePushUnknown = async (data) => { const handlePush = async (data) => { const { message } = data; + // This logic is (partially) duplicated in + // - Android: SubscriberService::onNotificationReceived() + // - Android: FirebaseService::onMessageReceived() + // - Web app: hooks.js:handleNotification() + // - Web app: sw.js:handleMessage(), sw.js:handleMessageClear(), ... + if (message.event === EVENT_MESSAGE) { await handlePushMessage(data); } else if (message.event === EVENT_MESSAGE_DELETE) { diff --git a/web/src/app/Notifier.js b/web/src/app/Notifier.js index 723ec43d..f6e47a7c 100644 --- a/web/src/app/Notifier.js +++ b/web/src/app/Notifier.js @@ -26,7 +26,7 @@ class Notifier { subscriptionId: subscription.id, message: notification, defaultTitle, - topicRoute: new URL(routes.forSubscription(subscription), window.location.origin).toString() + topicRoute: new URL(routes.forSubscription(subscription), window.location.origin).toString(), }) ); } @@ -40,7 +40,7 @@ class Notifier { console.log(`[Notifier] Cancelling notification with ${tag}`); const registration = await this.serviceWorkerRegistration(); const notifications = await registration.getNotifications({ tag }); - notifications.forEach(n => n.close()); + notifications.forEach((n) => n.close()); } catch (e) { console.log(`[Notifier] Error cancelling notification`, e); } @@ -72,7 +72,7 @@ class Notifier { if (hasWebPushTopics) { return pushManager.subscribe({ userVisibleOnly: true, - applicationServerKey: urlB64ToUint8Array(config.web_push_public_key) + applicationServerKey: urlB64ToUint8Array(config.web_push_public_key), }); } diff --git a/web/src/components/hooks.js b/web/src/components/hooks.js index 1c9c2bff..9dadd551 100644 --- a/web/src/components/hooks.js +++ b/web/src/components/hooks.js @@ -51,8 +51,11 @@ export const useConnectionListeners = (account, subscriptions, users, webPushTop }; const handleNotification = async (subscriptionId, notification) => { - // Note: This logic is duplicated in the Android app in SubscriberService::onNotificationReceived() - // and FirebaseService::handleMessage(). + // This logic is (partially) duplicated in + // - Android: SubscriberService::onNotificationReceived() + // - Android: FirebaseService::onMessageReceived() + // - Web app: hooks.js:handleNotification() + // - Web app: sw.js:handleMessage(), sw.js:handleMessageClear(), ... if (notification.event === EVENT_MESSAGE_DELETE && notification.sequence_id) { await subscriptionManager.deleteNotificationBySequenceId(subscriptionId, notification.sequence_id);