fix(desktop): populate member_count in get_channels so channel browser shows real counts#548
Conversation
…r shows real counts The channel browser dialog renders `channel.memberCount` directly, but `get_channels` was always returning 0 for that field. The value comes from a kind:40901 'channel summary' sidecar in `channel_info_from_event`, and every caller passed `None` for the summary — the relay doesn't emit kind:40901 yet either. The top bar's count appeared to work only because `ChannelMembersBar` does its own live kind:39002 fetch via `useChannelMembersQuery` and counts that, ignoring `channel.memberCount`. Fix at the Tauri layer: after assembling the channel list, issue a single batched kind:39002 query for every channel id and count unique p-tag pubkeys. One extra relay round-trip total, not N. If the query fails we fall back to 0 (prior behavior) rather than breaking the whole listing. When the kind:40901 summary sidecar is implemented relay-side this extra query can be removed in favor of the existing summary path. Signed-off-by: tlongwell-block <109685178+tlongwell-block@users.noreply.github.com>
… add tests Replace the inline kind:39002 dedupe/count loop with a small helper that delegates p-tag parsing to nostr_convert::channel_members_from_event, matching get_channel_members. One source of truth for member dedupe. Add five unit tests for count_members_by_channel covering: per-channel counts, duplicate-pubkey dedupe, missing d-tag (skipped), zero-member channel (recorded as 0 so it overwrites the default), and empty input. Tests live in a sibling channels_tests.rs to keep channels.rs under the per-file line cap. Signed-off-by: tlongwell-block <109685178+tlongwell-block@users.noreply.github.com>
deeddcd to
ebaae2f
Compare
|
@codex review please |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ebaae2f7e3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "kinds": [39002], | ||
| "#d": all_d_tags, | ||
| "limit": all_d_tags.len(), |
There was a problem hiding this comment.
Restrict member-count query to relay-signed 39002 events
The new get_channels member-count fetch filters only by kinds and #d, so any kind:39002 event with a matching d tag is accepted regardless of author. Because count_members_by_channel trusts these events, a non-relay publisher can inject a forged members event (same channel id, inflated p tags) and the browser will show an incorrect member_count. This is especially reachable because 39002 is not treated as relay-only in ingest; please constrain this query to the trusted relay author (or the same author as the channel metadata event) before counting.
Useful? React with 👍 / 👎.
* origin/main: (33 commits) dev-mcp: add view_image tool (#602) fix(relay,desktop): only advertise NIP-43 when enforced; probe pairing by supported_nips (#601) fix(desktop): derive unread state from NIP-RS + relay catch-up only (#599) docs(testing): rewrite TESTING.md for current API and CLI-first workflow (#597) fix(agent): fix OpenAI-compat request body serialization and max_tokens (#595) feat(desktop): per-persona and per-agent env var overrides (#594) fix(desktop): stop pinning agents to deprecated SPROUT_ACP_TURN_TIMEOUT (#592) fix(desktop): populate member_count in get_channels so channel browser shows real counts (#548) fix(desktop): autofocus message composer on channel/thread open (#572) refactor(cli): restructure flat commands into 12 subcommand groups (#585) feat(sdk): add builder functions for workflows, DMs, and presence (#589) feat(desktop): add message more-actions dropdown menu (#590) fix(mobile): preserve channel list across background/resume reconnection (#588) Redesign Home as an inbox (#582) fix(desktop): drive unread badges from live subscription, not refetched lastMessageAt (#581) fix(desktop): refine header scaling and shadow (#573) fix(desktop): keep day dividers below header (#574) Move agent activity below composer (#579) docs(nips): NIP-AE — Agent Engrams (#575) refactor: extract shared @mention resolver into sprout-sdk (#580) ... Signed-off-by: Tyler Longwell <tlongwell@squareup.com>
Summary
The channel browser dialog shows
0members for every channel becauseget_channelsalways returnsmember_count: 0. This PR fixes that by computing the count from kind:39002 events in the same Tauri command.Root cause
ChannelInfo.member_countis populated innostr_convert::channel_info_from_event, which reads it from a kind:40901 "channel summary" sidecar event. Two problems:commands/channels.rspassesNonefor the summary.sprout-core::kindbut nothing publishes it.The top bar in
ChannelMembersBarappears to work only because it ignoreschannel.memberCountand does its own live kind:39002 fetch viauseChannelMembersQuery, counting members client-side. The browser dialog renderschannel.memberCountdirectly and so always shows0.Fix
After
get_channelsassembles the channel list, issue a single batched query for kind:39002 events with#dset to every listed channel id, then overwritemember_countfor each channel from the unique p-tag pubkey count. One extra relay round-trip total, not N.If the query fails we silently fall back to
0(the prior behavior) so a sidecar miss can't break the whole channel listing.Why fix at the Tauri layer
channel.memberCountflows through every channel listing in the UI. Fixing it at the command level means anything that reads the field gets the correct value — not just the browser dialog.Future work (not in this PR)
If/when the kind:40901 channel summary sidecar is implemented relay-side, the existing summary path in
channel_info_from_eventcan supersede this extra query and it can be removed.Verification
cargo check— cleancargo test --lib— all 245 tests passcargo clippy— no new warnings on changed filepnpm build(desktop) — clean