DEV: Expose `Composer.serializeOnUpdate` in client side plugin api.

DEV: Expose Composer.serializeOnUpdate in client side plugin api.

Also expose Composer.serializeOnCreate as well.

diff --git a/app/assets/javascripts/discourse/app/lib/plugin-api.js b/app/assets/javascripts/discourse/app/lib/plugin-api.js
index a10e183..4b6356c 100644
--- a/app/assets/javascripts/discourse/app/lib/plugin-api.js
+++ b/app/assets/javascripts/discourse/app/lib/plugin-api.js
@@ -55,7 +55,7 @@ import { on } from "@ember/object/evented";
 import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";
 
 // If you add any methods to the API ensure you bump up this number
-const PLUGIN_API_VERSION = "0.8.43";
+const PLUGIN_API_VERSION = "0.9.0";
 
 class PluginApi {
   constructor(version, container) {
@@ -957,6 +957,36 @@ class PluginApi {
   }
 
   /**
+   * Adds a field to composer create serializer
+   *
+   * Example:
+   *
+   * api.serializeOnCreate('key_set_in_model', 'field_name_in_payload');
+   *
+   * to keep both of them same
+   * api.serializeOnCreate('field_name');
+   *
+   */
+  serializeOnCreate(fieldName, property) {
+    Composer.serializeOnCreate(fieldName, property);
+  }
+
+  /**
+   * Adds a field to composer update serializer
+   *
+   * Example:
+   *
+   * api.serializeOnUpdate('key_set_in_model', 'field_name_in_payload');
+   *
+   * to keep both of them same
+   * api.serializeOnUpdate('field_name');
+   *
+   */
+  serializeOnUpdate(fieldName, property) {
+    Composer.serializeOnUpdate(fieldName, property);
+  }
+
+  /**
    * Registers a criteria that can be used as default topic order on category
    * pages.
    *
diff --git a/app/assets/javascripts/discourse/app/models/composer.js b/app/assets/javascripts/discourse/app/models/composer.js
index a17461a..98ccdfa 100644
--- a/app/assets/javascripts/discourse/app/models/composer.js
+++ b/app/assets/javascripts/discourse/app/models/composer.js
@@ -61,6 +61,11 @@ const CLOSED = "closed",
     no_bump: "noBump",
     draft_key: "draftKey"
   },
+  _update_serializer = {
+    raw: "reply",
+    topic_id: "topic.id",
+    raw_old: "rawOld"
+  },
   _edit_topic_serializer = {
     title: "topic.title",
     categoryId: "topic.category.id",
@@ -851,6 +856,11 @@ const Composer = RestModel.extend({
     });
   },
 
+  @discourseComputed("editConflict", "originalText")
+  rawOld(editConflict, originalText) {
+    return editConflict ? null : originalText;
+  },
+
   editPost(opts) {
     const post = this.post;
     const oldCooked = post.cooked;
@@ -885,14 +895,12 @@ const Composer = RestModel.extend({
     }
 
     const props = {
-      topic_id: this.topic.id,
-      raw: this.reply,
-      raw_old: this.editConflict ? null : this.originalText,
       edit_reason: opts.editReason,
       image_sizes: opts.imageSizes,
       cooked: this.getCookedHtml()
     };
 
+    this.serialize(_update_serializer, props);
     this.set("composeState", SAVING);
 
     const rollback = throwAjaxError(error => {
@@ -1225,6 +1233,17 @@ Composer.reopenClass({
     return Object.keys(_create_serializer);
   },
 
+  serializeOnUpdate(fieldName, property) {
+    if (!property) {
+      property = fieldName;
+    }
+    _update_serializer[fieldName] = property;
+  },
+
+  serializedFieldsForUpdate() {
+    return Object.keys(_update_serializer);
+  },
+
   serializeToDraft(fieldName, property) {
     if (!property) {
       property = fieldName;

GitHub sha: a1a798ac