aboutsummaryrefslogtreecommitdiffstats
path: root/src/sw-nwc.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-09-14 17:42:04 -0700
committerAdam Soltys <[email protected]>2026-09-14 17:42:04 -0700
commit5a0f70fcedd7a02a159de1819082981a6fd6244f (patch)
tree41afd35f5e109e55a0767007fc20bab291fd39c4 /src/sw-nwc.js
parent7a1a628366d7ef8888b49217ae04cc9bcb97799e (diff)
downloadcoinosv3-5a0f70fcedd7a02a159de1819082981a6fd6244f.tar.gz
coinosv3-5a0f70fcedd7a02a159de1819082981a6fd6244f.zip
A reply or a mention on nostr can buzz your phone.
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 <[email protected]> Claude-Session: https://claude.ai/code/session_01QYJfZ4A1TDCEY4Foq3CApR
Diffstat (limited to 'src/sw-nwc.js')
-rw-r--r--src/sw-nwc.js16
1 files changed, 12 insertions, 4 deletions
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 || './');
})());
});