FIX: more resilient whisper state between composer states (#6687)

FIX: more resilient whisper state between composer states (#6687)

From 4f24d7dec8e32742ab1524857c68ce4c77ae2040 Mon Sep 17 00:00:00 2001
From: Joffrey JAFFEUX <j.jaffeux@gmail.com>
Date: Thu, 29 Nov 2018 16:16:34 +0100
Subject: [PATCH] FIX: more resilient whisper state between composer states
 (#6687)


diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6
index 4117b7d..0425973 100644
--- a/app/assets/javascripts/discourse/controllers/composer.js.es6
+++ b/app/assets/javascripts/discourse/controllers/composer.js.es6
@@ -194,9 +194,13 @@ export default Ember.Controller.extend({
 
   canUnlistTopic: Em.computed.and("model.creatingTopic", "isStaffUser"),
 
-  @computed("canWhisper", "model.whisper")
-  showWhisperToggle(canWhisper, isWhisper) {
-    return canWhisper && !isWhisper;
+  @computed("canWhisper", "model.post")
+  showWhisperToggle(canWhisper, repliedToPost) {
+    const replyingToWhisper =
+      repliedToPost &&
+      repliedToPost.get("post_type") === this.site.post_types.whisper;
+
+    return canWhisper && !replyingToWhisper;
   },
 
   @computed("isStaffUser", "model.action")
@@ -220,7 +224,7 @@ export default Ember.Controller.extend({
     return option;
   },
 
-  @computed("model.composeState", "model.creatingTopic")
+  @computed("model.composeState", "model.creatingTopic", "model.post")
   popupMenuOptions(composeState) {
     if (composeState === "open" || composeState === "fullscreen") {
       let options = [];
diff --git a/test/javascripts/acceptance/composer-test.js.es6 b/test/javascripts/acceptance/composer-test.js.es6
index c1fa34b..c878f5c 100644
--- a/test/javascripts/acceptance/composer-test.js.es6
+++ b/test/javascripts/acceptance/composer-test.js.es6
@@ -366,28 +366,36 @@ QUnit.test("Composer can toggle between edit and reply", async assert => {
 });
 
 QUnit.test("Composer can toggle whispers", async assert => {
+  const menu = selectKit(".toolbar-popup-menu-options");
+
   await visit("/t/this-is-a-test-topic/9");
   await click(".topic-post:eq(0) button.reply");
 
-  await selectKit(".toolbar-popup-menu-options").expand();
-  await selectKit(".toolbar-popup-menu-options").selectRowByValue(
-    "toggleWhisper"
-  );
+  await menu.expand();
+  await menu.selectRowByValue("toggleWhisper");
 
   assert.ok(
     find(".composer-fields .whisper .d-icon-eye-slash").length === 1,
     "it sets the post type to whisper"
   );
 
-  await selectKit(".toolbar-popup-menu-options").expand();
-  await selectKit(".toolbar-popup-menu-options").selectRowByValue(
-    "toggleWhisper"
-  );
+  await menu.expand();
+  await menu.selectRowByValue("toggleWhisper");
 
   assert.ok(
     find(".composer-fields .whisper .d-icon-eye-slash").length === 0,
     "it removes the whisper mode"
   );
+
+  await menu.expand();
+  await menu.selectRowByValue("toggleWhisper");
+
+  await click(".toggle-fullscreen");
+
+  assert.ok(
+    menu.rowByValue("toggleWhisper").exists(),
+    "whisper toggling is still present when going fullscreen"
+  );
 });
 
 QUnit.test(

GitHub

1 Like

Nice change! should make mistake non whisper replies a lot rarer

1 Like