Skip to content

The desktop app keeps unsent drafts across restarts and shows them in the chat list - #199

Merged
pitis merged 2 commits into
mainfrom
feat/desktop-drafts
Nov 14, 2026
Merged

pitis merged 2 commits into
mainfrom
feat/desktop-drafts

Conversation

@pitis

@pitis pitis commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

What changed

The desktop app (core/desktop) now keeps unsent text across launches and shows it in the chat list, as the Mac app does.

  • Kept in the core's encrypted database (the owner's choice over a plain file): the core already has the drafts table (SQLCipher, migration 0029) and the two Client calls, set_draft (blank text clears) and drafts, exposed through UniFFI. The Mac app moved onto them in Group keys and contact ids stay out of logs, file names, notifications and preferences #176. No core, schema or UniFFI change in this PR; the desktop app uses the same calls.

  • Every change is written (AppStore.saveDraft): what the composer holds is the open chat's draft, unless it holds an edit (the draft from before the edit stays). Writes go through one queue. Changes that pile up while the database is busy are folded down to each chat's last one, so quitting waits for at most one write per chat. A failed write or read is shown, and logged with the error only (never the text).

  • Quitting waits for the writes (AppStore.stop): Cmd/Ctrl-Q and closing the window both go through quit, which closes the queue and waits for it to finish before stopping the core. Because the text is saved as it's typed, nothing depends on the window still being there when the app quits.

  • Read at launch (AppStore.loadDrafts), before the chats are listed. If the read fails, the app says so and keeps nothing typed until the next launch, so it can't write over drafts it never read.

  • Sending or clearing the text removes the draft. A failed send puts its words back:

    • into the composer;
    • into the chat's draft;
    • or, if an edit was started meanwhile, back once the edit ends.

    If the chat already has a draft, or new text was typed, the words are lost (as on the Mac), and the error no longer says they're back. A deleted chat's draft is cleared once the delete worked, after any write still queued. A failed delete keeps the draft (AppStore.deleteChat).

  • Chat list: a chat that isn't open shows "Draft: …" (text::preview, one line, as ChatList.line / SidebarView), after what the chat is (Blocked, Message request, …) and before its last message. The last message's tick isn't shown under a draft.

  • The snapshot demo gives Note to Self a draft, and its last message is now ours, as it always is in Note to Self.

New module: core/desktop/src/app/drafts.rs. The hooks in mod.rs, compose.rs and view.rs are a few lines each.

Drafts keep the words, not their styles, as on the Mac.

Why

Closes the shortcut: on drafts in app/mod.rs. Before this, the desktop app lost every draft and the open composer's text when it quit, and the chat list never showed that a chat had a draft.

How it was tested

  • text: the "Draft: …" line comes after what the chat is and before the last message, on one line, and shows even when the chat has no messages yet.
  • drafts::tests: a change is written once the drafts are read, an unchanged one isn't, and blank text clears. Writes queued before quitting are all written, and a real core opened again over the same folder returns them (encrypted DB).
  • drafts::window_tests (headless window, --features snapshot):
    • Typing writes the open chat's draft. Before the hooks were added, this test failed at its first check.
    • An edit writes nothing, and the earlier draft comes back.
    • A send that fails while an edit is open comes back once the edit ends.
    • Switching chats puts the other chat's draft in the composer, and the list shows this one's.
    • Clearing by hand clears the draft. Sending clears it, and a failed send writes it back.
    • If new text was typed before the failure, the new text stays and the error doesn't claim the words are back.
    • Over a real core: the drafts are read at launch, and a failed delete keeps the draft. What is typed is written before Writer::finish ends, and is there when the folder is opened again. Not closing the queue makes this test fail.
  • make format, make lint, cd core && cargo test -q, cargo test -p hush-desktop --features snapshot (3 runs), cargo clippy -p hush-desktop --all-targets --features snapshot -- -D warnings: all pass.
  • I rendered the snapshots and checked them:
    • Note to Self reads "Draft: Renew the passport before Ju…" with no tick, in light and dark.
    • On the Files screen (no draft), its read tick shows.
  • No Swift or sig-core change, so the Swift leg wasn't affected.

Follow-ups

Closes #134

… the chat list

