Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
drafts: Convert .data("draft-id") to a module variable.
Anders Kaseorg49e1c919c31a
diff --git a/web/src/compose.js b/web/src/compose.jsindex e60ec77e258..003c7924afe 100644--- a/web/src/compose.js+++ b/web/src/compose.js@@ -132,7 +132,7 @@ export function clear_compose_box() {$("textarea#compose-textarea").val("").trigger("focus");compose_validate.check_overflow_text();compose_validate.clear_topic_resolved_warning();- $("textarea#compose-textarea").removeData("draft-id");+ drafts.set_compose_draft_id(undefined);compose_ui.autosize_textarea($("textarea#compose-textarea"));compose_banner.clear_errors();compose_banner.clear_warnings();diff --git a/web/src/compose_actions.ts b/web/src/compose_actions.tsindex 19cb224eb60..b6662cb993f 100644--- a/web/src/compose_actions.ts+++ b/web/src/compose_actions.ts@@ -124,7 +124,7 @@ function clear_box(): void {compose_state.set_recipient_edited_manually(false);clear_textarea();compose_validate.check_overflow_text();- $("textarea#compose-textarea").removeData("draft-id");+ drafts.set_compose_draft_id(undefined);$("textarea#compose-textarea").toggleClass("invalid", false);compose_ui.autosize_textarea($("textarea#compose-textarea"));compose_banner.clear_errors();@@ -338,7 +338,7 @@ export function start(raw_opts: ComposeActionsStartOpts): void {show_compose_box(opts);if (opts.draft_id) {- $("textarea#compose-textarea").data("draft-id", opts.draft_id);+ drafts.set_compose_draft_id(opts.draft_id);}const $clear_topic_button = $("#recipient_box_clear_topic_button");diff --git a/web/src/drafts.ts b/web/src/drafts.tsindex 71a74a248f8..7683e457b01 100644--- a/web/src/drafts.ts+++ b/web/src/drafts.ts@@ -382,6 +382,12 @@ function maybe_notify(no_notify: boolean): void {}}+export let compose_draft_id: string | undefined;++export function set_compose_draft_id(draft_id: string | undefined): void {+ compose_draft_id = draft_id;+}+type UpdateDraftOptions = {no_notify?: boolean;update_count?: boolean;@@ -389,8 +395,7 @@ type UpdateDraftOptions = {};export function update_draft(opts: UpdateDraftOptions = {}): string | undefined {- const draft_id: unknown = $("textarea#compose-textarea").data("draft-id");- assert(draft_id === undefined || typeof draft_id === "string");+ const draft_id = compose_draft_id;const old_draft = draft_id === undefined ? undefined : draft_model.getDraft(draft_id);const no_notify = opts.no_notify ?? false;@@ -428,7 +433,7 @@ export function update_draft(opts: UpdateDraftOptions = {}): string | undefined// We have never saved a draft for this message, so add one.const update_count = opts.update_count ?? true;const new_draft_id = draft_model.addDraft(draft, update_count);- $("textarea#compose-textarea").data("draft-id", new_draft_id);+ compose_draft_id = new_draft_id;maybe_notify(no_notify);return new_draft_id;diff --git a/web/tests/compose_actions.test.js b/web/tests/compose_actions.test.jsindex 990335f0c3f..d3ecc041511 100644--- a/web/tests/compose_actions.test.js+++ b/web/tests/compose_actions.test.js@@ -46,6 +46,7 @@ mock_esm("../src/drafts", {update_draft: noop,update_compose_draft_count: noop,get_last_restorable_draft_based_on_compose_state: noop,+ set_compose_draft_id: noop,});mock_esm("../src/unread_ops", {notify_server_message_read: noop,