Bug 1592505 - Require prepareForSending to return a message. r=mkmelin a=jorgk
authorPatrick Cloke <clokep@gmail.com>
Wed, 06 Nov 2019 07:35:29 -0500
changeset 36389 9be1474307f448e3db3e564e6f3efb0a3b7957ef
parent 36388 162757dcb4cd49e973ce0282ec70adde85f22a84
child 36390 ccbcf47c5673534d79f39eeb5058145685f4c839
push id2523
push usermozilla@jorgk.com
push dateThu, 07 Nov 2019 13:59:32 +0000
treeherdercomm-beta@4c356f38873a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, jorgk
bugs1592505
Bug 1592505 - Require prepareForSending to return a message. r=mkmelin a=jorgk
chat/components/public/prplIConversation.idl
chat/components/src/imConversations.js
chat/components/src/test/test_conversations.js
chat/modules/jsProtoHelper.jsm
--- a/chat/components/public/prplIConversation.idl
+++ b/chat/components/public/prplIConversation.idl
@@ -46,17 +46,17 @@ interface prplIConversation: nsISupports
   /**
    * Send a message in the conversation
    */
   void sendMsg(in AUTF8String aMsg);
 
   /**
    * Preprocess messages before they are sent (eg. split long messages).
    *
-   * @returns the modified message or null if no changes are to be made.
+   * @returns the potentially modified message(s).
    */
   Array<AString> prepareForSending(in imIOutgoingMessage aMsg);
 
   /**
    * Postprocess messages before they are displayed (eg. escaping). The
    * implementation can set aMsg.displayMessage, otherwise the originalMessage
    * is used.
    */
--- a/chat/components/src/imConversations.js
+++ b/chat/components/src/imConversations.js
@@ -473,22 +473,16 @@ UIConversation.prototype = {
       return;
     }
 
     // Protocols have an opportunity here to preprocess messages before they are
     // sent (eg. split long messages). If a message is split here, the split
     // will be visible in the UI.
     let messages = this.target.prepareForSending(om);
 
-    // Protocols can return null if they don't need to make any changes.
-    // (nb. passing null with retval array results in an empty array)
-    if (!messages || !messages.length) {
-      messages = [om.message];
-    }
-
     for (let msg of messages) {
       // Add-ons (eg. OTR) have an opportunity to tweak or cancel the message
       // at this point.
       om = new OutgoingMessage(msg, this.target);
       this.notifyObservers(om, "sending-message");
       if (om.cancelled) {
         continue;
       }
--- a/chat/components/src/test/test_conversations.js
+++ b/chat/components/src/test/test_conversations.js
@@ -235,18 +235,18 @@ var test_prpl_message_prep = function() 
 
   let msg = "Hi!";
   let prefix = "test> ";
 
   let prepared = false;
   conv.prepareForSending = function(aMsg) {
     ok(aMsg.QueryInterface(Ci.imIOutgoingMessage), "Wrong message type.");
     equal(aMsg.message, msg, "Expected the original message.");
-    aMsg.message = prefix + aMsg.message;
     prepared = true;
+    return [prefix + aMsg.message];
   };
 
   conv.prepareForDisplaying = function(aMsg) {
     ok(aMsg.QueryInterface(Ci.imIMessage), "Wrong message type.");
     equal(aMsg.displayMessage, prefix + msg, "Expected the prefixed message.");
     aMsg.displayMessage = aMsg.displayMessage.slice(prefix.length);
   };
 
--- a/chat/modules/jsProtoHelper.jsm
+++ b/chat/modules/jsProtoHelper.jsm
@@ -655,17 +655,17 @@ var GenericConversationPrototype = {
       try {
         observer.observe(aSubject, aTopic, aData);
       } catch (e) {
         this.ERROR(e);
       }
     }
   },
 
-  prepareForSending: aOutgoingMessage => null,
+  prepareForSending: aOutgoingMessage => [aOutgoingMessage.message],
   prepareForDisplaying(aImMessage) {
     if (aImMessage.displayMessage !== aImMessage.message) {
       this.DEBUG(
         "Preparing:\n" +
           aImMessage.message +
           "\nDisplaying:\n" +
           aImMessage.displayMessage
       );