Repository navigation
The desktop app keeps unsent drafts across restarts and shows them in the chat list - #199
Conversation
… 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.
Review (
|
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
draftstable (SQLCipher, migration0029) and the twoClientcalls,set_draft(blank text clears) anddrafts, 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 throughquit, 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:
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, asChatList.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 inmod.rs,compose.rsandview.rsare a few lines each.Drafts keep the words, not their styles, as on the Mac.
Why
Closes the
shortcut:ondraftsinapp/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):Writer::finishends, 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.sig-corechange, so the Swift leg wasn't affected.Follow-ups
shortcut:not ported from the Mac app: it reads the drafts again when the chat list changes (a chat deleted on the phone takes its draft). Here, a draft that is still in memory for such a chat stays until the next launch. It only shows if that chat comes back in the same session.Closes #134