DEV: Prefer modifyClass and modifyClassStatic

DEV: Prefer modifyClass and modifyClassStatic

The plugin used to call reopen and reopenClass directly on the modified class.

diff --git a/assets/javascripts/discourse/initializers/decrypt-post-revision.js b/assets/javascripts/discourse/initializers/decrypt-post-revision.js
index 6971336..25e2eb4 100644
--- a/assets/javascripts/discourse/initializers/decrypt-post-revision.js
+++ b/assets/javascripts/discourse/initializers/decrypt-post-revision.js
@@ -1,5 +1,5 @@
+import { withPluginApi } from "discourse/lib/plugin-api";
 import { cookAsync } from "discourse/lib/text";
-import Post from "discourse/models/post";
 import {
   ENCRYPT_ACTIVE,
   getEncryptionStatus,
@@ -18,41 +18,45 @@ export default {
       return;
     }
 
-    Post.reopenClass({
-      loadRevision() {
-        return this._super(...arguments).then((result) => {
-          if (!hasTopicKey(result.topic_id)) {
-            return result;
-          }
+    withPluginApi("0.11.3", (api) => {
+      api.modifyClassStatic("model:post", {
+        pluginId: "discourse-encrypt",
 
-          const topicKey = getTopicKey(result.topic_id);
-          return Promise.all([
-            topicKey.then((k) => decrypt(k, result.raws.previous)),
-            topicKey.then((k) => decrypt(k, result.raws.current)),
-          ])
-            .then(([previous, current]) =>
-              Promise.all([
-                previous.raw,
-                cookAsync(previous.raw),
-                current.raw,
-                cookAsync(current.raw),
-              ])
-            )
-            .then(([prevRaw, prevCooked, currRaw, currCooked]) => {
-              result.body_changes.side_by_side = `
+        loadRevision() {
+          return this._super(...arguments).then((result) => {
+            if (!hasTopicKey(result.topic_id)) {
+              return result;
+            }
+
+            const topicKey = getTopicKey(result.topic_id);
+            return Promise.all([
+              topicKey.then((k) => decrypt(k, result.raws.previous)),
+              topicKey.then((k) => decrypt(k, result.raws.current)),
+            ])
+              .then(([previous, current]) =>
+                Promise.all([
+                  previous.raw,
+                  cookAsync(previous.raw),
+                  current.raw,
+                  cookAsync(current.raw),
+                ])
+              )
+              .then(([prevRaw, prevCooked, currRaw, currCooked]) => {
+                result.body_changes.side_by_side = `
                 <div class="revision-content">${prevCooked}</div>
                 <div class="revision-content">${currCooked}</div>`;
-              result.body_changes.side_by_side_markdown = `
+                result.body_changes.side_by_side_markdown = `
                 <table class="markdown">
                   <tr>
                     <td class="diff-del">${prevRaw}</td>
                     <td class="diff-ins">${currRaw}</td>
                   </tr>
                 </table>`;
-              return result;
-            });
-        });
-      },
+                return result;
+              });
+          });
+        },
+      });
     });
   },
 };
diff --git a/assets/javascripts/discourse/initializers/decrypt-posts.js b/assets/javascripts/discourse/initializers/decrypt-posts.js
index 40854db..b5a4594 100644
--- a/assets/javascripts/discourse/initializers/decrypt-posts.js
+++ b/assets/javascripts/discourse/initializers/decrypt-posts.js
@@ -268,7 +268,7 @@ export default {
       return;
     }
 
