Skip to content

A reply or edit ends, as on Esc, when its chat can no longer be written in - #306

Merged
pitis merged 5 commits into
mainfrom
fix/reply-ends-without-composer
Nov 29, 2026
Merged

pitis merged 5 commits into
mainfrom
fix/reply-ends-without-composer

Conversation

@pitis

@pitis pitis commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

What changed

A reply or an edit that is open when its chat can no longer be written in now ends. That covers a chat blocked from the sidebar, turned back into a request, or changed by a sync from the phone. It ends the way Esc ends it:

  • A reply is dropped. What was typed stays in the composer as the chat's draft. Nothing is sent.
  • An edit is dropped, and the draft it replaced comes back, as on Esc.
  • Nothing is said. The bar in place of the composer ("You blocked …", the request's answers) already shows why. Esc says nothing either. The one notice nearby is for an edit whose message was deleted ("…so the edit wasn't sent."), and that is a different case.
  • After an unblock, the reply or edit doesn't come back.
  • A message menu opened before the chat lost its composer still offers Reply and Edit. Picking one now starts nothing: reply and start_editing check has_composer() first.

How it's built:

  • Every change to a chat's state reaches the app as a chat-list reload (ConversationsChanged → refresh_chats → set_chats). That is also the only place the list changes outside the demo. So set_chats calls a new chats_loaded, which asks has_composer() (A chat without a composer is read-only: its messages offer only Copy and Delete for Everyone #302) about the open chat. Without one, it ends the reply and the edit.
  • Ending an edit restores the draft, and that needs the window, which a load doesn't have. edit_gone already defers stop_editing for this reason. That deferral is now stop_editing_later, which both use.
  • It runs once: after the first reload the reply and edit are gone, so later reloads find nothing to end. A reload that leaves the chat with a composer changes nothing.

Why

Found in the review of #302. A reply or edit open when the chat lost its composer was kept, unseen. It came back when the chat had a composer again, possibly much later and in a different context.

How it was tested

  • Window test actions::window_tests::a_reply_or_edit_ends_as_on_esc_when_its_chat_loses_its_composer. It was written first and failed at each step:

    • On the code before the fix: blocked: the reply ends — left: Some("Replying to yourself"), right: None.
    • With only the reply's half of the fix: blocked: the edit ends — left: Some("Editing message"), right: None.

    The test replies to our message in the Family group and types "half a reply", then:

    • A reload with another chat (Ana's) blocked keeps the reply.
    • A reload with the group blocked ends the reply, which is what the core sends after a block from the sidebar. The demo has no core, so the reload stands in for the block. The composer still holds "half a reply", and the chat's draft is "half a reply".
    • A second reload while it's blocked changes nothing.
    • Unblocked, the reply doesn't come back.
    • The test then edits the same message. A normal reload keeps the edit. With the group turned back into a request, the edit ends: the composer and the draft are back to "half a reply", a second reload changes nothing, and no error is set. Accepted, the edit doesn't come back.
    • After the review's additions, it was checked again with chats_loaded switched off: it fails at "blocked: the reply ends".
    • A last step opens our message's menu from the keys, blocks the chat, then picks Reply, and again Edit: neither starts. It failed first: at "Reply, picked once blocked" without the guards, and at "Edit, picked once blocked" with only reply's.
  • Gate. make format && make check on 2ac8e61, which has origin/main 32364a4 merged:

    • cargo fmt --check passes.
    • cargo clippy --all-targets -D warnings passes, plain and with --features hush-desktop/snapshot.
    • cargo test --features hush-desktop/snapshot passes (405 + 554 tests, 4 ignored as before).
    • It ran with TZ=America/New_York. One test outside this PR, files::window_tests::a_click_on_a_file_presses_it_and_leaves_the_keys_in_the_composer, fails from 00:00 to about 01:30 local time on origin/main's code too, because of a day line among the demo's files (see the review comment).
  • Snapshots: none. Nothing drawn changed, and the bar that replaces the composer is A chat without a composer is read-only: its messages offer only Copy and Delete for Everyone #302's.

Not changed:

  • A send the core refuses puts its reply back (restore_reply). If the chat lost its composer in between, the reply would come back unseen. The core answers as soon as the message is stored and queued, so the window is one local database write. A failure on the network marks the message Failed and puts nothing back. This is left as is.

Closes #303

@pitis

pitis commented Nov 29, 2026

Copy link
Copy Markdown
Owner Author

Review (/pr-review-toolkit:review-pr on git diff origin/main...HEAD)

I ran three reviewers: code, tests and comments. None found anything Critical. The code reviewer found no Important issues either. It checked that set_chats is the only place the chat list changes outside the demo, that the deferred edit end runs once and safely, and that a normal reload returns before touching anything.

Important (tests), fixed in cb981a6:

  1. No test that a second reload while the chat has no composer changes nothing. That is the "once" in the requirement. The test now reloads twice in that state and checks that the composer and the draft still hold "half a reply" both times.
  2. Only a block was exercised. A fix that checked blocked alone, in place of has_composer(), would have passed. The edit half now turns the chat back into a request (message_request), and the reply half still uses a block.

Suggestions:

  • Tests: the "not sent" label couldn't fail, because the demo has no core to send with. It now says "what was typed stays". Fixed.
  • Tests: nothing checked that blocking another chat keeps the open chat's reply. The first reload now blocks Ana's chat and checks that the reply stays. Fixed.
  • Tests: the open chat dropping out of the list also ends the reply or edit, which matches the "Select a chat" screen. Declined: it isn't in the issue, and the view already treats a missing chat as having no composer.
  • Comments: chats_loaded's doc now says why the reply or edit has to end (else it would come back unseen). It names the bar it means (render_request_bar), which can't be mixed up with composer_bar, and says "blocked or a request" in place of "a request again". The test's comment says "the Family group". Fixed.
  • Code: a message menu already open when a sync from the phone blocks the chat still offers Reply and Edit. Picking one starts a reply or edit in a chat with no composer, which nothing ends until the next reload. Declined, here: this is an old race, not one this PR makes, and the issue doesn't cover it. It needs a menu open at the very moment a sync arrives. The fix would be a has_composer() guard at the top of reply and start_editing. It can be a follow-up if wanted.

Not changed, as the PR body says: restore_reply after a send the core refuses. The window is one local database write.

Gate on dc0215a (origin/main 32364a4 merged): make format && make check passes: fmt, both clippy runs, and tests (405 + 554, 4 ignored as before). It ran with TZ=America/New_York, because one test outside this PR, files::window_tests::a_click_on_a_file_presses_it_and_leaves_the_keys_in_the_composer, fails between 00:00 and about 01:30 local time on origin/main's own code too. The demo's files are 90 to 20 minutes old, so after midnight a day line falls between them and moves the photo the test clicks. With any other clock it passes.

@pitis

pitis commented Nov 29, 2026

Copy link
Copy Markdown
Owner Author

Follow-up to the review: the guard is added (2ac8e61). This was the declined code suggestion; it's now done at the orchestrator's request.

  • reply and start_editing return at once when the open chat has no composer (has_composer()). A message menu opened before a sync from the phone blocked the chat still offers Reply and Edit, but picking either now starts nothing.
  • Test: a new step in a_reply_or_edit_ends_as_on_esc_when_its_chat_loses_its_composer opens our "On my way"'s menu from the keys, blocks the chat with a set_chats reload, then picks Reply. It does the same again for Edit. Neither starts, and the composer keeps "half a reply". With a composer back, the same picks reply and edit. The step failed first: without the guards at "Reply, picked once blocked" (left Some("Replying to yourself")), and with only reply's guard at "Edit, picked once blocked" (left Some("Editing message")).
  • Gate on 2ac8e61 (up to date with origin/main 32364a4): make format && make check passes: fmt, both clippy runs, and tests (405 + 554, 4 ignored).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An open reply or edit ends when its chat can no longer be written in

1 participant