FIX: Use unique pluginId for modifyClass

FIX: Use unique pluginId for modifyClass

diff --git a/assets/javascripts/discourse/initializers/decrypt-post-revision.js b/assets/javascripts/discourse/initializers/decrypt-post-revision.js
index 25e2eb4..9441eb3 100644
--- a/assets/javascripts/discourse/initializers/decrypt-post-revision.js
+++ b/assets/javascripts/discourse/initializers/decrypt-post-revision.js
@@ -20,7 +20,7 @@ export default {
 
     withPluginApi("0.11.3", (api) => {
       api.modifyClassStatic("model:post", {
-        pluginId: "discourse-encrypt",
+        pluginId: "decrypt-post-revisions",
 
         loadRevision() {
           return this._super(...arguments).then((result) => {
diff --git a/assets/javascripts/discourse/initializers/encrypt-composer.js b/assets/javascripts/discourse/initializers/encrypt-composer.js
index 756d7f7..3ba776c 100644
--- a/assets/javascripts/discourse/initializers/encrypt-composer.js
+++ b/assets/javascripts/discourse/initializers/encrypt-composer.js
@@ -36,7 +36,7 @@ export default {
     withPluginApi("0.11.3", (api) => {
       // Check recipients and show encryption status in composer.
       api.modifyClass("model:composer", {
-        pluginId: "discourse-encrypt",
+        pluginId: "encrypt-composer",
 
         @on("init")
         @observes("creatingPrivateMessage", "topic")
diff --git a/assets/javascripts/discourse/initializers/encrypt-delete-topic.js b/assets/javascripts/discourse/initializers/encrypt-delete-topic.js
new file mode 100644
index 0000000..e1f5b52
--- /dev/null
+++ b/assets/javascripts/discourse/initializers/encrypt-delete-topic.js
@@ -0,0 +1,141 @@
+import { ajax } from "discourse/lib/ajax";
+import { withPluginApi } from "discourse/lib/plugin-api";
+import Post from "discourse/models/post";
+import I18n from "I18n";
+
+export default {
+  name: "encrypt-delete-topic",
+
+  initialize() {
+    withPluginApi("0.11.3", (api) => {
+      api.modifyClass("controller:topic", {
+        pluginId: "encrypt-delete-topic",
+
+        permanentDeleteConfirmation(callback) {
+          bootbox.confirm(
+            I18n.t("encrypt.post.delete.confirm"),
+            I18n.t("encrypt.post.delete.no_value"),
+            I18n.t("encrypt.post.delete.yes_value"),
+            (result) => {
+              if (result) {
+                callback();
+              } else {
+                return;
+              }
+            }
+          );
+        },
+
+        createTimer(post_id) {
+          return ajax("/encrypt/encrypted_post_timers", {
+            type: "POST",
+            data: { post_id },
+          });
+        },
+
+        deleteTimer(post_id) {
+          return ajax("/encrypt/encrypted_post_timers", {
+            type: "DELETE",
+            data: { post_id },
+          });
+        },
+
+        deleteTopic() {
+          // TODO: https://github.com/emberjs/ember.js/issues/15291
+          let { _super } = this;
+          if (this.model.encrypted_title) {
+            this.permanentDeleteConfirmation(() => {
+              return this.createTimer(
+                this.model.postStream.posts[0].id
+              ).then(() => this.model.destroy(this.currentUser));
+            });
+          } else {
+            return _super.call(this, ...arguments);
+          }
+        },
+
+        actions: {
+          deletePost(post) {
+            // TODO: https://github.com/emberjs/ember.js/issues/15291
+            let { _super } = this;
+
+            if (post.encrypted_raw && post.get("post_number") !== 1) {
+              this.permanentDeleteConfirmation(() => {
+                return this.createTimer(post.id).then((result) => {
+                  post.setProperties({ delete_at: result.delete_at });
+                  return _super.call(this, ...arguments);
+                });
+              });
+            } else {
+              return _super.call(this, ...arguments);
+            }
+          },
+
+          deleteSelected() {
+            // TODO: https://github.com/emberjs/ember.js/issues/15291
+            let { _super } = this;
+
+            const user = this.currentUser;
+
+            if (this.selectedAllPosts) {
+              this.send("toggleMultiSelect");
+              return this.deleteTopic();
+            }
+
+            if (this.selectedPosts[0].encrypted_raw) {
+              this.permanentDeleteConfirmation(() => {
+                return this.createTimer(this.selectedPostIds).then((result) => {
+                  Post.deleteMany(this.selectedPostIds);
+                  this.get("model.postStream.posts").forEach((p) => {
+                    this.postSelected(p) &&
+                      p.setDeletedState(user) &&
+                      p.setProperties({
+                        delete_at: result.delete_at,
+                        deleted_at: new Date(),
+                        deleted_by: user,
+                      });
+                  });
+                  this.send("toggleMultiSelect");
+                });
+              });
+            } else {
+              return _super.call(this, ...arguments);
+            }
+          },
+
+          recoverTopic() {
+            // TODO: https://github.com/emberjs/ember.js/issues/15291
+            let { _super } = this;
+
+            if (this.model.encrypted_title) {
+              return this.deleteTimer(this.model.postStream.posts[0].id).then(
+                () => {
+                  this.model.postStream.posts[0].setProperties({
+                    delete_at: false,
+                  });
+                  return _super.call(this, ...arguments);
+                }
+              );
+            } else {
+              return _super.call(this, ...arguments);
+            }
+          },
+
+          recoverPost(post) {
+            // TODO: https://github.com/emberjs/ember.js/issues/15291
+            let { _super } = this;
+
+            if (post.encrypted_raw) {
+              return this.deleteTimer(post.id).then(() => {
+                post.setProperties({ delete_at: false });
+                return _super.call(this, ...arguments);
+              });
+            } else {
+              return _super.call(this, ...arguments);
+            }
+          },
+        },
+      });
+    });
+  },
+};
diff --git a/assets/javascripts/discourse/initializers/encrypt-drafts.js b/assets/javascripts/discourse/initializers/encrypt-drafts.js
index 2e04719..761ff15 100644
--- a/assets/javascripts/discourse/initializers/encrypt-drafts.js
+++ b/assets/javascripts/discourse/initializers/encrypt-drafts.js
@@ -55,7 +55,7 @@ export default {
 
     withPluginApi("0.11.3", (api) => {
       api.modifyClassStatic("model:draft", {
-        pluginId: "discourse-encrypt",
+        pluginId: "encrypt-drafts",
 
         save(draftKey, sequence, data, clientId) {
           // TODO: https://github.com/emberjs/ember.js/issues/15291
@@ -118,7 +118,7 @@ export default {
       });
 
       api.modifyClass("model:user-drafts-stream", {
-        pluginId: "discourse-encrypt",
+        pluginId: "encrypt-drafts",
 
         findItems(site) {
           return this._super(site).then(() => {
diff --git a/assets/javascripts/discourse/initializers/encrypt-posts.js b/assets/javascripts/discourse/initializers/encrypt-posts.js
index f0fbab7..4006708 100644
--- a/assets/javascripts/discourse/initializers/encrypt-posts.js
+++ b/assets/javascripts/discourse/initializers/encrypt-posts.js
@@ -62,7 +62,7 @@ export default {
 
     withPluginApi("0.11.3", (api) => {
       api.modifyClassStatic("model:topic", {
-        pluginId: "discourse-encrypt",
+        pluginId: "encrypt-posts",
 
         update(topic, props) {
           // TODO: https://github.com/emberjs/ember.js/issues/15291
@@ -82,7 +82,7 @@ export default {
       });
 
       api.modifyClass("adapter:post", {
-        pluginId: "discourse-encrypt",
+        pluginId: "encrypt-posts",
 
         createRecord(store, type, args) {
           // TODO: https://github.com/emberjs/ember.js/issues/15291

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

GitHub sha: a53765f4da3d6e9551953dd228de48dc6611defb

This commit appears in #137 which was approved by gschlager. It was merged by udan11.