From c62938a1b1cd0f079fa8b51d61a2948eb78058f3 Mon Sep 17 00:00:00 2001 From: Pratik Chanda Date: Sun, 27 Jul 2025 18:14:55 +0530 Subject: [PATCH] message_send: Fix update draft error when message send fails. Currently, we save a draft copy in case message send fails on server but this only saves a copy of message when it has savable message length. Short message doesn't save a copy and throws an error. This commit introduces a new option `force_save` to `update_draft` and saves any message regardless of message length if passed true. --- web/src/compose.js | 4 ++++ web/src/drafts.ts | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/web/src/compose.js b/web/src/compose.js index 69a038da89..09b4c1f0ad 100644 --- a/web/src/compose.js +++ b/web/src/compose.js @@ -182,6 +182,10 @@ export let send_message = (request = create_message_object()) => { no_notify: true, update_count: false, is_sending_saving: true, + // Even 2-character messages that you actually tried to send + // should be saved as a draft, since it's confusing if a + // message can just disappear into the void. + force_save: true, }); let local_id; diff --git a/web/src/drafts.ts b/web/src/drafts.ts index cc30b85d01..ac02703c66 100644 --- a/web/src/drafts.ts +++ b/web/src/drafts.ts @@ -317,10 +317,12 @@ export function rename_stream_recipient( } } -export function snapshot_message(): LocalStorageDraft | undefined { - if (!compose_state.composing() || !compose_state.has_savable_message_content()) { +export function snapshot_message(force_save = false): LocalStorageDraft | undefined { + const can_save_message = force_save || compose_state.has_savable_message_content(); + if (!compose_state.composing() || !can_save_message) { // If you aren't in the middle of composing the body of a - // message or the message is shorter than 2 characters long, don't try to snapshot. + // message, forcing a save or the message is shorter than 2 characters long, + // don't try to snapshot. return undefined; } @@ -423,6 +425,7 @@ type UpdateDraftOptions = { no_notify?: boolean; update_count?: boolean; is_sending_saving?: boolean; + force_save?: boolean; }; export let update_draft = (opts: UpdateDraftOptions = {}): string | undefined => { @@ -430,7 +433,8 @@ export let update_draft = (opts: UpdateDraftOptions = {}): string | undefined => const old_draft = draft_id === undefined ? undefined : draft_model.getDraft(draft_id); const no_notify = opts.no_notify ?? false; - const draft = snapshot_message(); + const force_save = opts.force_save ?? false; + const draft = snapshot_message(force_save); if (draft === undefined) { // The user cleared the compose box, which means