Task 9: Guilds and channels domain (#9) #43

Merged
charles merged 4 commits from task/9-core-guilds-channels into foundation 2026-11-11 18:16:16 +00:00
Owner

What

The guilds and channels domains of fluxer-core (Foundation plan, Task 9; spec §4).

  • guilds.rs: Guilds { by_id } of GuildRecord { guild, roles, channels, members, member_count, unavailable }, reduced from READY, GUILD_CREATE/UPDATE/DELETE, CHANNEL_CREATE/UPDATE/DELETE (channel id set), GUILD_ROLE_* and GUILD_MEMBER_*.
  • channels.rs: Channels { by_id } holding guild channels and DMs, reduced from READY (guilds[].channels, private_channels), GUILD_CREATE/DELETE and CHANNEL_*.
  • selectors/sidebar.rs: guild_order, channel_tree (SidebarSection), can_view, dm_list.
  • app.rs / lib.rs: the two stub structs are replaced by the real ones and App::apply calls their reducers. README updated.

Stacked on: task/8-core-store-session

How it was tested

crates/fluxer-core/tests/guilds_channels.rs, 18 tests through App::apply with fixtures/gateway/{ready,guild_create,channel_update}.json: the six the plan names (can_view_respects_role_and_member_overwrites has its 4 cases) plus owner/administrator, base role permissions, unknown guild/member, a second READY, GUILD_CREATE over an unavailable stub, GUILD_UPDATE, role and member events, and logout. Tests were committed failing first. cargo xtask ci is green locally.

Deviations and decisions the plan leaves open

  • Gateway dispatches received while not logged in are dropped by App::apply for these two domains, and a logout empties both (so a dispatch already on its way cannot repopulate the store, and nothing leaks into the next account). Task 12's cached-READY path will need to feed the store its own way.
  • An unavailable guild ({id, unavailable}) that was never seen in full gets a record with a placeholder Guild (empty name, owner id 0), because GuildRecord.guild is not optional in the plan. An unavailable stub for a known guild only marks it; nothing is forgotten.
  • can_view follows the fork's computePermissions (role overwrites of the member's roles are combined, allow wins over deny, then the member overwrite). Not ported: the fork's "visiting" guild mode and the MFA-elevated-permission mask, neither of which affects VIEW_CHANNEL for a member. With no @everyone role known the base is empty (the fork falls back to DEFAULT_PERMISSIONS).
  • channel_tree: uncategorised channels come first as a category: None section (omitted when empty); a category is listed when the user may view it or it has a visible channel; threads are not rows; a channel whose parent_id is not a known category is listed as uncategorised; channel kinds unknown to the client are listed as text-like.
  • dm_list sorts by last_message_id, falling back to the channel's own id for conversations without messages; pinned_dms is not applied yet.
  • CHANNEL_UPDATE without last_message_id keeps the known one. GUILD_ROLE_DELETE also strips the role from loaded members. member_count is adjusted on member add (new members only) and remove.

Closes #9

🤖 Generated with Claude Code

