DEV: Move from top-notices connector to addGlobalNotice API

DEV: Move from top-notices connector to addGlobalNotice API

diff --git a/assets/javascripts/discourse/connectors/top-notices/encrypt.hbs b/assets/javascripts/discourse/connectors/top-notices/encrypt.hbs
deleted file mode 100644
index 66f4b9a..0000000
--- a/assets/javascripts/discourse/connectors/top-notices/encrypt.hbs
+++ /dev/null
@@ -1,13 +0,0 @@
-{{#if showNoBackupWarning}}
-  <div class="row">
-    <div class="alert alert-warn">
-      <span>{{{i18n "encrypt.no_backup_warn" basePath=basePath}}}</span>
-      {{d-button
-        icon="times"
-        action=(action (mut noticeStatus) 'dismissed')
-        class="btn btn-flat close"
-        title="banner.close"
-      }}
-    </div>
-  </div>
-{{/if}}
diff --git a/assets/javascripts/discourse/connectors/top-notices/encrypt.js.es6 b/assets/javascripts/discourse/connectors/top-notices/encrypt.js.es6
deleted file mode 100644
index 108f883..0000000
--- a/assets/javascripts/discourse/connectors/top-notices/encrypt.js.es6
+++ /dev/null
@@ -1,69 +0,0 @@
-import { getOwner } from "discourse-common/lib/get-owner";
-import {
-  ENCRYPT_ACTIVE,
-  ENCRYPT_DISABLED,
-  getEncryptionStatus
-} from "discourse/plugins/discourse-encrypt/lib/discourse";
-
-const NO_BACKUP_WARN_NOTICE_KEY = "discourse-encrypt-no-backup-warn";
-
-export default {
-  setupComponent(args, component) {
-    const currentUser = getOwner(component).lookup("current-user:main");
-    const status = getEncryptionStatus(currentUser);
-
-    component.setProperties({
-      basePath: Discourse.BaseUri,
-      isEncryptEnabled: status !== ENCRYPT_DISABLED,
-      isEncryptActive: status === ENCRYPT_ACTIVE,
-      showNoBackupWarning: 15,
-
-      /** Listens for encryption status updates. */
-      listener() {
-        const newStatus = getEncryptionStatus(currentUser);
-        component.setProperties({
-          isEncryptEnabled: newStatus !== ENCRYPT_DISABLED,
-          isEncryptActive: newStatus === ENCRYPT_ACTIVE
-        });
-      },
-
-      didInsertElement() {
-        this._super(...arguments);
-        this.appEvents.on("encrypt:status-changed", this, this.listener);
-      },
-
-      willDestroyElement() {
-        this._super(...arguments);
-        this.appEvents.off("encrypt:status-changed", this, this.listener);
-      }
-    });
-
-    Ember.defineProperty(component, "noticeStatus", {
-      set(value) {
-        window.localStorage.setItem(NO_BACKUP_WARN_NOTICE_KEY, value);
-        return window.localStorage.getItem(NO_BACKUP_WARN_NOTICE_KEY);
-      },
-      get() {
-        return window.localStorage.getItem(NO_BACKUP_WARN_NOTICE_KEY);
-      }
-    });
-
-    Ember.defineProperty(
-      component,
-      "showNoBackupWarning",
-      Ember.computed(
-        "isEncryptActive",
-        "noticeStatus",
-        "currentUser.encrypt_private",
-        () => {
-          const ids = this.get("currentUser.encrypt_private");
-          return (
-            this.isEncryptActive &&
-            !this.noticeStatus &&
-            (!ids || Object.keys(JSON.parse(ids)).length === 0)
-          );
-        }
-      )
-    );
-  }
-};
diff --git a/assets/javascripts/discourse/initializers/update-state.js.es6 b/assets/javascripts/discourse/initializers/update-state.js.es6
index 2280d4d..d3869cf 100644
--- a/assets/javascripts/discourse/initializers/update-state.js.es6
+++ b/assets/javascripts/discourse/initializers/update-state.js.es6
@@ -1,3 +1,4 @@
+import { withPluginApi } from "discourse/lib/plugin-api";
 import { deleteDb } from "discourse/plugins/discourse-encrypt/lib/database";
 import {
   ENCRYPT_ACTIVE,
@@ -25,6 +26,25 @@ export default {
       deleteDb();
     }
 
+    if (
+      currentUser &&
+      status === ENCRYPT_ACTIVE &&
+      (!currentUser.encrypt_private ||
+        Object.keys(JSON.parse(currentUser.encrypt_private)).length === 0)
+    ) {
+      withPluginApi("0.8.37", api => {
+        api.addGlobalNotice(
+          I18n.t("encrypt.no_backup_warn", { basePath: Discourse.BaseUri }),
+          "key-backup-notice",
+          {
+            level: "warn",
+            dismissable: true,
+            dismissDuration: moment.duration(1, "day")
+          }
+        );
+      });
+    }
+
     if (messageBus && status !== ENCRYPT_DISABLED) {
       messageBus.subscribe("/plugin/encrypt/keys", function(data) {
         currentUser.setProperties({

GitHub sha: 1ca19d7b