REFACTOR: composer controller (#7516)

REFACTOR: composer controller (#7516)

diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6
index 9a370ce..c6b1aba 100644
--- a/app/assets/javascripts/discourse/controllers/composer.js.es6
+++ b/app/assets/javascripts/discourse/controllers/composer.js.es6
@@ -116,7 +116,7 @@ export default Ember.Controller.extend({
   },
 
   @computed("showPreview")
-  toggleText: function(showPreview) {
+  toggleText(showPreview) {
     return showPreview
       ? I18n.t("composer.hide_preview")
       : I18n.t("composer.show_preview");
@@ -127,7 +127,7 @@ export default Ember.Controller.extend({
     if (!this.site.mobileView) {
       this.keyValueStore.set({
         key: "composer.showPreview",
-        value: this.get("showPreview")
+        value: this.showPreview
       });
     }
   },
@@ -147,7 +147,7 @@ export default Ember.Controller.extend({
     usernames = usernames || "";
     if (
       (creatingPM && usernames.length === 0) ||
-      usernames === this.currentUser.get("username")
+      usernames === this.currentUser.username
     ) {
       return "usernames";
     }
@@ -172,7 +172,7 @@ export default Ember.Controller.extend({
         // be default disabled.
         // That said we should remember the state
         this._toolbarEnabled =
-          $(window).width() > 370 && !this.capabilities.isAndroid;
+          window.innerWidth > 370 && !this.capabilities.isAndroid;
       }
       return this._toolbarEnabled || storedVal === "true";
     },
@@ -192,11 +192,10 @@ export default Ember.Controller.extend({
   @computed("model.canEditTitle", "model.creatingPrivateMessage")
   canEditTags(canEditTitle, creatingPrivateMessage) {
     return (
-      this.site.get("can_tag_topics") &&
+      this.site.can_tag_topics &&
       canEditTitle &&
       !creatingPrivateMessage &&
-      (!this.get("model.topic.isPrivateMessage") ||
-        this.site.get("can_tag_pms"))
+      (!this.get("model.topic.isPrivateMessage") || this.site.can_tag_pms)
     );
   },
 
@@ -216,31 +215,24 @@ export default Ember.Controller.extend({
   @computed("model.post")
   replyingToWhisper(repliedToPost) {
     return (
-      repliedToPost &&
-      repliedToPost.get("post_type") === this.site.post_types.whisper
+      repliedToPost && repliedToPost.post_type === this.site.post_types.whisper
     );
   },
 
-  @computed("replyingToWhisper", "model.whisper")
-  isWhispering(replyingToWhisper, whisper) {
-    return replyingToWhisper || whisper;
-  },
+  isWhispering: Ember.computed.or("replyingToWhisper", "model.whisper"),
 
   @computed("model.action", "isWhispering")
   saveIcon(action, isWhispering) {
-    if (isWhispering) {
-      return "far-eye-slash";
-    }
+    if (isWhispering) return "far-eye-slash";
+
     return SAVE_ICONS[action];
   },
 
   @computed("model.action", "isWhispering", "model.editConflict")
   saveLabel(action, isWhispering, editConflict) {
-    if (editConflict) {
-      return "composer.overwrite_edit";
-    } else if (isWhispering) {
-      return "composer.create_whisper";
-    }
+    if (editConflict) return "composer.overwrite_edit";
+    else if (isWhispering) return "composer.create_whisper";
+
     return SAVE_LABELS[action];
   },
 
@@ -270,7 +262,7 @@ export default Ember.Controller.extend({
   @computed("model.composeState", "model.creatingTopic", "model.post")
   popupMenuOptions(composeState) {
     if (composeState === "open" || composeState === "fullscreen") {
-      let options = [];
+      const options = [];
 
       options.push(
         this._setupPopupMenuOption(() => {
@@ -295,9 +287,9 @@ export default Ember.Controller.extend({
       );
 
       return options.concat(
-        _popupMenuOptionsCallbacks.map(callback => {
-          return this._setupPopupMenuOption(callback);
-        })
+        _popupMenuOptionsCallbacks.map(callback =>
+          this._setupPopupMenuOption(callback)
+        )
       );
     }
   },
@@ -307,7 +299,9 @@ export default Ember.Controller.extend({
     if (!Discourse.User.currentProp("staff")) {
       return false;
     }
-    var hasTargetGroups = this.get("model.hasTargetGroups");
+
+    const hasTargetGroups = this.get("model.hasTargetGroups");
+
     // We need exactly one user to issue a warning
     if (
       Ember.isEmpty(usernames) ||
@@ -316,12 +310,13 @@ export default Ember.Controller.extend({
     ) {
       return false;
     }
+
     return creatingPrivateMessage;
   },
 
-  @computed("model.topic")
-  draftTitle(topic) {
-    return emojiUnescape(escapeExpression(topic.get("title")));
+  @computed("model.topic.title")
+  draftTitle(topicTitle) {
+    return emojiUnescape(escapeExpression(topicTitle));
   },
 
   @computed
@@ -344,11 +339,11 @@ export default Ember.Controller.extend({
     openComposer(options, post, topic) {
       this.open(options).then(() => {
         let url;
-        if (post) url = post.get("url");
-        if (!post && topic) url = topic.get("url");
+        if (post) url = post.url;
+        if (!post && topic) url = topic.url;
 
         let topicTitle;
-        if (topic) topicTitle = topic.get("title");
+        if (topic) topicTitle = topic.title;
 
         if (!url || !topicTitle) return;
 
@@ -360,7 +355,7 @@ export default Ember.Controller.extend({
 
         const reply = this.get("model.reply");
         if (!reply || !reply.includes(continueDiscussion)) {
-          this.get("model").prependText(continueDiscussion, {
+          this.model.prependText(continueDiscussion, {
             new_line: true
           });
         }
@@ -381,7 +376,7 @@ export default Ember.Controller.extend({
 
     typed() {
       this.checkReplyLength();
-      this.get("model").typing();
+      this.model.typing();
     },
 
     cancelled() {
@@ -394,13 +389,14 @@ export default Ember.Controller.extend({
 
     afterRefresh($preview) {
       const topic = this.get("model.topic");
-      const linkLookup = this.get("linkLookup");
+      const linkLookup = this.linkLookup;
+
       if (!topic || !linkLookup) {
         return;
       }
 
       // Don't check if there's only one post
-      if (topic.get("posts_count") === 1) {
+      if (topic.posts_count === 1) {
         return;
       }
 
@@ -484,11 +480,13 @@ export default Ember.Controller.extend({
       if (this.get("model.editingPost")) {
         const replyToPostNumber = this.get("model.post.reply_to_post_number");
         if (replyToPostNumber) {
-          const replyPost = postStream
-            .get("posts")
-            .findBy("post_number", replyToPostNumber);
+          const replyPost = postStream.posts.findBy(
+            "post_number",
+            replyToPostNumber
+          );
+
           if (replyPost) {
-            postId = replyPost.get("id");
+            postId = replyPost.id;
           }
         }
       }
@@ -497,8 +495,8 @@ export default Ember.Controller.extend({
         this.set("model.loading", true);
         const composer = this;
 
-        return this.store.find("post", postId).then(function(post) {
-          const quote = Quote.build(post, post.get("raw"), {
+        return this.store.find("post", postId).then(post => {
+          const quote = Quote.build(post, post.raw, {
             raw: true,
             full: true
           });
@@ -521,12 +519,14 @@ export default Ember.Controller.extend({
     },
 
     hitEsc() {
-      if (Ember.$(".emoji-picker-modal.fadeIn").length === 1) {
+      if (
+        document.querySelectorAll(".emoji-picker-modal.fadeIn").length === 1
+      ) {
         this.appEvents.trigger("emoji-picker:close");
         return;
       }
 
-      if ((this.get("messageCount") || 0) > 0) {
+      if ((this.messageCount || 0) > 0) {
         this.appEvents.trigger("composer-messages:close");
         return;
       }
@@ -553,13 +553,13 @@ export default Ember.Controller.extend({
 
           if (group.max_mentions < group.user_count) {
             body = I18n.t("composer.group_mentioned_limit", {

[... diff too long, it was truncated ...]

GitHub sha: a85b7fee

1 Like