FIX: Use modifyClass API instead of calling reopen (#18)

FIX: Use modifyClass API instead of calling reopen (#18)

This is the recommended way of modifying classes and can help plugins interact with each other in a more predictable way.

diff --git a/assets/javascripts/discourse/initializers/setup-bcc.js.es6 b/assets/javascripts/discourse/initializers/setup-bcc.js.es6
index 2244b6c..4f1e73f 100644
--- a/assets/javascripts/discourse/initializers/setup-bcc.js.es6
+++ b/assets/javascripts/discourse/initializers/setup-bcc.js.es6
@@ -1,5 +1,6 @@
 import { ajax } from "discourse/lib/ajax";
 import { Result } from "discourse/adapters/rest";
+import { withPluginApi } from "discourse/lib/plugin-api";
 
 export default {
   name: "setup-bcc",
@@ -12,21 +13,24 @@ export default {
       composer.class.serializeToDraft("use_bcc");
     }
 
-    let adapter = container.lookup("adapter:post");
-    adapter.reopen({
-      createRecord(store, type, args) {
-        if (type === "post" && args.use_bcc) {
-          return ajax("/posts/bcc", {
-            method: "POST",
-            data: args
-          }).then(json => {
-            return new Result(json.post, json);
-          });
-        } else {
-          delete args.use_bcc;
-          return this._super(store, type, args);
-        }
-      }
+    withPluginApi("0.8.10", (api) => {
+      api.modifyClass("adapter:post", {
+        pluginId: "discourse-bcc",
+
+        createRecord(store, type, args) {
+          if (type === "post" && args.use_bcc) {
+            return ajax("/posts/bcc", {
+              method: "POST",
+              data: args,
+            }).then((json) => {
+              return new Result(json.post, json);
+            });
+          } else {
+            delete args.use_bcc;
+            return this._super(store, type, args);
+          }
+        },
+      });
     });
-  }
+  },
 };

GitHub sha: 3c1b849bfa9b76a9c8ad7ceb76318fdb17a7052b

This commit appears in #18 which was approved by CvX. It was merged by udan11.