diff options
| author | Adam Soltys <[email protected]> | 2026-09-14 17:42:04 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-09-14 17:42:04 -0700 |
| commit | 5a0f70fcedd7a02a159de1819082981a6fd6244f (patch) | |
| tree | 41afd35f5e109e55a0767007fc20bab291fd39c4 /src/features/messages.js | |
| parent | 7a1a628366d7ef8888b49217ae04cc9bcb97799e (diff) | |
| download | coinosv3-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/features/messages.js')
| -rw-r--r-- | src/features/messages.js | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/features/messages.js b/src/features/messages.js index e39a35e..71daef8 100644 --- a/src/features/messages.js +++ b/src/features/messages.js @@ -44,6 +44,18 @@ const CACHE_MAX = 50; // messages kept per channel / per DM thread in feature st // and need no billboard. const CLIENT_TAG = ['client', 'coinos']; +// A view the URL asks to open (a notification tap): read once, then taken +// off the address so a reload doesn't repeat it. +const OPEN_VIEW = (() => { + try { + const v = new URLSearchParams(location.search).get('open'); + if (!v) return null; + const u = new URL(location.href); u.searchParams.delete('open'); + history.replaceState(null, '', u.pathname + (u.search || '')); + return v; + } catch { return null; } +})(); + export function messagesFeature(ctx) { const { h, ui, render, wallet, toast, hook } = ctx; @@ -1295,7 +1307,7 @@ export function messagesFeature(ctx) { // per-category opt-outs travel with the registration so the notifier // never sends what the user turned off (a suppressed-but-delivered push // would earn Chrome's generic "updated in background" nag instead) - const reasons = { payment: s.reasons?.payment !== false, dm: s.reasons?.dm !== false }; + const reasons = { payment: s.reasons?.payment !== false, dm: s.reasons?.dm !== false, mention: s.reasons?.mention !== false }; // Stamp the network: the same seed makes the same nostr pubkey on mainnet // AND staging, so without this the notifier fans a mainnet payment push // out to the staging PWA's subscription too — and tapping it opened @@ -1356,6 +1368,7 @@ export function messagesFeature(ctx) { : h('div', { class: 'small faint' }, t('notifOnDevice')), rowT(t('notifPayRecv'), 'payment'), rowT(t('notifDm'), 'dm'), + rowT(t('notifMention'), 'mention'), h('div', { class: 'small faint' }, t('notifChatHint'))); } @@ -5361,6 +5374,7 @@ export function messagesFeature(ctx) { let notifSeenAtOpen = 0; // what counted as new when the list was opened function openNotifs() { notifSeenAtOpen = notifSeen(); + ui.chatOpen = true; ui.msgView = 'notifs'; notifNow(); refreshNotifs(true).catch(() => {}); @@ -5572,6 +5586,14 @@ export function messagesFeature(ctx) { setTimeout(() => { try { const me = ctx.shownPubkey && ctx.shownPubkey(); if (me) prefetchProfilePage(me); } catch {} }, 2500); + // A tapped "new reply" notification lands here: as ?open=notifs when + // it had to open a window, or as a worker message when one was open. + if (OPEN_VIEW === 'notifs') setTimeout(openNotifs, 0); + try { + navigator.serviceWorker?.addEventListener('message', (ev) => { + if (ev.data && ev.data.type === 'open' && ev.data.view === 'notifs') openNotifs(); + }); + } catch {} if (urlInvite && !pendingLink) { loadLinkInvite(urlInvite); setTimeout(() => { ui.chatOpen = true; ui.msgView = 'home'; render(); }, 0); |
