DEV: Reload page on encrypt:status-changed

DEV: Reload page on encrypt:status-changed

diff --git a/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6 b/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6
index 56d3001..d68d3ad 100644
--- a/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6
+++ b/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6
@@ -10,8 +10,7 @@ import {
   canEnableEncrypt,
   ENCRYPT_ACTIVE,
   ENCRYPT_DISABLED,
-  getEncryptionStatus,
-  reload
+  getEncryptionStatus
 } from "discourse/plugins/discourse-encrypt/lib/discourse";
 import { unpackIdentity } from "discourse/plugins/discourse-encrypt/lib/pack";
 import {
@@ -112,7 +111,6 @@ export default {
       return Promise.all([saveIdentityPromise, saveDbIdentityPromise]).then(
         () => {
           this.appEvents.trigger("encrypt:status-changed");
-          reload();
         }
       );
     },
@@ -129,7 +127,6 @@ export default {
       return identityPromise
         .then(() => {
           this.appEvents.trigger("encrypt:status-changed");
-          reload();
         })
         .catch(() =>
           bootbox.alert(I18n.t("encrypt.preferences.passphrase_invalid"))
@@ -150,7 +147,6 @@ export default {
       deleteDb()
         .then(() => {
           this.appEvents.trigger("encrypt:status-changed");
-          reload();
         })
         .finally(() => this.set("inProgress", false));
     },
diff --git a/assets/javascripts/discourse/controllers/activate-encrypt.js.es6 b/assets/javascripts/discourse/controllers/activate-encrypt.js.es6
index 289c2e9..0c7457e 100644
--- a/assets/javascripts/discourse/controllers/activate-encrypt.js.es6
+++ b/assets/javascripts/discourse/controllers/activate-encrypt.js.es6
@@ -1,4 +1,3 @@
-import { reload } from "discourse/plugins/discourse-encrypt/lib/discourse";
 import ModalFunctionality from "discourse/mixins/modal-functionality";
 import { activateEncrypt } from "discourse/plugins/discourse-encrypt/lib/discourse";
 
@@ -41,7 +40,6 @@ export default Ember.Controller.extend(ModalFunctionality, {
           });
           this.set("models", null);
           this.send("closeModal");
-          reload();
         })
         .catch(() =>
           this.set("error", I18n.t("encrypt.preferences.passphrase_invalid"))
diff --git a/assets/javascripts/discourse/initializers/update-state.js.es6 b/assets/javascripts/discourse/initializers/update-state.js.es6
index 6a66853..2280d4d 100644
--- a/assets/javascripts/discourse/initializers/update-state.js.es6
+++ b/assets/javascripts/discourse/initializers/update-state.js.es6
@@ -2,7 +2,8 @@ import { deleteDb } from "discourse/plugins/discourse-encrypt/lib/database";
 import {
   ENCRYPT_ACTIVE,
   ENCRYPT_DISABLED,
-  getEncryptionStatus
+  getEncryptionStatus,
+  reload
 } from "discourse/plugins/discourse-encrypt/lib/discourse";
 
 export default {
@@ -12,16 +13,25 @@ export default {
     const currentUser = container.lookup("current-user:main");
     const messageBus = container.lookup("message-bus:main");
 
-    const status = getEncryptionStatus(currentUser);
+    const appEvents = container.lookup("service:app-events");
+    appEvents.on("encrypt:status-changed", skipReload => {
+      if (!skipReload) {
+        reload();
+      }
+    });
 
+    const status = getEncryptionStatus(currentUser);
     if (!currentUser || status !== ENCRYPT_ACTIVE) {
       deleteDb();
     }
 
     if (messageBus && status !== ENCRYPT_DISABLED) {
       messageBus.subscribe("/plugin/encrypt/keys", function(data) {
-        currentUser.set("encrypt_public", data.public);
-        currentUser.set("encrypt_private", data.private);
+        currentUser.setProperties({
+          encrypt_public: data.public,
+          encrypt_private: data.private
+        });
+        appEvents.trigger("encrypt:status-changed", true);
       });
     }
   }
diff --git a/test/javascripts/acceptance/encrypt-test.js.es6 b/test/javascripts/acceptance/encrypt-test.js.es6
index f033b41..2c44bd7 100644
--- a/test/javascripts/acceptance/encrypt-test.js.es6
+++ b/test/javascripts/acceptance/encrypt-test.js.es6
@@ -443,7 +443,7 @@ test("topic titles in notification panel are decrypted", async assert => {
   // In test environments, because `Ember.run.debounce` is aliased to `Ember.run`.
   await window.Discourse.__container__
     .lookup("service:app-events")
-    .trigger("encrypt:status-changed");
+    .trigger("encrypt:status-changed", true);
 
   assert.equal(
     find(".quick-access-panel span[data-topic-id]").text(),

GitHub sha: 3c7677e4