Text chat 11: core composer (#261) #309

Manually merged
charles merged 6 commits from textchat-11-core-composer into textchat 2026-11-12 20:38:20 +00:00
Owner

What

Text chat 11, the rich composer in fluxer-core (spec §6.2 Content conversion, Send, Edit, Typing, Autocomplete; spec §3.2):

  • chat::content::to_wire(&Draft, &App) -> WireContent { content, allowed_mentions, length_utf16 }: mention spans become <@id>, <@&id>, <#id>, @everyone/@here, <:n:id>/<a:n:id>; typed :name: and :name::skin-tone-N: convert to Unicode or a usable custom emoji of the channel's guild; emoticons convert when the setting is on and they stand alone; code spans, fences, links and existing markup stay untouched; length in UTF-16 units; allowed_mentions is {replied_user} with a reply only.
  • chat::autocomplete::query(text, cursor) -> Option<Trigger> with the patterns and priority of SlashCommandUtils.ts; results in sections of at most 10 (recent authors first, roles by position, @everyone/@here only with MENTION_EVERYONE, viewable text channels, emoji frecency first, stickers, saved media, commands); Up/Down/Select/Dismiss.
  • Replies (default mention rules: off for own messages and in DMs), ToggleReplyMention, inline edit (StartEdit, EditLastMessage on Up in an empty composer, SaveEdit -> PatchMessage, empty edit asks delete unless attachments are kept), the escape ladder (edit, sticker, attachments, reply), the @everyone confirm, over-limit/blank sends blocked, +:name: reacts to the last message.
  • Sends go through Messages as SendRichMessage (pending + RetrySend resends the same request); the Foundation DraftChanged/SendDraft path keeps working for text in ui.drafts.
  • Typing (typing::RollingTyping): first 1500 ms after the first keystroke, then every 8 s, at once after 16 s idle; never while editing or for commands. Slowmode countdown from the typing answer and from sends.
  • Drafts persisted to LocalSettings::chat.drafts 400 ms after the last edit via Effect::Schedule.
  • selectors::composer(&App, channel) -> ComposerModel with the plan's fields.

Tests

New crates/fluxer-core/tests/{chat_composer.rs,chat_content.rs,chat_autocomplete.rs} with every test named in the plan (to_wire_cases is a table of more than 20 cases) plus a few extras. Tests were committed first and failed to compile before the implementation. FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci passes locally on Linux after merging the current origin/textchat. No desktop tests apply to this task.

Deviations from the plan

  • Files outside the task's list, kept minimal: event.rs gains ApiResult::TypingCooldown { channel_id, message_send_cooldown_ms } (the server's 200 answer to typing under slowmode; Text chat 21 maps it) and UserAction::ComposerEscape(channel) for the escape ladder; chat/{mod.rs,state.rs} and app.rs route the composer actions and split limits into limits_of(...) so reducers can call it with borrowed parts; selectors/{mod.rs,composer.rs} hold the composer selector; tests/chat_ports.rs no longer expects the composer actions to be stubs; the crate README documents the composer.
  • Premium limits are not modelled yet (as in Text chat 10), so max_message_length is the instance/default value.

Follow-ups: #347 (minor review findings 1-3 deferred).

Closes #261

🤖 Generated with Claude Code

