fix(desktop): prune real-channel observed refs on thread/message read#1258
Draft
wpfleger96 wants to merge 1 commit into
Draft
fix(desktop): prune real-channel observed refs on thread/message read#1258wpfleger96 wants to merge 1 commit into
wpfleger96 wants to merge 1 commit into
Conversation
markThreadRead/markMessageRead route through markChannelRead with a synthetic thread:<root>/msg:<id> key, so its clearObserved prune looks up latestByChannelRef under that key — never the real channel — and the real channel's observed refs survive a read that covers their last badge event. The count stays correct (markers are evaluated per event), but the channel stays permanently eligible for recount, a latent liability. A new lazy prune effect, driven off the unread memo's own output, drops those dead refs when the channel is no longer counted unread. Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
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.
What this is
A latent-liability cleanup in the channel unread bookkeeping. It is not the phantom-badge fix — the phantom Will reported is working-as-designed (NIP-RS Option 1: a new reply to an unopened thread correctly lights the numeric badge), and whether passive channel-open should also clear thread-tier badges is a separate UX decision currently with Will. This PR changes none of that behavior.
The asymmetry
markThreadRead/markMessageRead(AppShell.tsx) route throughmarkChannelReadwith a syntheticthread:<root>/msg:<id>key. InsidemarkChannelRead, theclearObservedprune looks uplatestByChannelRefunder that key — which is keyed by real channel id, so the lookup is alwaysundefined,clearObservedresolves tofalse, and the prune never runs. Even if it did, it would delete the entry under the synthetic key, not the real channel's.Net: after a thread/message read covers a channel's last badge event, the real channel's
latestByChannelRefandobservedUnreadEventsByChannelRefentries are never dropped. The badge count stays correct (the unread memo re-evaluates each observed event against the current markers), but the channel remains permanently eligible for recount with dead refs — a latent liability, not a visible bug.The fix
A lazy prune effect in
useUnreadChannels, driven off the unread memo's own output. A channel that is absent fromunreadChannelIds, not forced-unread, and not active has no unread observed events left, so its observed refs are dead weight and get dropped. Pruning is invisible to the count (a covered channel and an absent one both contribute 0), so there is noreadStateVersionbump and no re-render loop. The decision logic lives in a purepruneCoveredObservedRefsinunreadChannelCounts.ts(the existing home for observed-ref mutation), making it unit-testable alongside the other observed-event helpers.Regression coverage: a thread read that covers a channel's last badge event prunes both refs, and the badge stays
0even when a catch-up REQ re-records the same already-covered event; plus the three retention paths (channel still unread, active channel, forced-unread) that must keep their refs.Note for reviewers
useUnreadChannels.tssits close to the repo's 1000-line file-size ceiling; the prune decision is therefore extracted tounreadChannelCounts.tsrather than inlined, which keeps the hook file under the limit and the logic testable as a pure function.Related: #1253 (the Phase 1 dot-tier restore, already merged) — this is the Phase 2 cleanup track from the same investigation.