diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-10-09 12:08:31 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-10-09 12:08:31 +0200 |
| commit | 6832df6177ad973ad0e1b4f0a49d7a6da06c6e04 (patch) | |
| tree | d9040ce0da5d82400d1b973344615ca1c6b67b3c /packages/meshbay-hub/src/meshbay_hub/static/settings-page.js | |
| parent | 2860f1de75af1d44d35292ecbf79c68f02409d19 (diff) | |
| download | meshbay-6832df6177ad973ad0e1b4f0a49d7a6da06c6e04.tar.gz | |
feat: notifications on Android while closed, with nothing to install
The phone fetches what is new every fifteen minutes with a poll secret
(POST /v1/push/poll) that reads notification lines and nothing else. When a
UnifiedPush distributor is already installed, the hub also pushes at once,
encrypted to the phone (RFC 8291); losing the distributor falls back to
fetching.
The hub now honours "disable all notifications" itself: create_notification
creates nothing for that account, as it already did for a muted group, so
neither switch lets anything reach a phone. The interface used to be the only
reader of the account-wide switch.
Push endpoints are member-supplied URLs: a send refuses non-public
addresses, connects to the address it checked, and follows no redirect.
Android build untested here (no SDK on this machine).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/settings-page.js')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/static/settings-page.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/settings-page.js b/packages/meshbay-hub/src/meshbay_hub/static/settings-page.js index 8755556..985b219 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/settings-page.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/settings-page.js @@ -5,6 +5,7 @@ import { t, getLocale, setLocale, LOCALES } from './i18n.js'; import * as downloads from './downloads.js'; import * as platform from './platform.js'; import { hubFetch } from './hub-client.js'; +import { syncPush, enablePush, disablePush } from './push.js'; import { APPS } from './apps.js'; import { PAGE_SIZE_PREF, PAGE_SIZE_DEFAULT, PAGE_SIZE_STEP, PAGE_SIZE_MAX, pageSizeFrom, @@ -81,6 +82,35 @@ export function SettingsPage({ user, theme, onThemeChange, groups, onPrefsChange } }, [globalMute, user.token, onPrefsChange]); + // Notifications on this phone (Android only: `platform.push.available`). + const [push, setPush] = useState(null); + const [pushBusy, setPushBusy] = useState(false); + useEffect(() => { + if (!platform.push.available) return; + syncPush(user).catch(() => platform.push.status()).then(setPush).catch(() => {}); + }, [user]); + + const togglePush = useCallback(async () => { + if (pushBusy) return; + setPushBusy(true); + try { + setPush(push && push.enabled ? await disablePush(user) : await enablePush(user, setPush)); + } catch (err) { + setPush(await platform.push.status().catch(() => null)); + } finally { + setPushBusy(false); + } + }, [push, pushBusy, user]); + + const pushHint = () => { + if (!push) return null; + if (globalMute) return t('settings.push_global_off'); + if (!push.enabled) return t('settings.push_off'); + if (!push.permitted) return t('settings.push_blocked'); + if (push.state === 'pending') return t('settings.push_pending'); + return push.endpoint ? t('settings.push_ready') : t('settings.push_poll'); + }; + const toggleMute = useCallback(async (gid) => { const next = !muted[gid]; setMuted(prev => ({ ...prev, [gid]: next })); @@ -240,6 +270,17 @@ export function SettingsPage({ user, theme, onThemeChange, groups, onPrefsChange <span class="toggle-switch-track"><span class="toggle-switch-thumb"></span></span> </label> </div> + ${push && html` + <div class="settings-row"> + <span class="settings-label">${t('settings.push_label')}</span> + <label class="toggle-switch"> + <input type="checkbox" checked=${!!push.enabled} disabled=${pushBusy} + onChange=${togglePush} /> + <span class="toggle-switch-track"><span class="toggle-switch-thumb"></span></span> + </label> + </div> + <p class="settings-hint">${pushHint()}</p> + `} ${!globalMute && html` <p class="settings-hint" style="margin-bottom:8px">${t('settings.notif_global_hint')}</p> ${groups.map(g => html` |