[judy] feat(notify): OS notifications for new unread threads#60
Merged
Conversation
…posts
Trigger a Web Notification when a thread transitions read \u2192 unread,
gated on:
- user opted in via Settings \u2192 \u7cfb\u7edf\u901a\u77e5 toggle
- browser Notification permission granted
- tab hidden (visible tabs already show red dot/badge)
- thread is not the currently-open one
Implementation lives entirely client-side (no backend churn). Hooks into
the existing updateUnreadTitle() pass: every refresh diffs the current
unread-thread-id set against the previous snapshot, fires one banner per
newly-unread thread. Notification tag = thread_id (collapses repeats).
Click \u2192 window.focus() + selectThread().
Settings:
- new fieldset \u201c\u7cfb\u7edf\u901a\u77e5\u201d with a checkbox + status hint
- permission request happens on toggle-on, not on page load
- separate localStorage key (openforge.notifyPrefs.v1) so it's
portable away from the avatar prefs
First-load guard: _prevUnreadIds starts as null \u2192 first pass seeds
only, so opening the app with an existing backlog doesn't flood you
with notifications.
🤖 bot-review (comment-only · phase 1)Diff: Red-line checks:
Phase 1: this bot leaves comments only. Auto-approve will be enabled per-path after 1–2 weeks of clean runs. Promotion plan: judy PR #42 follow-up. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thread:
th_19e6e6a8a5a_2979daWhat
PWA shell (PR #46) made OpenForge feel like an app; this hooks up the matching capability — when a thread you haven't read gets a new post, you get a real macOS Notification banner (so you don't have to keep peeking at the browser tab for the red dot).
How it works
Entirely client-side. Hooked into the existing
updateUnreadTitle()pass that already runs on every poll / SSE refresh:_collectUnreadIndex()walks loaded squads and returnsMap<thread_id, {thread, squad}>of currently-unread threads._prevUnreadIds(snapshot from last tick). Anything innew \ oldis a brand-new unread → ping.new Notification(title, { tag: 'openforge:' + thread_id })— tag de-dupes if the same thread bumps twice in a tick.window.focus()+selectThread(thread_id)(and flips currentSquadId so the thread is actually visible).Guards (each independently can block a banner)
Notification.permission !== 'granted')_notifyPrefs.enabled)document.visibilityState === 'visible') — red dot is enough when you're already looking_prevUnreadIds, never notifies (avoid blasting the full backlog on app open)Settings UI
New fieldset in the Settings modal: 系统通知 with a checkbox + status label (未授权 / 已授权但未启用 / 已启用 / 浏览器拒绝了权限 / 不支持). Permission request only fires when the user toggles on — never on page load. Stored in
localStorage:openforge.notifyPrefs.v1(separate from avatar prefs).Toggling on also fires a one-shot test banner ("系统通知已启用") so the user sees what to expect.
Files
web/app.js— notify infra (~110 lines), settings wiring (~50 lines)web/index.html— new fieldset in settings modalweb/style.css— 6 lines for.notify-rowTest plan
forge updateto pullOut of scope
showNotificationfrom sw.js + push subscription. Phase 2 if needed.cc @scott