## What The guilds and channels domains of `fluxer-core` (Foundation plan, Task 9; spec §4). - `guilds.rs`: `Guilds { by_id }` of `GuildRecord { guild, roles, channels, members, member_count, unavailable }`, reduced from `READY`, `GUILD_CREATE/UPDATE/DELETE`, `CHANNEL_CREATE/UPDATE/DELETE` (channel id set), `GUILD_ROLE_*` and `GUILD_MEMBER_*`. - `channels.rs`: `Channels { by_id }` holding guild channels and DMs, reduced from `READY` (`guilds[].channels`, `private_channels`), `GUILD_CREATE/DELETE` and `CHANNEL_*`. - `selectors/sidebar.rs`: `guild_order`, `channel_tree` (`SidebarSection`), `can_view`, `dm_list`. - `app.rs` / `lib.rs`: the two stub structs are replaced by the real ones and `App::apply` calls their reducers. README updated. Stacked on: task/8-core-store-session ## How it was tested `crates/fluxer-core/tests/guilds_channels.rs`, 18 tests through `App::apply` with `fixtures/gateway/{ready,guild_create,channel_update}.json`: the six the plan names (`can_view_respects_role_and_member_overwrites` has its 4 cases) plus owner/administrator, base role permissions, unknown guild/member, a second `READY`, `GUILD_CREATE` over an unavailable stub, `GUILD_UPDATE`, role and member events, and logout. Tests were committed failing first. `cargo xtask ci` is green locally. ## Deviations and decisions the plan leaves open - Gateway dispatches received while not logged in are dropped by `App::apply` for these two domains, and a logout empties both (so a dispatch already on its way cannot repopulate the store, and nothing leaks into the next account). Task 12's cached-READY path will need to feed the store its own way. - An unavailable guild (`{id, unavailable}`) that was never seen in full gets a record with a placeholder `Guild` (empty name, owner id 0), because `GuildRecord.guild` is not optional in the plan. An unavailable stub for a known guild only marks it; nothing is forgotten. - `can_view` follows the fork's `computePermissions` (role overwrites of the member's roles are combined, allow wins over deny, then the member overwrite). Not ported: the fork's "visiting" guild mode and the MFA-elevated-permission mask, neither of which affects `VIEW_CHANNEL` for a member. With no `@everyone` role known the base is empty (the fork falls back to `DEFAULT_PERMISSIONS`). - `channel_tree`: uncategorised channels come first as a `category: None` section (omitted when empty); a category is listed when the user may view it or it has a visible channel; threads are not rows; a channel whose `parent_id` is not a known category is listed as uncategorised; channel kinds unknown to the client are listed as text-like. - `dm_list` sorts by `last_message_id`, falling back to the channel's own id for conversations without messages; `pinned_dms` is not applied yet. - `CHANNEL_UPDATE` without `last_message_id` keeps the known one. `GUILD_ROLE_DELETE` also strips the role from loaded members. `member_count` is adjusted on member add (new members only) and remove. Closes #9 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Refs #8

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
feat(core): store skeleton and session reducer
All checks were successful
ci / Windows (x64) (push) Successful in 42s
ci / Linux (x86_64) (push) Successful in 1m0s
ci / Windows (x64) (pull_request) Successful in 41s
ci / Linux (x86_64) (pull_request) Successful in 1m5s
cacedcbbf7
Refs #8

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Refs #9

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
feat(core): guild and channel reducers and sidebar selectors
All checks were successful
ci / Windows (x64) (pull_request) Successful in 45s
ci / Windows (x64) (push) Successful in 43s
ci / Linux (x86_64) (pull_request) Successful in 1m3s
ci / Linux (x86_64) (push) Successful in 1m10s
e753f32ec6
Refs #9

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Author
Owner

Independent review: Task 9 (core-guilds-channels) at e753f32

Scope: git diff cacedcb..e753f32 (8 files, all in crates/fluxer-core).

Checks

  1. Plan tests: all six named tests exist in tests/guilds_channels.rs and assert what the plan says against fixtures/gateway/ready.json (ready_populates_guilds_channels_and_dms, channel_tree_groups_by_category_and_sorts, guild_order_follows_user_settings_then_joined_at, can_view_respects_role_and_member_overwrites with its 4 numbered cases, channel_delete_removes_from_tree, guild_delete_unavailable_keeps_record_marked), plus 12 extra. Failing-first commit df15ba9 precedes the implementation.
  2. Interfaces: Guilds { by_id }, GuildRecord { guild, roles: BTreeMap, channels: BTreeSet, members: HashMap, member_count, unavailable }, Channels { by_id }, guild_order, channel_tree -> Vec<SidebarSection { category: Option<Channel>, channels: Vec<Channel> }>, can_view(app, &Channel), dm_list all present as written. Selectors are exported from fluxer_core::selectors (not the crate root).
  3. Invariants: no new dependencies, core-isolation step passes, no I/O, no unwrap/indexing on server data in the reducers or selectors (unknown guilds, roles, parents and channel kinds are handled), no tokens in code or tests.
  4. Review Focus: none of the five items belongs to this task.
  5. cargo xtask ci in the review worktree: green (fmt, clippy, deny, core-isolation, tests; 18/18 in guilds_channels; screenshot tests skipped as configured). can_view compared with the fork's computePermissions: faithful for the non-visiting path.