## What Text chat 11, the rich composer in `fluxer-core` (spec §6.2 Content conversion, Send, Edit, Typing, Autocomplete; spec §3.2): - `chat::content::to_wire(&Draft, &App) -> WireContent { content, allowed_mentions, length_utf16 }`: mention spans become `<@id>`, `<@&id>`, `<#id>`, `@everyone`/`@here`, `<:n:id>`/`<a:n:id>`; typed `:name:` and `:name::skin-tone-N:` convert to Unicode or a usable custom emoji of the channel's guild; emoticons convert when the setting is on and they stand alone; code spans, fences, links and existing markup stay untouched; length in UTF-16 units; `allowed_mentions` is `{replied_user}` with a reply only. - `chat::autocomplete::query(text, cursor) -> Option<Trigger>` with the patterns and priority of `SlashCommandUtils.ts`; results in sections of at most 10 (recent authors first, roles by position, `@everyone`/`@here` only with MENTION_EVERYONE, viewable text channels, emoji frecency first, stickers, saved media, commands); Up/Down/Select/Dismiss. - Replies (default mention rules: off for own messages and in DMs), `ToggleReplyMention`, inline edit (`StartEdit`, `EditLastMessage` on Up in an empty composer, `SaveEdit` -> `PatchMessage`, empty edit asks delete unless attachments are kept), the escape ladder (edit, sticker, attachments, reply), the `@everyone` confirm, over-limit/blank sends blocked, `+:name:` reacts to the last message. - Sends go through `Messages` as `SendRichMessage` (pending + `RetrySend` resends the same request); the Foundation `DraftChanged`/`SendDraft` path keeps working for text in `ui.drafts`. - Typing (`typing::RollingTyping`): first 1500 ms after the first keystroke, then every 8 s, at once after 16 s idle; never while editing or for commands. Slowmode countdown from the typing answer and from sends. - Drafts persisted to `LocalSettings::chat.drafts` 400 ms after the last edit via `Effect::Schedule`. - `selectors::composer(&App, channel) -> ComposerModel` with the plan's fields. ## Tests New `crates/fluxer-core/tests/{chat_composer.rs,chat_content.rs,chat_autocomplete.rs}` with every test named in the plan (`to_wire_cases` is a table of more than 20 cases) plus a few extras. Tests were committed first and failed to compile before the implementation. `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` passes locally on Linux after merging the current `origin/textchat`. No desktop tests apply to this task. ## Deviations from the plan - Files outside the task's list, kept minimal: `event.rs` gains `ApiResult::TypingCooldown { channel_id, message_send_cooldown_ms }` (the server's 200 answer to typing under slowmode; Text chat 21 maps it) and `UserAction::ComposerEscape(channel)` for the escape ladder; `chat/{mod.rs,state.rs}` and `app.rs` route the composer actions and split `limits` into `limits_of(...)` so reducers can call it with borrowed parts; `selectors/{mod.rs,composer.rs}` hold the composer selector; `tests/chat_ports.rs` no longer expects the composer actions to be stubs; the crate README documents the composer. - Premium limits are not modelled yet (as in Text chat 10), so `max_message_length` is the instance/default value. Follow-ups: #347 (minor review findings 1-3 deferred). Closes #261 🤖 Generated with [Claude Code](https://claude.com/claude-code)
# Conflicts:
#	crates/fluxer-proto/README.md
#	crates/fluxer-proto/src/gateway/events.rs
#	crates/fluxer-proto/src/models/channel.rs
#	crates/fluxer-proto/src/models/mod.rs
#	crates/fluxer-proto/src/models/settings.rs
#	crates/fluxer-proto/tests/models_roundtrip.rs
Content conversion table, autocomplete triggers and results, replies,
edits, sends, typing, slowmode, drafts persistence. They fail to compile
until the composer lands.

Refs #261

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Drafts with mention spans and cursor, content conversion to the wire
form, autocomplete (triggers, results, selection), replies, inline edit,
the @everyone confirm, slowmode countdown, rolling typing sender and
drafts persisted 400 ms after the last edit. Sends go through
Messages as SendRichMessage; the Foundation DraftChanged path is kept.

Refs #261

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

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

Independent review: Text chat 11 (core composer)

I reviewed git diff 53fbd6f..origin/textchat-11-core-composer (head 7ca5a5c).

Plan tests: all 18 named tests exist. to_wire_cases has 24 cases. The values match the spec: 1500/8000/16000 ms typing, the 400 ms draft save, 10 results per kind and the 50-member confirm threshold.

Interfaces: these exist as the plan writes them:

  • content::to_wire(&Draft, &App) -> WireContent { content, allowed_mentions, length_utf16 }
  • autocomplete::query(text, cursor) -> Option<Trigger> with all 8 variants
  • selectors::composer(&App, channel) -> ComposerModel with every listed field, plus Counter { remaining, over } and Slowmode { remaining_s, active }
  • LocalSettings::chat.drafts, written through Effect::Schedule 400 ms after the last edit

