A platform for community discussion. Free, open, simple.
FIX: restore whisper state when reopening a draft (#37510)
Renato Atilio5171c32f4b56
diff --git a/frontend/discourse/app/controllers/topic.js b/frontend/discourse/app/controllers/topic.jsindex e6b572f88e8..148df69eb75 100644--- a/frontend/discourse/app/controllers/topic.js+++ b/frontend/discourse/app/controllers/topic.js@@ -801,6 +801,9 @@ export default class TopicController extends Controller {post?.get("post_number") !== 1) {composerController.set("model.post", post);+ if (post?.get("post_type") === this.site.post_types.whisper) {+ composerController.set("model.whisper", true);+ }composerController.set("model.composeState", Composer.OPEN);this.appEvents.trigger("composer:insert-block", quotedText.trim());} else {@@ -821,6 +824,7 @@ export default class TopicController extends Controller {if (draftData.draft) {const data = JSON.parse(draftData.draft);opts.draftSequence = draftData.draft_sequence;+ opts.whisper = data.whisper;if (quotedText) {opts.reply = data.reply + "\n" + quotedText;diff --git a/frontend/discourse/app/models/composer.js b/frontend/discourse/app/models/composer.jsindex 54799a5f658..9ccff645262 100644--- a/frontend/discourse/app/models/composer.js+++ b/frontend/discourse/app/models/composer.js@@ -929,7 +929,8 @@ export default class Composer extends RestModel {if (opts.post) {this.setProperties({post: opts.post,- whisper: opts.post.post_type === this.site.post_types.whisper,+ whisper:+ opts.whisper ?? opts.post.post_type === this.site.post_types.whisper,});if (!this.topic) {diff --git a/frontend/discourse/tests/acceptance/composer-test.js b/frontend/discourse/tests/acceptance/composer-test.jsindex cc1f7014aab..5f9f3146a40 100644--- a/frontend/discourse/tests/acceptance/composer-test.js+++ b/frontend/discourse/tests/acceptance/composer-test.js@@ -906,6 +906,26 @@ acceptance(`Composer`, function (needs) {.exists("toggle whisper is available when reply to topic");});+ test("Composer restores whisper state from draft", async function (assert) {+ pretender.get("/drafts/topic_9.json", function () {+ return response(200, {+ draft: JSON.stringify({+ reply: "draft with whisper",+ action: "reply",+ whisper: true,+ }),+ draft_sequence: 1,+ });+ });++ await visit("/t/this-is-a-test-topic/9");+ await click(".topic-post[data-post-number='2'] button.reply");++ assert+ .dom("#reply-control.composing-whisper")+ .exists("composer shows whisper styling from draft");+ });+test("Composer draft with dirty reply can toggle to edit", async function (assert) {await visit("/t/this-is-a-test-topic/9");