-    withPluginApi("0.8.25", (api) => {
+    withPluginApi("0.11.3", (api) => {
       const verified = {};
 
       api.includePostAttributes("encrypted_raw");
diff --git a/assets/javascripts/discourse/initializers/decrypt-topics.js b/assets/javascripts/discourse/initializers/decrypt-topics.js
index d9f84bd..dcc46e8 100644
--- a/assets/javascripts/discourse/initializers/decrypt-topics.js
+++ b/assets/javascripts/discourse/initializers/decrypt-topics.js
@@ -92,6 +92,7 @@ export default {
 
     // Try to decrypt new titles that may appear after rendering a component.
     const self = this;
+
     Component.reopen({
       didRender() {
         scheduleOnce("afterRender", self, () => {
@@ -101,7 +102,7 @@ export default {
       },
     });
 
-    withPluginApi("0.8.31", (api) => {
+    withPluginApi("0.11.3", (api) => {
       // All quick-access panels
       api.reopenWidget("quick-access-panel", {
         setItems() {
@@ -154,7 +155,7 @@ export default {
       });
     });
 
-    withPluginApi("0.8.31", (api) => {
+    withPluginApi("0.11.3", (api) => {
       api.decorateWidget("header:after", (helper) => {
         if (
           helper.widget.state.userVisible ||
diff --git a/assets/javascripts/discourse/initializers/encrypt-composer.js b/assets/javascripts/discourse/initializers/encrypt-composer.js
index 4e24fb1..756d7f7 100644
--- a/assets/javascripts/discourse/initializers/encrypt-composer.js
+++ b/assets/javascripts/discourse/initializers/encrypt-composer.js
@@ -1,8 +1,8 @@
-import I18n from "I18n";
 import discourseComputed, {
   observes,
   on,
 } from "discourse-common/utils/decorators";
+import { withPluginApi } from "discourse/lib/plugin-api";
 import Composer from "discourse/models/composer";
 import {
   ENCRYPT_ACTIVE,
@@ -17,6 +17,7 @@ import {
   decrypt,
   importKey,
 } from "discourse/plugins/discourse-encrypt/lib/protocol";
+import I18n from "I18n";
 import { Promise } from "rsvp";
 
 export default {
@@ -32,131 +33,135 @@ export default {
     Composer.serializeOnCreate("is_encrypted", "isEncrypted");
     Composer.serializeOnCreate("delete_after_minutes", "deleteAfterMinutes");
 
-    // Check recipients and show encryption status in composer.
-    Composer.reopen({
-      @on("init")
-      @observes("creatingPrivateMessage", "topic")
-      updateEncryptProperties() {
-        let isEncrypted = this.isEncrypted;
-
-        if (
-          this.topic &&
-          this.topic.encrypted_title &&
-          hasTopicKey(this.topic.id)
-        ) {
-          // Force encryption for existing encrypted topics.
-          isEncrypted = true;
-        } else if (this.isNew && this.creatingPrivateMessage) {
-          // `isEncryptedChanged` is set true only when the value of
-          // `isEncrypted` is changed. This is needed because during save
-          // (serialization), this method is called and `isEncrypted` is
-          // reset.
-          if (!this.isEncryptedChanged) {
-            isEncrypted = this.siteSettings.encrypt_pms_default;
+    withPluginApi("0.11.3", (api) => {
+      // Check recipients and show encryption status in composer.
+      api.modifyClass("model:composer", {
+        pluginId: "discourse-encrypt",
+
+        @on("init")
+        @observes("creatingPrivateMessage", "topic")
+        updateEncryptProperties() {
+          let isEncrypted = this.isEncrypted;
+
+          if (
+            this.topic &&
+            this.topic.encrypted_title &&
+            hasTopicKey(this.topic.id)
+          ) {
+            // Force encryption for existing encrypted topics.
+            isEncrypted = true;
+          } else if (this.isNew && this.creatingPrivateMessage) {
+            // `isEncryptedChanged` is set true only when the value of
+            // `isEncrypted` is changed. This is needed because during save
+            // (serialization), this method is called and `isEncrypted` is
+            // reset.
+            if (!this.isEncryptedChanged) {
+              isEncrypted = this.siteSettings.encrypt_pms_default;
+            }
           }
-        }
-
-        this.setProperties({
-          /** @var Whether the current message is going to be encrypted. */
-          isEncrypted,
-
-          /** @var Whether current error is shown or not. In most cases, it
-           *       is equal to `isEncrypted` except when `isEncrypted` is
-           *       forcibly set to false (i.e. when an error occurs).
-           */
-          showEncryptError: isEncrypted,
-        });
-      },
-
-      @observes("targetRecipients")
-      checkEncryptRecipients() {

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

GitHub sha: 517c27808ad9cd72dd35f37d9b726e83b32da2a8

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