Invariants:

  • No new dependencies and no I/O in fluxer-core.
  • No file bytes, clipboard images, upload URLs or secrets.
  • No new fixtures.
  • Slicing in convert, protected_len, typed_emoji, needs_mention_confirm and replace/adjust_spans stays on char boundaries, so server or user text cannot panic it.
  • TypingCooldown uses the server's message_send_cooldown_ms (api/channel/services/ChannelService.ts:40,219).

Review Focus 2:

  • convert() matches EmoticonConversionUtils.ts: the leading boundary is \s, the trailing boundary is a space or the end of the text, and backtick runs close only on a run of the same length.
  • Text is trimmed as useTextareaSubmit.ts:461 does.
  • allowed_mentions is sent only with a reply, as {replied_user}. This matches buildMessageCreateRequest/shouldIncludeAllowedMentions, and AllowedMentions skips empty lists when it serializes.
  • Content length is counted in UTF-16 units.
  • Trigger detection follows the order and patterns of SlashCommandUtils.ts:5-14. /kick|ban|msg command arguments are not handled; the plan does not ask for them.

Findings

  1. minor: chat/content.rs protected_len protects only bare http(s):// URLs. It does not protect Markdown links [text](url), which the original's findMarkdownLinkEnd does. So [see :) here](https://x) with emoticons on converts the :), and the original leaves it. The module doc and the README also say "links" are untouched, which overstates it. Suggest a follow-up issue.
  2. minor: chat/autocomplete.rs mentions() sorts recent authors first even when the query is not empty. Spec §3.2 says recent speakers come first "when the query is empty". This changes ranking only, not correctness.
  3. minor: app.rs loads drafts back only on the not-logged-in to logged-in transition, and only if Persisted::Loaded has already arrived. If a login could finish before the settings file loads, the first draft save would overwrite the stored drafts with only the in-memory ones. Startup loads first today, so I don't think this can happen now. A guard such as loading drafts on Loaded while logged in would make it robust.
  4. minor: message_reference for replies is built with guild_id: None, while the original also sends the guild id. The server accepts this; noting it for parity only.
  5. minor (carried over from Text chat 10): limits_of resolves guild features from ui.selected_channel, not from the draft's channel. Premium limits are still not modelled, as the PR says.

CI

I ran FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci locally in a clean review worktree. Result: "all steps passed", exit 0. chat_composer, chat_content and chat_autocomplete all ran and passed.

Verdict: APPROVED. There are no blocking findings, and local CI is green. Findings 1 to 3 could become follow-up issues.

