Task 11: Presence, users, UI state (#11) #42

Manually merged
charles merged 0 commits from task/11-core-presence-ui into foundation 2026-11-11 18:28:08 +00:00
Owner

What this builds

Task 11 of the Foundation plan, in fluxer-core:

  • Users { by_id } (users.rs): every UserPartial seen in READY (users, the logged-in user, DM recipients, guild members, presences), GUILD_CREATE, GUILD_MEMBER_*, CHANNEL_CREATE/UPDATE recipients, PRESENCE_UPDATE, USER_UPDATE, message authors and mentions (gateway and REST results). Newest copy wins; users are not removed while logged in.
  • PresenceState { by_user } (presence.rs): from READY/GUILD_CREATE presences and PRESENCE_UPDATE. READY replaces the previous session's presences. Offline users are not kept; read with PresenceState::status(user_id).
  • UiState (ui.rs): selected guild/channel, last_channel_per_guild, drafts, member list toggle, sidebar width (default 320, clamped 200..=480), window focus, settings tab. SelectGuild restores the channel last open there (also for the DM list); a deleted channel or a left guild is deselected and forgotten (an unavailable guild keeps the selection).
  • selectors::members: member_list(app, guild), display_name(app, user_id, guild), plus status_of(app, user_id).
  • App gains pub users: Users; App::apply calls the three reducers and, when the session goes from logged in to logged out, clears users, presences and the account's part of the UI state (layout stays).

How it was tested

crates/fluxer-core/tests/presence_ui.rs (13 tests, written first and seen failing): the five the plan names (presence_update_changes_status, member_list_hoists_roles_then_online_offline, select_guild_restores_last_channel, display_name_precedence, sidebar_width_clamped) plus users learned from READY/presences/messages, READY replacing presences, deleted channel/guild handling, drafts, settings tab, UI defaults and logout clearing. They use the ready, presence_update and message_create gateway fixtures. cargo xtask ci is green locally.

Deviations from the plan / things to look at

  • Guilds / GuildRecord are declared in app.rs here with exactly the shape of Task 9's Interfaces block (by_id, guild, roles, channels, members, member_count: u64, unavailable), without reducers. member_list and display_name have to read guild members and roles, and Task 9 runs in parallel, so nothing fills them yet; the tests insert a GuildRecord built from the READY fixture. When Task 9 lands, its definition replaces this one (expect a mechanical conflict in app.rs, lib.rs and selectors/mod.rs).
  • MemberGroup has a third field kind: MemberGroupKind { Role, Online, Offline }: with only role: Option<Role> the "Online" and "Offline" groups cannot be told apart.
  • Member list rules where the plan is silent: roles ordered by hoist_position (falling back to position) descending; a member is listed once, under their highest hoisted role; offline and invisible members go to "Offline" whatever their roles; members sorted by display name ignoring case; empty groups omitted; unknown or unavailable guild gives an empty list.
  • The gateway does not send a client its own presence, so status_of shows the logged-in user with the status of the synced user settings, or online when there is none.
  • last_channel_per_guild is keyed by Option<Snowflake> (None = DM list). SelectChannel records the channel under the currently selected guild, since the channel store (Task 9) is not available to look up its guild.
  • UiState has an extra last_settings_tab so OpenSettings(None) can reopen the last tab.
  • SendDraft removes the draft in the UI reducer. The messages reducer of Task 10 must run before self.ui.reduce in App::apply if it reads ui.drafts (commented there).
  • display_name returns "Unknown User" for an id the client has never seen.
  • SidebarResized does not persist yet (PersistOp::SaveSettings is Task 12).

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

Closes #11

🤖 Generated with Claude Code

## What this builds Task 11 of the Foundation plan, in `fluxer-core`: - `Users { by_id }` (`users.rs`): every `UserPartial` seen in `READY` (`users`, the logged-in user, DM recipients, guild members, presences), `GUILD_CREATE`, `GUILD_MEMBER_*`, `CHANNEL_CREATE/UPDATE` recipients, `PRESENCE_UPDATE`, `USER_UPDATE`, message authors and mentions (gateway and REST results). Newest copy wins; users are not removed while logged in. - `PresenceState { by_user }` (`presence.rs`): from `READY`/`GUILD_CREATE` `presences` and `PRESENCE_UPDATE`. `READY` replaces the previous session's presences. Offline users are not kept; read with `PresenceState::status(user_id)`. - `UiState` (`ui.rs`): selected guild/channel, `last_channel_per_guild`, drafts, member list toggle, sidebar width (default 320, clamped 200..=480), window focus, settings tab. `SelectGuild` restores the channel last open there (also for the DM list); a deleted channel or a left guild is deselected and forgotten (an `unavailable` guild keeps the selection). - `selectors::members`: `member_list(app, guild)`, `display_name(app, user_id, guild)`, plus `status_of(app, user_id)`. - `App` gains `pub users: Users`; `App::apply` calls the three reducers and, when the session goes from logged in to logged out, clears users, presences and the account's part of the UI state (layout stays). ## How it was tested `crates/fluxer-core/tests/presence_ui.rs` (13 tests, written first and seen failing): the five the plan names (`presence_update_changes_status`, `member_list_hoists_roles_then_online_offline`, `select_guild_restores_last_channel`, `display_name_precedence`, `sidebar_width_clamped`) plus users learned from READY/presences/messages, READY replacing presences, deleted channel/guild handling, drafts, settings tab, UI defaults and logout clearing. They use the `ready`, `presence_update` and `message_create` gateway fixtures. `cargo xtask ci` is green locally. ## Deviations from the plan / things to look at - **`Guilds` / `GuildRecord` are declared in `app.rs` here** with exactly the shape of Task 9's Interfaces block (`by_id`, `guild`, `roles`, `channels`, `members`, `member_count: u64`, `unavailable`), without reducers. `member_list` and `display_name` have to read guild members and roles, and Task 9 runs in parallel, so nothing fills them yet; the tests insert a `GuildRecord` built from the READY fixture. When Task 9 lands, its definition replaces this one (expect a mechanical conflict in `app.rs`, `lib.rs` and `selectors/mod.rs`). - `MemberGroup` has a third field `kind: MemberGroupKind { Role, Online, Offline }`: with only `role: Option<Role>` the "Online" and "Offline" groups cannot be told apart. - Member list rules where the plan is silent: roles ordered by `hoist_position` (falling back to `position`) descending; a member is listed once, under their highest hoisted role; offline and invisible members go to "Offline" whatever their roles; members sorted by display name ignoring case; empty groups omitted; unknown or unavailable guild gives an empty list. - The gateway does not send a client its own presence, so `status_of` shows the logged-in user with the `status` of the synced user settings, or online when there is none. - `last_channel_per_guild` is keyed by `Option<Snowflake>` (`None` = DM list). `SelectChannel` records the channel under the currently selected guild, since the channel store (Task 9) is not available to look up its guild. - `UiState` has an extra `last_settings_tab` so `OpenSettings(None)` can reopen the last tab. - `SendDraft` removes the draft in the UI reducer. The messages reducer of Task 10 must run before `self.ui.reduce` in `App::apply` if it reads `ui.drafts` (commented there). - `display_name` returns `"Unknown User"` for an id the client has never seen. - `SidebarResized` does not persist yet (`PersistOp::SaveSettings` is Task 12). Stacked on: task/8-core-store-session Closes #11 🤖 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 #11

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
feat(core): presence, users and ui state
All checks were successful
ci / Windows (x64) (push) Successful in 39s
ci / Windows (x64) (pull_request) Successful in 39s
ci / Linux (x86_64) (push) Successful in 1m7s
ci / Linux (x86_64) (pull_request) Successful in 1m3s
f4ce82e123
Refs #11

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

Independent review: Task 11 (core-presence-ui) at f4ce82e

Scope: git diff cacedcb..origin/task/11-core-presence-ui (9 files, fluxer-core only).

Checks

  1. Plan tests: all five exist in crates/fluxer-core/tests/presence_ui.rs and assert the plan's behaviour: presence_update_changes_status, member_list_hoists_roles_then_online_offline, select_guild_restores_last_channel, display_name_precedence (nick > global_name > username), sidebar_width_clamped (default 320, clamp 200..=480, boundaries 199/200/480/481 covered). 8 further tests. Failing-first commit 95b44a0 precedes the implementation.
  2. Interfaces: Users { by_id }, PresenceState { by_user: HashMap<Snowflake, UserStatus> }, every UiState field with the plan's types and defaults, member_list(app, guild) -> Vec<MemberGroup>, display_name(app, user_id, Option<Snowflake>) -> String all exist as written. App gains pub users: Users.
  3. Invariants: no new dependencies, no banned crates, no I/O, no tokens in code or tests. No unwrap/index/expect on server data in the new source; unknown statuses, unknown role ids, unknown guilds and unseen users are handled without panicking.
  4. Review Focus: none of the five items belongs to this task.
  5. cargo xtask ci in the review worktree: all steps passed (presence_ui: 13 passed; screenshot tests skipped as configured). Remote runners not checked.

Findings

  • minor (app.rs): Guilds/GuildRecord are declared here with Task 9's shape and no reducers. Task 9 creates them in guilds.rs; expect conflicts in app.rs, lib.rs and selectors/mod.rs, and Task 9's definition should win. Until Task 9 lands, member_list is only exercised against a hand-built record; rerun the member tests through the real Ready reducer when integrating.
  • minor (selectors/members.rs, ui.rs): MemberGroup has an extra kind field and UiState an extra last_settings_tab. Additive for readers, but consumers cannot build these with the plan's struct literal. Hoist order (hoist_position ?? position, descending) matches the fork's GuildRole.ts / guild_member_list_groups.erl.
  • minor (ui.rs): SelectGuild restores selected_channel directly, without a SelectChannel action. Task 10 fetches the first page on SelectChannel only, so a restored channel with no loaded messages would stay empty unless Task 10 also reacts to SelectGuild/the selection change. Also, SelectChannel files the channel under the currently selected guild, which is wrong if a channel is ever opened from outside its guild (notification, jump link).
  • minor (users.rs, presence.rs): reducers are not gated on being logged in. A late ApiResult::Messages or gateway event arriving after logout repopulates users/presence, which then survive into the next account's session until its READY (presence is cleared on READY, users are not).
  • minor (app.rs): the ordering constraint (messages reducer must read ui.drafts before self.ui.reduce on SendDraft) is only a comment; Task 10 needs to honour it and should test it.

Verdict: APPROVE (0 blocking, 5 minor; local ci green)

## Independent review: Task 11 (core-presence-ui) at f4ce82e Scope: `git diff cacedcb..origin/task/11-core-presence-ui` (9 files, fluxer-core only). **Checks** 1. Plan tests: all five exist in `crates/fluxer-core/tests/presence_ui.rs` and assert the plan's behaviour: `presence_update_changes_status`, `member_list_hoists_roles_then_online_offline`, `select_guild_restores_last_channel`, `display_name_precedence` (nick > global_name > username), `sidebar_width_clamped` (default 320, clamp 200..=480, boundaries 199/200/480/481 covered). 8 further tests. Failing-first commit 95b44a0 precedes the implementation. 2. Interfaces: `Users { by_id }`, `PresenceState { by_user: HashMap<Snowflake, UserStatus> }`, every `UiState` field with the plan's types and defaults, `member_list(app, guild) -> Vec<MemberGroup>`, `display_name(app, user_id, Option<Snowflake>) -> String` all exist as written. `App` gains `pub users: Users`. 3. Invariants: no new dependencies, no banned crates, no I/O, no tokens in code or tests. No `unwrap`/index/`expect` on server data in the new source; unknown statuses, unknown role ids, unknown guilds and unseen users are handled without panicking. 4. Review Focus: none of the five items belongs to this task. 5. `cargo xtask ci` in the review worktree: all steps passed (presence_ui: 13 passed; screenshot tests skipped as configured). Remote runners not checked. **Findings** - minor (`app.rs`): `Guilds`/`GuildRecord` are declared here with Task 9's shape and no reducers. Task 9 creates them in `guilds.rs`; expect conflicts in `app.rs`, `lib.rs` and `selectors/mod.rs`, and Task 9's definition should win. Until Task 9 lands, `member_list` is only exercised against a hand-built record; rerun the member tests through the real `Ready` reducer when integrating. - minor (`selectors/members.rs`, `ui.rs`): `MemberGroup` has an extra `kind` field and `UiState` an extra `last_settings_tab`. Additive for readers, but consumers cannot build these with the plan's struct literal. Hoist order (`hoist_position ?? position`, descending) matches the fork's `GuildRole.ts` / `guild_member_list_groups.erl`. - minor (`ui.rs`): `SelectGuild` restores `selected_channel` directly, without a `SelectChannel` action. Task 10 fetches the first page on `SelectChannel` only, so a restored channel with no loaded messages would stay empty unless Task 10 also reacts to `SelectGuild`/the selection change. Also, `SelectChannel` files the channel under the currently selected guild, which is wrong if a channel is ever opened from outside its guild (notification, jump link). - minor (`users.rs`, `presence.rs`): reducers are not gated on being logged in. A late `ApiResult::Messages` or gateway event arriving after logout repopulates `users`/`presence`, which then survive into the next account's session until its `READY` (presence is cleared on `READY`, users are not). - minor (`app.rs`): the ordering constraint (messages reducer must read `ui.drafts` before `self.ui.reduce` on `SendDraft`) is only a comment; Task 10 needs to honour it and should test it. **Verdict: APPROVE** (0 blocking, 5 minor; local ci green)
charles manually merged commit 24e7c9d137 into foundation 2026-11-11 18:28:08 +00:00
Sign in to join this conversation.
No description provided.