diff --git a/atproto-notifications/src/pages/Early.tsx b/atproto-notifications/src/pages/Early.tsx index 4d68403..f63e735 100644 --- a/atproto-notifications/src/pages/Early.tsx +++ b/atproto-notifications/src/pages/Early.tsx @@ -1,6 +1,7 @@ import { useCallback, useState } from 'react'; import { Link, useSearchParams } from 'react-router'; -import { postJson } from '../components/Fetch'; +import { GetJson, postJson } from '../components/Fetch'; +import { ButtonGroup } from '../components/Buttons'; import './Early.css'; export function Early({ }) { @@ -8,6 +9,7 @@ export function Early({ }) { const [notified, setNotified] = useState(false); const [pushStatus, setPushStatus] = useState(null); const [pushed, setPushed] = useState(false); + const [notifyToggleCounter, setNotifyToggleCounter] = useState(0); const returning = !searchParams.has('hello'); @@ -35,6 +37,21 @@ export function Early({ }) { setPushed(true); }); + // TODO move up (to chrome?) so it syncs + const setGlobalNotifications = useCallback(async enabled => { + // setSecretDevStatus('pending'); + const host = import.meta.env.VITE_NOTIFICATIONS_HOST; + const url = new URL('/global-notify', host); + try { + await postJson(url, JSON.stringify({ notify_enabled: enabled }), true) + // setSecretDevStatus(null); + } catch (err) { + console.error('failed to set self-notify setting', err); + // setSecretDevStatus('failed'); + } + setNotifyToggleCounter(n => n + 1); + }); + return (

Hello!

@@ -72,6 +89,24 @@ export function Early({ }) { {(returning || (pushed && pushStatus !== 'failed')) && ( <>

Great!

+

You're all set up to enable notifications:

+ + ( + ⏸  pause{!notify_enabled && 'd'}}, + {val: 'active', label: <>▶  {notify_enabled ? 'notifications active' : 'enable notifications'}}, + ]} + current={notify_enabled ? 'active' : 'paused'} + onChange={val => setGlobalNotifications(val === 'active')} + /> + )} + /> +

You can get back to this page by clicking the early early diff --git a/server/notifications.js b/server/notifications.js index cf33ce0..0f450e7 100644 --- a/server/notifications.js +++ b/server/notifications.js @@ -69,8 +69,6 @@ const isTorment = source => { parts.reverse(); parts = parts.join('.'); - // const unreversed = parts.toReversed().join('.'); - const app = psl.parse(parts)?.domain ?? 'unknown'; let appPrefix = app.split('.'); @@ -130,7 +128,10 @@ const handleDust = db => async event => { // this works for now since only the account owner is assumed to be a notification target // but for "replies on post" etc that won't hold const { notify_enabled, notify_self } = db.getNotifyAccountGlobals(did); - if (!notify_enabled) console.warn('would drop this since notifies are not enabled (ui todo)'); + if (!notify_enabled) { + console.warn('dropping notification for global not-enabled setting'); + return; + } if (!notify_self) { const source_did = extractUriDid(source_record); if (!source_did) {