## Independent review: Text chat 11 (core composer) I reviewed `git diff 53fbd6f..origin/textchat-11-core-composer` (head 7ca5a5c). **Plan tests:** all 18 named tests exist. `to_wire_cases` has 24 cases. The values match the spec: 1500/8000/16000 ms typing, the 400 ms draft save, 10 results per kind and the 50-member confirm threshold. **Interfaces:** these exist as the plan writes them: - `content::to_wire(&Draft, &App) -> WireContent { content, allowed_mentions, length_utf16 }` - `autocomplete::query(text, cursor) -> Option<Trigger>` with all 8 variants - `selectors::composer(&App, channel) -> ComposerModel` with every listed field, plus `Counter { remaining, over }` and `Slowmode { remaining_s, active }` - `LocalSettings::chat.drafts`, written through `Effect::Schedule` 400 ms after the last edit **Invariants:** - No new dependencies and no I/O in fluxer-core. - No file bytes, clipboard images, upload URLs or secrets. - No new fixtures. - Slicing in `convert`, `protected_len`, `typed_emoji`, `needs_mention_confirm` and `replace`/`adjust_spans` stays on char boundaries, so server or user text cannot panic it. - `TypingCooldown` uses the server's `message_send_cooldown_ms` (`api/channel/services/ChannelService.ts:40,219`). **Review Focus 2:** - `convert()` matches `EmoticonConversionUtils.ts`: the leading boundary is `\s`, the trailing boundary is a space or the end of the text, and backtick runs close only on a run of the same length. - Text is trimmed as `useTextareaSubmit.ts:461` does. - `allowed_mentions` is sent only with a reply, as `{replied_user}`. This matches `buildMessageCreateRequest`/`shouldIncludeAllowedMentions`, and `AllowedMentions` skips empty lists when it serializes. - Content length is counted in UTF-16 units. - Trigger detection follows the order and patterns of `SlashCommandUtils.ts:5-14`. `/kick|ban|msg` command arguments are not handled; the plan does not ask for them. ### Findings 1. **minor**: `chat/content.rs` `protected_len` protects only bare `http(s)://` URLs. It does not protect Markdown links `[text](url)`, which the original's `findMarkdownLinkEnd` does. So `[see :) here](https://x)` with emoticons on converts the `:)`, and the original leaves it. The module doc and the README also say "links" are untouched, which overstates it. Suggest a follow-up issue. 2. **minor**: `chat/autocomplete.rs` `mentions()` sorts recent authors first even when the query is not empty. Spec §3.2 says recent speakers come first "when the query is empty". This changes ranking only, not correctness. 3. **minor**: `app.rs` loads drafts back only on the not-logged-in to logged-in transition, and only if `Persisted::Loaded` has already arrived. If a login could finish before the settings file loads, the first draft save would overwrite the stored drafts with only the in-memory ones. Startup loads first today, so I don't think this can happen now. A guard such as loading drafts on `Loaded` while logged in would make it robust. 4. **minor**: `message_reference` for replies is built with `guild_id: None`, while the original also sends the guild id. The server accepts this; noting it for parity only. 5. **minor (carried over from Text chat 10)**: `limits_of` resolves guild features from `ui.selected_channel`, not from the draft's channel. Premium limits are still not modelled, as the PR says. ### CI I ran `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` locally in a clean review worktree. Result: "all steps passed", exit 0. `chat_composer`, `chat_content` and `chat_autocomplete` all ran and passed. **Verdict: APPROVED.** There are no blocking findings, and local CI is green. Findings 1 to 3 could become `follow-up` issues.
Author
Owner

Independent review: Text chat 11 (core composer), second pass, head 1ea0a32, diff cfbc399..origin/textchat-11-core-composer

Checks

  1. Plan tests: all 18 named tests are present (to_wire_cases in chat_content.rs has 20+ rows covering user/role/channel spans, @everyone/@here, usable and unusable custom emoji, :name: with skin tone, emoticons on/off and inside words, code spans and fences, UTF-16 length). The values match the spec: 1500/8000/16000 ms typing, 400 ms draft save, at most 10 results, the reply-mention default (off for own messages and DMs).
  2. Interfaces: content::to_wire(&Draft, &App) -> WireContent { content, allowed_mentions, length_utf16 }, autocomplete::query(text, cursor) -> Option<Trigger::{Mention, Channel, Emoji, Command, Gif, Sticker, Saved, React}>, and selectors::composer(&App, channel) -> ComposerModel { placeholder, text, reply, editing, counter{remaining, over}, slowmode{remaining_s, active}, can_send, can_attach, autocomplete{sections, selected}, everyone_confirm } all match the plan. LocalSettings::chat.drafts is written 400 ms after the last change through Effect::Schedule. The deviations listed in the PR (ApiResult::TypingCooldown, UserAction::ComposerEscape, limits_of, the legacy SendDraft routing) are additive and break no interface.
  3. Invariants: fluxer-core has no new dependencies (Cargo.toml is unchanged) and holds no file bytes, clipboard images or URLs. Slicing in convert, protected_len, typed_emoji, detect, replace and adjust_spans stays on char boundaries, and a cursor sent by the UI is clamped, so server data and UI input cannot panic. No secrets or paths appear anywhere.
  4. Review Focus 2: the trigger regexes and their priority follow SlashCommandUtils.ts:5-14. allowed_mentions is {replied_user} only when the message is a reply, as in MessageRequestUtils.ts (DEFAULT_ALLOWED_MENTIONS = {replied_user: true}). @everyone/@here and roles reaching more than 50 members go through the confirm. Code spans, fences, existing markup and bare URLs are left untouched. Length counts UTF-16 code units.
  5. FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci in the review worktree: all steps passed (exit 0).

