mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
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.
This commit is contained in:
committed by
Tim Abbott
parent
39895b0c3d
commit
c62938a1b1
@@ -182,6 +182,10 @@ export let send_message = (request = create_message_object()) => {
|
|||||||
no_notify: true,
|
no_notify: true,
|
||||||
update_count: false,
|
update_count: false,
|
||||||
is_sending_saving: true,
|
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;
|
let local_id;
|
||||||
|
|||||||
@@ -317,10 +317,12 @@ export function rename_stream_recipient(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function snapshot_message(): LocalStorageDraft | undefined {
|
export function snapshot_message(force_save = false): LocalStorageDraft | undefined {
|
||||||
if (!compose_state.composing() || !compose_state.has_savable_message_content()) {
|
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
|
// 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;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -423,6 +425,7 @@ type UpdateDraftOptions = {
|
|||||||
no_notify?: boolean;
|
no_notify?: boolean;
|
||||||
update_count?: boolean;
|
update_count?: boolean;
|
||||||
is_sending_saving?: boolean;
|
is_sending_saving?: boolean;
|
||||||
|
force_save?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export let update_draft = (opts: UpdateDraftOptions = {}): string | undefined => {
|
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 old_draft = draft_id === undefined ? undefined : draft_model.getDraft(draft_id);
|
||||||
|
|
||||||
const no_notify = opts.no_notify ?? false;
|
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) {
|
if (draft === undefined) {
|
||||||
// The user cleared the compose box, which means
|
// The user cleared the compose box, which means
|
||||||
|
|||||||
Reference in New Issue
Block a user