drafts: Extract maybe_notify function in update_draft.

This is a prep commit for adding node test coverage to
drafts.update_draft().
This commit is contained in:
YashRE42
2021-11-30 23:57:11 +05:30
committed by Tim Abbott
parent 555f80c34b
commit c8f18f8ae7

View File

@@ -175,6 +175,12 @@ function draft_notify() {
setTimeout(remove_instance, 3000);
}
function maybe_notify(no_notify) {
if (!no_notify) {
draft_notify();
}
}
export function update_draft(opts = {}) {
const no_notify = opts.no_notify || false;
const draft = snapshot_message();
@@ -194,9 +200,7 @@ export function update_draft(opts = {}) {
// We don't save multiple drafts of the same message;
// just update the existing draft.
draft_model.editDraft(draft_id, draft);
if (!no_notify) {
draft_notify();
}
maybe_notify(no_notify);
return draft_id;
}
@@ -204,9 +208,7 @@ export function update_draft(opts = {}) {
// one.
const new_draft_id = draft_model.addDraft(draft);
$("#compose-textarea").data("draft-id", new_draft_id);
if (!no_notify) {
draft_notify();
}
maybe_notify(no_notify);
return new_draft_id;
}