drafts: Delete a draft if it is cleared from the compose box.

We used to keep the draft, assuming that clearing the composebox
was an accident. Now we want to delete the draft, in preparation
for auto-restoring drafts when opening the composebox for narrows
with drafts associated with them. If a user opens the composebox
and sees a draft they don't want anymore, clearing the box is a
way we expect them to try to delete it.
This commit is contained in:
evykassirer
2022-08-29 21:44:21 -07:00
committed by Tim Abbott
parent 01e898252b
commit cb3f22c30e
2 changed files with 21 additions and 6 deletions

View File

@@ -377,18 +377,18 @@ type UpdateDraftOptions = {
export function update_draft(opts: UpdateDraftOptions = {}): string | undefined {
const no_notify = opts.no_notify ?? false;
const draft = snapshot_message();
const draft_id = $("textarea#compose-textarea").data("draft-id");
if (draft === undefined) {
// The user cleared the compose box, which means
// there is nothing to save here. Don't obliterate
// the existing draft yet--the user may have mistakenly
// hit delete after select-all or something.
// Just do nothing.
// there is nothing to save here but delete the
// draft if exists.
if (draft_id) {
draft_model.deleteDraft(draft_id);
}
return undefined;
}
const draft_id = $("textarea#compose-textarea").data("draft-id");
if (draft_id !== undefined) {
// We don't save multiple drafts of the same message;
// just update the existing draft.