Findings (no blocking findings; the earlier minor findings are tracked in #347)

  • minor: drafts are persisted as plain text only (take_due_drafts), without their mention spans. After a restart, a draft with a mention pill (@Ada L.) is sent as the literal text, not <@id>, unless the user picks the mention again.
  • minor: settings.chat.drafts is not keyed by account. After a logout and a login with another account on the same machine, the earlier account's drafts are loaded into the composer (they are shown only where the channel ids match, but the text stays in the file).
  • minor: needs_mention_confirm searches the converted content with contains("@everyone"), so @everyone inside a code span still asks for confirmation.

Verdict: APPROVED. No blocking findings, local CI is green.

🤖 Generated with Claude Code

**Independent review: Text chat 11 (core composer)**, second pass, head `1ea0a32`, diff `cfbc399..origin/textchat-11-core-composer` **Checks** 1. Plan tests: all 18 named tests are present (`to_wire_cases` in chat_content.rs has 20+ rows covering user/role/channel spans, `@everyone`/`@here`, usable and unusable custom emoji, `:name:` with skin tone, emoticons on/off and inside words, code spans and fences, UTF-16 length). The values match the spec: 1500/8000/16000 ms typing, 400 ms draft save, at most 10 results, the reply-mention default (off for own messages and DMs). 2. Interfaces: `content::to_wire(&Draft, &App) -> WireContent { content, allowed_mentions, length_utf16 }`, `autocomplete::query(text, cursor) -> Option<Trigger::{Mention, Channel, Emoji, Command, Gif, Sticker, Saved, React}>`, and `selectors::composer(&App, channel) -> ComposerModel { placeholder, text, reply, editing, counter{remaining, over}, slowmode{remaining_s, active}, can_send, can_attach, autocomplete{sections, selected}, everyone_confirm }` all match the plan. `LocalSettings::chat.drafts` is written 400 ms after the last change through `Effect::Schedule`. The deviations listed in the PR (`ApiResult::TypingCooldown`, `UserAction::ComposerEscape`, `limits_of`, the legacy `SendDraft` routing) are additive and break no interface. 3. Invariants: fluxer-core has no new dependencies (Cargo.toml is unchanged) and holds no file bytes, clipboard images or URLs. Slicing in `convert`, `protected_len`, `typed_emoji`, `detect`, `replace` and `adjust_spans` stays on char boundaries, and a cursor sent by the UI is clamped, so server data and UI input cannot panic. No secrets or paths appear anywhere. 4. Review Focus 2: the trigger regexes and their priority follow `SlashCommandUtils.ts:5-14`. `allowed_mentions` is `{replied_user}` only when the message is a reply, as in `MessageRequestUtils.ts` (`DEFAULT_ALLOWED_MENTIONS = {replied_user: true}`). `@everyone`/`@here` and roles reaching more than 50 members go through the confirm. Code spans, fences, existing markup and bare URLs are left untouched. Length counts UTF-16 code units. 5. `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` in the review worktree: **all steps passed** (exit 0). **Findings** (no blocking findings; the earlier minor findings are tracked in #347) - minor: drafts are persisted as plain text only (`take_due_drafts`), without their mention spans. After a restart, a draft with a mention pill (`@Ada L.`) is sent as the literal text, not `<@id>`, unless the user picks the mention again. - minor: `settings.chat.drafts` is not keyed by account. After a logout and a login with another account on the same machine, the earlier account's drafts are loaded into the composer (they are shown only where the channel ids match, but the text stays in the file). - minor: `needs_mention_confirm` searches the converted content with `contains("@everyone")`, so `@everyone` inside a code span still asks for confirmation. Verdict: **APPROVED**. No blocking findings, local CI is green. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
charles manually merged commit 55e5d937ec into textchat 2026-11-12 20:38:20 +00:00
Sign in to join this conversation.
No description provided.