DEV: Use more computed properties

DEV: Use more computed properties

diff --git a/assets/javascripts/discourse/connectors/composer-action-after/encrypt.hbs b/assets/javascripts/discourse/connectors/composer-action-after/encrypt.hbs
index 349866b..213e97a 100644
--- a/assets/javascripts/discourse/connectors/composer-action-after/encrypt.hbs
+++ b/assets/javascripts/discourse/connectors/composer-action-after/encrypt.hbs
@@ -1,7 +1,7 @@
 {{#if showEncryptControls}}
   <div class="encrypt-controls">
     {{#if isEncryptActive}}
-      <a href {{action clicked}} title={{title}} class="btn btn-default btn-icon no-text encrypt-toggle {{if model.isEncrypted "enabled"}} {{if disabled "disabled"}}">
+      <a href {{action "clicked"}} title={{title}} class="btn btn-default btn-icon no-text encrypt-toggle {{if model.isEncrypted "enabled"}} {{if disabled "disabled"}}">
         {{d-icon (if model.isEncrypted "lock" "unlock")}}
       </a>
 
diff --git a/assets/javascripts/discourse/connectors/composer-action-after/encrypt.js b/assets/javascripts/discourse/connectors/composer-action-after/encrypt.js
index 4b533e2..d8b1ada 100644
--- a/assets/javascripts/discourse/connectors/composer-action-after/encrypt.js
+++ b/assets/javascripts/discourse/connectors/composer-action-after/encrypt.js
@@ -9,19 +9,12 @@ import I18n from "I18n";
 export default {
   setupComponent(args, component) {
     const { currentUser } = component;
-    const status = getEncryptionStatus(currentUser);
 
     component.setProperties({
-      isEncryptEnabled: status !== ENCRYPT_DISABLED,
-      isEncryptActive: status === ENCRYPT_ACTIVE,
+      encryptStatus: getEncryptionStatus(currentUser),
 
-      /** Listens for encryption status updates. */
       listener() {
-        const newStatus = getEncryptionStatus(currentUser);
-        component.setProperties({
-          isEncryptEnabled: newStatus !== ENCRYPT_DISABLED,
-          isEncryptActive: newStatus === ENCRYPT_ACTIVE,
-        });
+        component.set("encryptStatus", getEncryptionStatus(currentUser));
       },
 
       didInsertElement() {
@@ -33,24 +26,25 @@ export default {
         this._super(...arguments);
         this.appEvents.off("encrypt:status-changed", this, this.listener);
       },
-
-      clicked() {
-        if (!this.disabled) {
-          this.model.setProperties({
-            isEncrypted: !this.model.isEncrypted,
-            isEncryptedChanged: true,
-            showEncryptError: !this.model.isEncrypted,
-            deleteAfterMinutes: null,
-            deleteAfterMinutesLabel: null,
-          });
-        } else {
-          this.model.set("showEncryptError", !this.model.showEncryptError);
-        }
-      },
     });
 
     defineProperty(
       component,
+      "isEncryptEnabled",
+      computed("encryptStatus", () => this.encryptStatus !== ENCRYPT_DISABLED)
+    );
+
+    defineProperty(
+      component,
+      "isEncryptActive",
+      computed("encryptStatus", () => this.encryptStatus === ENCRYPT_ACTIVE)
+    );
+
+    // Whether the encrypt controls should be displayed or not
+    //
+    // These are displayed only for new topics or already encrypted topics.
+    defineProperty(
+      component,
       "showEncryptControls",
       computed(
         "model.isNew",
@@ -118,6 +112,20 @@ export default {
   },
 
   actions: {
+    clicked() {
+      if (!this.disabled) {
+        this.model.setProperties({
+          isEncrypted: !this.model.isEncrypted,
+          isEncryptedChanged: true,
+          showEncryptError: !this.model.isEncrypted,
+          deleteAfterMinutes: null,
+          deleteAfterMinutesLabel: null,
+        });
+      } else {
+        this.model.set("showEncryptError", !this.model.showEncryptError);
+      }
+    },
+
     timerClicked(actionId, { name }) {
       if (actionId) {
         this.model.setProperties({
diff --git a/assets/javascripts/discourse/connectors/user-preferences-security/encrypt.hbs b/assets/javascripts/discourse/connectors/user-preferences-security/encrypt.hbs
index 0908674..d6403f9 100644
--- a/assets/javascripts/discourse/connectors/user-preferences-security/encrypt.hbs
+++ b/assets/javascripts/discourse/connectors/user-preferences-security/encrypt.hbs
@@ -1,7 +1,7 @@
 {{#if canEnableEncrypt}}
   <div class="control-group pref-title">
     <label class="control-label">{{i18n "encrypt.title"}}</label>
-    {{#if isIE11}}
+    {{#if capabilities.isIE11}}
       <div class="alert alert-error">
         <p>{{i18n "encrypt.preferences.ie11"}}</p>
       </div>
diff --git a/assets/javascripts/discourse/connectors/user-preferences-security/encrypt.js b/assets/javascripts/discourse/connectors/user-preferences-security/encrypt.js
index 7eb96fd..143f3fe 100644
--- a/assets/javascripts/discourse/connectors/user-preferences-security/encrypt.js
+++ b/assets/javascripts/discourse/connectors/user-preferences-security/encrypt.js
@@ -1,3 +1,4 @@
+import { computed, defineProperty } from "@ember/object";
 import showModal from "discourse/lib/show-modal";
 import {
   deleteDb,
@@ -19,59 +20,77 @@ import I18n from "I18n";
 
 export default {
   setupComponent(args, component) {
-    const { currentUser } = component;
-    const isCurrentUser = args.model.id === currentUser.id;
-
-    component.setProperties({
-      /** crypto.subtle is only available in secure contexts. */
-      isInsecureContext: !window.isSecureContext,
-      /** Not all algorithms are available in IE11. */
-      isIE11: this.capabilities.isIE11,
-      /** Whether current user is the same as model user. */
-      isCurrentUser,
-      /** Whether plugin is enabled for current user. */
-      canEnableEncrypt: args.model.can_encrypt,
-      /** Whether the encryption is enabled or not. */
-      isEncryptEnabled: !!args.model.encrypt_public,
-    });
-
-    if (isCurrentUser) {
-      const status = getEncryptionStatus(args.model);
+    component.set("isInsecureContext", !window.isSecureContext);
+
+    // Whether plugin is enabled for current user
+    defineProperty(
+      component,
+      "canEnableEncrypt",
+      computed("model.can_encrypt", () => this.model.can_encrypt)
+    );
+
+    // Only current user can enable encryption for themselves
+    defineProperty(
+      component,
+      "isCurrentUser",
+      computed(
+        "currentUser.id",
+        "model.id",
+        () => this.currentUser.id === this.model.id
+      )
+    );
+
+    if (component.isCurrentUser) {
       component.setProperties({
-        /** Value of passphrase input.
-         *  It should stay in memory for as little time as possible.
-         *  Clear it often.
-         */
+        encryptStatus: getEncryptionStatus(args.model),
+
+        /** Value of passphrase input. */
         passphrase: "",
+
         /** Whether it is an import operation. */
         importIdentity: false,
+
         /** Key to be imported .*/
         identity: "",
         identityPlaceholder: getPackedPlaceholder(),
-        /** Whether any operation (AJAX request, key generation, etc.) is
-         *  in progress. */
+
+        /** Whether any operation (AJAX request, key generation, etc) is
+         *  in progress.
+         */
         inProgress: false,
-        /** Whether the encryption is enabled or not. */
-        isEncryptEnabled: status !== ENCRYPT_DISABLED,
-        /** Whether the encryption is active on this device. */
-        isEncryptActive: status === ENCRYPT_ACTIVE,
-        /** Listens for encryption status updates. */
+
         listener() {
-          const newStatus = getEncryptionStatus(args.model);
-          component.setProperties({
-            isEncryptEnabled: newStatus !== ENCRYPT_DISABLED,
-            isEncryptActive: newStatus === ENCRYPT_ACTIVE,
-          });
+          component.set("encryptStatus", getEncryptionStatus(args.model));
         },
+
         didInsertElement() {
           this._super(...arguments);
           this.appEvents.on("encrypt:status-changed", this, this.listener);
         },
+
         willDestroyElement() {

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

GitHub sha: ed395ad412d4851b11104e3f29c74dee4b7b177f

This commit appears in #134 which was approved by eviltrout. It was merged by udan11.