Bug 1646049 - Fix display of own messages in private IRC chats when echo-message is enabled. r=mkmelin a=wsmwk
authorPatrick Cloke <clokep@gmail.com>
Thu, 25 Jun 2020 16:04:41 -0400
changeset 39470 9de7a3e59b412aaf2e054d7e499bb55dded0602d
parent 39469 2be1591aed0a2585ced46f5efe4ab3cd382f1f87
child 39471 933171d8b30a2967e590763818a80900b13d9d6d
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewersmkmelin, wsmwk
bugs1646049
Bug 1646049 - Fix display of own messages in private IRC chats when echo-message is enabled. r=mkmelin a=wsmwk
chat/protocols/irc/ircBase.jsm
--- a/chat/protocols/irc/ircBase.jsm
+++ b/chat/protocols/irc/ircBase.jsm
@@ -28,36 +28,44 @@ var {
   _,
   ctcpFormatToText,
   conversationErrorMessage,
   kListRefreshInterval,
 } = ChromeUtils.import("resource:///modules/ircUtils.jsm");
 
 function privmsg(aAccount, aMessage, aIsNotification) {
   let params = { tags: aMessage.tags };
-  // If the echo-message capability is enabled and the message is from our nick,
-  // mark it as outgoing. Otherwise, the message is incoming.
+  // If the the message is from our nick, it is outgoing to the conversation it
+  // is targeting. Otherwise, the message is incoming, but could be for a
+  // private message or a channel.
+  //
+  // Note that the only time it is expected to receive a message from us is if
+  // the echo-message capability is enabled.
+  let convName;
   if (
-    aAccount._activeCAPs.has("echo-message") &&
     aAccount.normalizeNick(aMessage.origin) ==
-      aAccount.normalizeNick(aAccount._nickname)
+    aAccount.normalizeNick(aAccount._nickname)
   ) {
     params.outgoing = true;
+    // The conversation name is who it is being sent to.
+    convName = aMessage.params[0];
   } else {
     params.incoming = true;
+    // If the target is a MUC name, use the target as the conversation name.
+    // Otherwise, this is a private message: use the sender as the conversation
+    // name.
+    convName = aAccount.isMUCName(aMessage.params[0])
+      ? aMessage.params[0]
+      : aMessage.origin;
   }
   if (aIsNotification) {
     params.notification = true;
   }
   aAccount
-    .getConversation(
-      aAccount.isMUCName(aMessage.params[0])
-        ? aMessage.params[0]
-        : aMessage.origin
-    )
+    .getConversation(convName)
     .writeMessage(aMessage.origin, aMessage.params[1], params);
   return true;
 }
 
 // Display the message and remove them from the rooms they're in.
 function leftRoom(aAccount, aNicks, aChannels, aSource, aReason, aKicked) {
   let msgId = "message." + (aKicked ? "kicked" : "parted");
   // If a part message was included, include it.