From c8f18f8ae78eac4a4beae8a744268196db855bfb Mon Sep 17 00:00:00 2001 From: YashRE42 <33805964+YashRE42@users.noreply.github.com> Date: Tue, 30 Nov 2021 23:57:11 +0530 Subject: [PATCH] drafts: Extract maybe_notify function in update_draft. This is a prep commit for adding node test coverage to drafts.update_draft(). --- static/js/drafts.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/static/js/drafts.js b/static/js/drafts.js index 33c9cb2e99..e45274d334 100644 --- a/static/js/drafts.js +++ b/static/js/drafts.js @@ -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; }