Repository navigation
feat(messages): let a plugin sort, filter and page a reader's rows - #3660
LordMelkor wants to merge 1 commit into
Conversation
joahg
left a comment
There was a problem hiding this comment.
🤖 Commenting rather than approving. This changes what users see in the conversation UI and touches FOUNDATION files, so it needs a design or core-team reviewer. Please get a maintainer sign-off on the three FOUNDATION files: src/features/conversation/contracts.ts, src/features/conversation/service.tsx and src/plugins/author.ts. The edits are additive (an optional arrangers extension, registerArranger, type exports), but they add a new plugin power, so the contract itself is worth a deliberate decision.
Worst issue: P2, no blocker found. What I checked:
- Contract:
arrangersis optional onConversationExtensionsand existing plugins are unaffected. A plugin built against the new types will throw on an older host (registerArrangeris undefined), so authors should feature-detect.ThreadView.loadAllis a required addition to the view type, so any otherThreadViewfake or implementer needs it too; the PR updates one test fake and CI is still running. - Misbehaving plugin: a throwing
includeor a throwing/non-finitecompareis caught, and the arranger is contained byContributionBoundaryand revoked on retire. A hunginclude/comparestill blocks the main thread, as any plugin code can. A filter that matches nothing can drive the channel fill loop past the 5-page cap, but it is bounded byhistoryLimited; thread loads are bounded by the 2,000 event / 4 MiB budget. - What a plugin can now do: silently hide any reply in a thread or channel (other than the root, the selected message and the viewer's own sends) and reorder thread replies, with no host-drawn indicator that a filter or order is active, and a channel filter that hides everything shows a blank list. Message renderers can already mislead somewhat, but this is a stronger and quieter lever. A visible host indicator (or a way to see hidden counts) seems worth deciding before this ships as a generic extension point.
- Read state: the channel timeline still passes unfiltered
window.rowstouseReading(latestMessageId), while the boundary and rendering use the filtered rows. If the newest row is hidden, catch-up never fires (unread badge can stick); if the newest row is shown but earlier ones are hidden, reaching the bottom catches up rows the user never saw. Mentions and broadcasts are not read by catch-up, so those stay unread. The description says unread logic is unchanged; I would like that behaviour confirmed as intended, with a test. - Paging and anchoring: the place rules, nearest-row hand-off, StrictMode replay handling and the
refilteredguard against counting re-shown rows as new read plausibly. I could not verify real-browser Virtua behaviour; the author notes it is untested and the tests use a mocked virtualizer. - Tests: substantial unit and viewport coverage. CI was still running when I looked (JavaScript, Browser journeys, Flake checks, Rust), so the result is unknown.
Not reviewed in depth: the loadAll staging and budget logic in relay/threads.ts beyond a read-through, the full ThreadPanel scroll-placement effect, the ~1,100 lines of test code, and the docs wording.
| !window.hasMore && !window.historyLimited, | ||
| ) | ||
| : window.rows, | ||
| includedReplies( |
There was a problem hiding this comment.
🤖 include filters here, but useReading below still gets latestMessageId from the unfiltered window.rows. If the newest row is hidden the channel never catches up; if it is shown while earlier rows are hidden, catch-up marks rows the user never saw. Is that the intended read behaviour with a filter, and is there a test for it?
| * applies an order once the whole thread is loaded. A throwing `include` shows | ||
| * every reply; a throwing or non-finite `compare` keeps host order. */ | ||
| export type ConversationArrangement = Readonly<{ | ||
| include?(row: ChannelMessage): boolean; |
There was a problem hiding this comment.
🤖 Design question for a maintainer: any plugin with conversation can now hide replies with no host-visible indicator that a filter is active (and a channel filter that hides everything shows a blank list). Should the host show a minimal active-arrangement marker, or a hidden-row count, so a plugin cannot hide messages silently?
| if (next === HOST_ARRANGEMENT) setOwnSent(new Set()); | ||
| // Reading starts in this commit, so a thread held at the page limit is | ||
| // not ordered before the rest of it arrives. | ||
| else void view.loadAll(); |
There was a problem hiding this comment.
🤖 This reads the whole thread (up to 2,000 events / 4 MiB) for any arrangement, including an include-only filter that does not need the whole thread. Consider calling loadAll only when compare is set, or confirm the filter case needs it.
joahg
left a comment
There was a problem hiding this comment.
🤖 Followup on 63f8f80. The fix looks right. Judging a change against the arrangement the reader last rendered, rather than the last one published, turns an effect's cleanup and setup in the same pass into a single change, so the same order keeps the reader's place. Own sends are now cleared only when the host order actually renders, so a withdraw-and-republish no longer drops them either. The new test covers the authoring example's lifecycle.
My earlier points still apply: channel read marking uses the unfiltered rows, there's no host-visible sign that an arrangement is hiding messages, and loadAll runs for include-only filters. This is still Buzz UI that touches FOUNDATION files, so it needs a design or core-team reviewer and a maintainer's sign-off, and I'm commenting rather than approving.
63f8f80 to
b18c1da
Compare
eda010a to
6e7315a
Compare
Give plugins the general capability to arrange a thread's replies or a
channel's timeline in place, while the feature (sorts, filters, window size,
paging, wording) lives in the plugin.
Core hooks:
- `session.foldRows(channelId, events, rootId?)`: the rows the readers fold
from proven events, with the viewer's own pending sends and delivery state.
- `session.retain()`: one `{ set, dispose }` hold of proven, visible events so
live edits, reactions and deletions of scanned rows pass visibility. It grants
no access and feeds no cache, unread count or view; unread uses it as evidence.
- `snapshotRead(filters, { priority: "background" })` and
`session.windowNewer` for relays that page NIP-CW windows oldest first.
- A `"reader"` accessory placement with `present({ ids, events, parents?,
open?, complete?, place? })`, `presentation`, `limits` and `targetId`.
The thread and channel readers show a presentation with their own controls,
limits and reading, draw no day dividers or grouped rows while it shows, and
return to the host rows at the reader's place on withdraw. Window admission
fixes: live replies inside pages a running read has fetched are admitted,
channel page verification is scoped to the window's channel, a list that turns
partial retakes its reading leases, and display parents nest only under
earlier rows.
A test-only reference plugin sorts (Top, Oldest), filters across every scanned
row and pages past the reader's limits over a 2,000-reply thread and a
5,000-row channel.
Made with human guidance from the maintainer driving this work.
Co-authored-by: Clod <c7b21872e9ddb79ca62967d0e21e6a4518a669eb04648e963cdfb2426e62fafb@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
6e7315a to
2966a32
Compare
Summary
Plugins can now sort, filter and page a thread's replies or a channel's timeline in place. Core supplies only the capability. The feature itself lives in the plugin: which sorts exist, what a filter matches, the window size, paging, layout and wording.
The motivating case is a Reddit-like thread. A sort or filter must mean the same thing whether or not the app has already loaded the rows it needs. So a plugin reads the whole conversation itself, keeps live updates of what it read, and asks the reader to show the rows it chose.
Relay side: block/buzz#9632. It lets NIP-CW windows page oldest first (
buzz-window-newer). This PR works without it too: the app reads older pages only, and the final rows are the same.Core changes, measured against the plugin-first rule
Each core change is measured against this project rule: a feature a plugin can build belongs in a plugin, and core adds only the smallest general capability a plugin needs to own that feature.
session.foldRows(channelId, events, rootId?)canAccess,relayAuthor,archiveAuthority, the agent-owner directory and the outbox. An installed plugin is a blob module (src/plugins/modules.ts:23) and cannot importrelay/fold.ts; copying it means about 1,500 lines that drift.ChannelMessagerows the readers fold. No cache, no reads, no view.session.retain()returning{ set, dispose }relay/event-access.ts:69-70). Rows a plugin read withsnapshotReadare known to nobody, so their live updates are dropped for everyone. Edit, react and read marking also cannot find them.retainedEventlookups and unread's message evidence, and nothing else: noaccept, no cache, norecent, no unread counts. It grants no access, because every reference is checked onsetand on each access change.snapshotRead(filters, { priority })snapshotReadtakes foreground read slots and delays the user's own reads.ReadOptions.priorityalready exists in the reader (relay/reader.ts:15) but is not reachable fromsnapshotRead.session.windowNewerbuzz-window-neweris NIP-11 data that only the host transports read.searchSort, set by both hosts.direction: "newer",root_aux: falseand channel 39006 windowsplacement: "reader"accessory, withpresent,presentation,limitsandtargetIdconversation/service.tsx:389-392).presentcall and three read-only props.messages/arrangement.ts) and reader wiring (ThreadPanel.tsx,ChannelTimeline.tsx)replyTree(rows, rootId?, displayParent?)use-reading.ts,unread.ts)partialandendMessageIdinputs to the existing reading lease.relay/threads.ts,relay/store.ts)Edits to FOUNDATION files, all in the approved list:
relay/session.ts:foldRows, theretainhandle,snapshotReadpriority andwindowNewer. Theretainhandle needs two internal wirings:heldEventinretainedEvent, andevidencepassed tocreateUnread.conversation/contracts.ts: the reader placement andpresent.conversation/service.tsx: one validation line.plugins/author.ts: type exports.What the reference plugin shows
tests/fixtures/conversation-arranger/plugin.tsis test-only and not shipped. It uses onlyctxand the author types. It has:session.live), it marks its result as not exact. After it reconnects, it reads the conversation again, but only while its window is visible, and after a random wait of up to 10 seconds, so a relay restart does not make every viewer read at once. Meanwhile the reader keeps the shown rows live.ended.The tests compare its output against an oracle built from raw events, over a 2,000-reply thread and a 5,000-row channel.
Size
Production: 1,396 added and 154 removed lines, comments included. The largest parts are
arrangement.ts(489),ThreadPanel.tsx(+183),ChannelTimeline.tsx(+174) andsession.ts(+142). Tests and fixtures: about 6,300 lines. Docs: 110 lines.Known limits
foldRowsis stateless, a plugin can still rank exactly at scan time without holding everything, but live changes then reach only the rows it holds. The reference plugin holds everything it reads, so past the bound it stops with an error. A true live "Top" at that size needs a relay-ranked query, which is a separate relay capability.readPage. AreadPagescan of more than about 2,400 replies trims or empties the open channel window. This predates this change. The docs send scans tosnapshotRead, which feeds no projection.Earlier review points
An earlier version of this PR added a headless
registerArranger({ include, compare })with no UI of its own. Its review asked for a host-visible sign that rows are hidden, noted that a filter matching nothing left a blank list, and noted that channel read marking used the unfiltered rows. In this version:include/compareandloadAllare gone.Related issue
None found.
Testing
All runs were on a separate Linux machine, at this PR's head, 2966a32, on main 46a09db.
pnpm typecheck, the types, design-system and rust-clippy pre-push lanes, and the fullvitest run(1,148 files passed, 8 skipped, no failures) all pass.htag, so the deleted row stayed visible (snapshot and live);buzzodz plugin initscaffolds, into one self-containedplugin.js, and Buzz loads it through its ordinary module loader (src/plugins/modules.ts, a blob import). Browser builds cannot install external plugins, so a small shim, applied only on the test machine and not part of this PR, replaces the desktop plugin storage: it lists the plugin in the catalog and returns its code. The Tauri desktop app was not run, because that machine cannot build it.buzz-review-completedis not added.Made with human guidance from the maintainer driving this work.
🤖 Generated with Claude Code