Each change to the composer is written to the core's encrypted drafts
table, in order, and quitting waits for the writes on their way. The
drafts are read at launch; a chat that isn't open shows "Draft: …".
A draft row shows no tick; a failed send's words are never said to be
back when they weren't, and come back after an edit; a failed delete
keeps the draft; write and read failures are logged (errors only);
queued writes are folded to each chat's last; tests cover reading,
writing and quitting over a real core.
@pitis

pitis commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

Review (/pr-review-toolkit:review-pr): findings and fixes

Five review agents read this PR: code, silent failures, tests, comments and types. Nothing Critical turned up in the code. The test reviewer rated one gap Critical, and it's fixed below. Every fix is in 235990b.

Fixed

  1. Important (code): the last message's tick showed in front of "Draft: …". The Mac's .draft line has no tick, and a read tick next to a draft looked like the draft had been read.

    • The row now works out drafted once, and uses it both to hide the tick and to style the "Draft:" prefix.
    • The demo's Note to Self now has our message as its last one, as in real use. The snapshot shows no tick with a draft, and a tick without one.
  2. Important (silent failures, comments, types): a failed send could lose its words while saying "Its text is back in its chat".

    • If new text was typed meanwhile: the new text stays (Mac behaviour) and the error no longer claims the words are back. attach::unsent gets back instead of worded.
    • If an edit was started meanwhile: the words go into the draft kept from before the edit (Actions::set_aside) and into the stored draft, so they come back when the edit ends. Before, ending the edit wiped them.
    • Whitespace-only composer: it now counts as empty when the words go back.
    • Covered in the window test.
  3. Important (silent failures): draft write and read failures weren't logged. After the window closes, nobody would see them. Both now tracing::warn! with the error only, never the text.

  4. Critical (tests): load_drafts and Writer::finish were untested. New headless window test, a_draft_typed_before_quitting_is_there_at_the_next_launch, over a real core in a temp folder:

    1. The drafts are read at launch.
    2. A failed delete keeps the draft.
    3. Text is typed, finish() ends after writing it, and the reopened folder has it.

    With finish changed so it doesn't close the queue, the test fails ("written: the core didn't answer in 5 s"). quit itself isn't called: it clears the real data folder's copies and quits the app. Its order (written.await before client.stop()) can only be checked by reading the code.

  5. Important (tests): the row's draft wiring was untested. The view now asks Hush::listed_draft(id) (none for the open chat). The window test asserts that it gives Family's draft after switching chats, and none for the open chat.

  6. Suggestion, taken (comments, tests): a failed delete wiped the draft, and the Mac keeps it. The draft is now cleared only once the delete worked, after any write still queued (AppStore.deleteChat). Tested for the failure case.

  7. Suggestion, taken (silent failures): quitting could wait on a long queue. That happens if the database connection is busy (one write per keystroke). write now folds what is queued down to each chat's last text, so quitting waits for at most one write per chat.

  8. Comments:

    • load_drafts, loaded, writes, keep_draft, set_typed and quit docs now say what they actually do.
    • The failed-read message now says what is true: "What you type isn't kept after Hush quits."
    • The DRAFT const cites SidebarView, which draws the prefix.
    • The launch order (drafts read before the chats) is commented.
    • The test helper doc and the unit test name no longer overclaim.

Declined

  • No time limit on quit waiting for draft writes (silent failures, Suggestion). The Mac app's stop waits the same way (await lastDraftWrite?.value). With folding (item 7), the wait is one write per chat, and a stuck database would stall the core's own stop anyway.
  • Test for a failed draft read at launch (tests, Suggestion). The reviewer agreed it isn't worth the cost: a real core can't easily be made to fail the read. The only effect of that path is that nothing gets written.
  • Re-reading drafts when the chat list changes (AppStore.reloadDrafts). This stays a documented shortcut: in drafts.rs: a chat deleted on the phone keeps its draft here until the next launch.

Needs the owner (not changed)

  • make test doesn't run the desktop window tests (--features snapshot), here or in the other modules. Adding cargo test -p hush-desktop --features snapshot to make test would close that gap.

Re-checked after the fixes

All of these pass:

  • make format
  • make lint
  • cd core && cargo test -q
  • cargo test -p hush-desktop --features snapshot, run 3 times with 149 tests each run
  • cargo clippy -p hush-desktop --all-targets --features snapshot -- -D warnings

I re-rendered the snapshots and checked them.

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.

The desktop app keeps unsent drafts across restarts and shows them in the chat list

1 participant