Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
drafts: Fix buggy "Saved as draft" notice flashing on send.
Tim Abbotted5d345aed3d
diff --git a/static/js/drafts.js b/static/js/drafts.jsindex 4e72442fbf7..16b1be9c8bc 100644--- a/static/js/drafts.js+++ b/static/js/drafts.js@@ -156,7 +156,8 @@ function draft_notify() {setTimeout(remove_instance, 1500);}-export function update_draft() {+export function update_draft(opts = {}) {+ const no_notify = opts.no_notify || false;const draft = snapshot_message();if (draft === undefined) {@@ -174,7 +175,9 @@ export function update_draft() {// We don't save multiple drafts of the same message;// just update the existing draft.draft_model.editDraft(draft_id, draft);- draft_notify();+ if (!no_notify) {+ draft_notify();+ }return draft_id;}@@ -182,7 +185,9 @@ export function update_draft() {// one.const new_draft_id = draft_model.addDraft(draft);$("#compose-textarea").data("draft-id", new_draft_id);- draft_notify();+ if (!no_notify) {+ draft_notify();+ }return new_draft_id;}diff --git a/static/js/echo.js b/static/js/echo.jsindex 9a747394134..d43b8deaa43 100644--- a/static/js/echo.js+++ b/static/js/echo.js@@ -237,9 +237,12 @@ export function try_deliver_locally(message_request) {return undefined;}- // Only saving in draft for locally echoed message- // This draft will be cleared after successfull message- const draft_id = drafts.update_draft();+ // Save a locally echoed message in drafts, so it cannot be+ // lost. It will be cleared if the message is sent successfully.+ // We ask the drafts system to not notify the user, since they'd+ // be quite distracting in the very common case that the message+ // sends normally.+ const draft_id = drafts.update_draft({no_notify: true});message_request.draft_id = draft_id;// Now that we've committed to delivering the message locally, we