From 5a0f70fcedd7a02a159de1819082981a6fd6244f Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 14 Sep 2026 17:42:04 -0700 Subject: A reply or a mention on nostr can buzz your phone. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The push notifier now watches kind 1 for the user's pubkey beside DMs and zap receipts, and pushes who, what, and an excerpt. The worker shows "New reply to your post" or "You were mentioned" with the text, and a tap lands in the Notifications list — as ?open=notifs when a window has to be opened, or as a worker message when one already is. It has its own switch, "Replies and mentions on nostr", in Settings → Notifications, on by default like payments and DMs. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01QYJfZ4A1TDCEY4Foq3CApR --- src/sw-nwc.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/sw-nwc.js') diff --git a/src/sw-nwc.js b/src/sw-nwc.js index a166368..3919bcb 100644 --- a/src/sw-nwc.js +++ b/src/sw-nwc.js @@ -44,13 +44,16 @@ self.addEventListener('push', (e) => { payment: ['Payment received', data.amountSat ? `+${Number(data.amountSat).toLocaleString()} sats — open coinos to see it.` : 'Open coinos to see it.'], dm: dmName ? [dmName, 'sent you a message.'] : ['New message', 'You have a new private message.'], chat: ['New chat activity', 'There are new messages in your communities.'], + mention: [data.reply ? 'New reply to your post' : 'You were mentioned', data.text || 'Open coinos to see it.'], }; const [title, body] = T[data.reason] || T.chat; + // a reply lands you in the Notifications list, where it is + const target = data.reason === 'mention' ? { url: './?open=notifs', view: 'notifs' } : { url: './' }; await self.registration.showNotification(title, { body, icon: 'icon-192.png', badge: 'badge-96.png', - tag: 'notify-' + (data.reason || 'chat'), renotify: data.reason === 'payment', - data: { url: './' }, + tag: 'notify-' + (data.reason || 'chat'), renotify: data.reason === 'payment' || data.reason === 'mention', + data: target, }); })()); return; @@ -102,10 +105,15 @@ self.addEventListener('push', (e) => { self.addEventListener('notificationclick', (e) => { e.notification.close(); + const d = (e.notification && e.notification.data) || {}; e.waitUntil((async () => { const all = await self.clients.matchAll({ type: 'window', includeUncontrolled: true }); const open = all.find((c) => 'focus' in c); - if (open) return open.focus(); - if (self.clients.openWindow) return self.clients.openWindow('./'); + if (open) { + // an open window goes where the notification points, without reloading + if (d.view) { try { open.postMessage({ type: 'open', view: d.view }); } catch (_) {} } + return open.focus(); + } + if (self.clients.openWindow) return self.clients.openWindow(d.url || './'); })()); }); -- cgit v1.2.3