From 951b3016a472c5d44859cb934d6c5b85e92b0eae Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Thu, 2 Jun 2022 23:36:34 +0530 Subject: [PATCH] FIX: keep composer draft when go back and forth between PM and New Topic. (#16978) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, draft get destroyed accidentally when we switch to PM with the below steps 1. Click “New Topic” 2. Type in the body 3. Switch to “New Message” 4. Click “cancel” --- app/assets/javascripts/discourse/app/models/composer.js | 3 ++- .../discourse/tests/acceptance/composer-actions-test.js | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/app/models/composer.js b/app/assets/javascripts/discourse/app/models/composer.js index d5bed57f0f5..396de7cefbc 100644 --- a/app/assets/javascripts/discourse/app/models/composer.js +++ b/app/assets/javascripts/discourse/app/models/composer.js @@ -871,7 +871,8 @@ const Composer = RestModel.extend({ this.set("title", opts.title); } - this.set("originalText", opts.draft ? "" : this.reply); + const isDraft = opts.draft || opts.skipDraftCheck; + this.set("originalText", isDraft ? "" : this.reply); if (this.canEditTitle) { if (isEmpty(this.title) && this.title !== "") { diff --git a/app/assets/javascripts/discourse/tests/acceptance/composer-actions-test.js b/app/assets/javascripts/discourse/tests/acceptance/composer-actions-test.js index d0bb7d62ab4..06796dd2306 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/composer-actions-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/composer-actions-test.js @@ -38,6 +38,12 @@ acceptance("Composer Actions", function (needs) { assert.ok(queryAll("#reply-title").val(), "this is the title"); assert.ok(queryAll(".d-editor-input").val(), "this is the reply"); + + await click("#reply-control a.cancel"); + assert.ok( + exists(".discard-draft-modal.modal"), + "it pops up the discard drafts modal" + ); }); test("replying to post", async function (assert) {