Findings

  • minor — crates/fluxer-core/src/channels.rs (ChannelCreate/ChannelUpdate): the payload's guild_id is stored as sent. If an update for a known guild channel ever arrived without guild_id, the stored channel would lose it and can_view would treat it as a DM (always visible) while it stays in the guild's tree. The fork's mapChannelToResponse always sends guild_id, so this is not reachable today; keeping the known guild_id on update (as is done for last_message_id) would close it.
  • minor — crates/fluxer-core/src/app.rs: gateway dispatches are dropped for these two domains unless Auth::LoggedIn. Correct for the logout race (tested), but Task 12's cached-READY path cannot populate the store before login completes without changing this gate. Should be a follow-up issue or a note on Task 12.
  • minor — crates/fluxer-core/src/selectors/sidebar.rs can_view: a missing @everyone role yields an empty base where the fork uses DEFAULT_PERMISSIONS; "visiting" guilds are not handled. Fails closed (channels hidden), display only.
  • minor — crates/fluxer-core/src/guilds.rs: GUILD_UPDATE ignores roles carried on the guild object (record.roles only changes via role events), and a never-loaded unavailable guild gets a placeholder Guild (empty name, owner id 0); UI tasks must check unavailable before rendering the name.
  • minor — dm_list ignores pinned_dms (not required by the plan).
  • note — app.rs and lib.rs are outside the task's Files list (needed to replace the stubs); Tasks 10/11 will conflict there mechanically.

Verdict: APPROVE — 0 blocking, 5 minor. Remote runners not checked (integrator's job).

## Independent review: Task 9 (core-guilds-channels) at e753f32 Scope: `git diff cacedcb..e753f32` (8 files, all in `crates/fluxer-core`). **Checks** 1. Plan tests: all six named tests exist in `tests/guilds_channels.rs` and assert what the plan says against `fixtures/gateway/ready.json` (`ready_populates_guilds_channels_and_dms`, `channel_tree_groups_by_category_and_sorts`, `guild_order_follows_user_settings_then_joined_at`, `can_view_respects_role_and_member_overwrites` with its 4 numbered cases, `channel_delete_removes_from_tree`, `guild_delete_unavailable_keeps_record_marked`), plus 12 extra. Failing-first commit df15ba9 precedes the implementation. 2. Interfaces: `Guilds { by_id }`, `GuildRecord { guild, roles: BTreeMap, channels: BTreeSet, members: HashMap, member_count, unavailable }`, `Channels { by_id }`, `guild_order`, `channel_tree -> Vec<SidebarSection { category: Option<Channel>, channels: Vec<Channel> }>`, `can_view(app, &Channel)`, `dm_list` all present as written. Selectors are exported from `fluxer_core::selectors` (not the crate root). 3. Invariants: no new dependencies, core-isolation step passes, no I/O, no unwrap/indexing on server data in the reducers or selectors (unknown guilds, roles, parents and channel kinds are handled), no tokens in code or tests. 4. Review Focus: none of the five items belongs to this task. 5. `cargo xtask ci` in the review worktree: green (fmt, clippy, deny, core-isolation, tests; 18/18 in `guilds_channels`; screenshot tests skipped as configured). `can_view` compared with the fork's `computePermissions`: faithful for the non-visiting path. **Findings** - minor — `crates/fluxer-core/src/channels.rs` (`ChannelCreate`/`ChannelUpdate`): the payload's `guild_id` is stored as sent. If an update for a known guild channel ever arrived without `guild_id`, the stored channel would lose it and `can_view` would treat it as a DM (always visible) while it stays in the guild's tree. The fork's `mapChannelToResponse` always sends `guild_id`, so this is not reachable today; keeping the known `guild_id` on update (as is done for `last_message_id`) would close it. - minor — `crates/fluxer-core/src/app.rs`: gateway dispatches are dropped for these two domains unless `Auth::LoggedIn`. Correct for the logout race (tested), but Task 12's cached-READY path cannot populate the store before login completes without changing this gate. Should be a `follow-up` issue or a note on Task 12. - minor — `crates/fluxer-core/src/selectors/sidebar.rs` `can_view`: a missing `@everyone` role yields an empty base where the fork uses `DEFAULT_PERMISSIONS`; "visiting" guilds are not handled. Fails closed (channels hidden), display only. - minor — `crates/fluxer-core/src/guilds.rs`: `GUILD_UPDATE` ignores `roles` carried on the guild object (`record.roles` only changes via role events), and a never-loaded unavailable guild gets a placeholder `Guild` (empty name, owner id 0); UI tasks must check `unavailable` before rendering the name. - minor — `dm_list` ignores `pinned_dms` (not required by the plan). - note — `app.rs` and `lib.rs` are outside the task's Files list (needed to replace the stubs); Tasks 10/11 will conflict there mechanically. **Verdict: APPROVE** — 0 blocking, 5 minor. Remote runners not checked (integrator's job).
charles merged commit 79aba39725 into foundation 2026-11-11 18:16:05 +00:00
Sign in to join this conversation.
No description provided.