Bug 1149275 - Ensure newly opened conversations get focused. r=clokep
authoraleth <aleth@instantbird.org>
Thu, 02 Apr 2015 19:46:06 +0200
changeset 22389 1cc7a71a04355c949421c3789386c48af37f5f3b
parent 22388 76d3068017576925b331610a016ad39b85a2c147
child 22390 f2e7cea9bc6aca3140fb49512d4cc16f85988540
push id1420
push usermbanner@mozilla.com
push dateMon, 29 Jun 2015 20:47:24 +0000
treeherdercomm-beta@b3db00bb24e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersclokep
bugs1149275
Bug 1149275 - Ensure newly opened conversations get focused. r=clokep
mail/components/im/content/chat-messenger-overlay.js
mail/components/im/content/imconversation.xml
--- a/mail/components/im/content/chat-messenger-overlay.js
+++ b/mail/components/im/content/chat-messenger-overlay.js
@@ -688,36 +688,41 @@ var chatHandler = {
     // Open a private conversation only for a middle or double click.
     if (aEvent.button != 1 && (aEvent.button != 0 || aEvent.detail != 2))
       return;
 
     let conv = document.getElementById("contactlistbox").selectedItem.conv;
     let nick = aEvent.originalTarget.chatBuddy.name;
     let name = conv.target.getNormalizedChatBuddyName(nick);
     try {
-      conv.account.createConversation(name);
+      let newconv = conv.account.createConversation(name);
+      this.focusConversation(newconv);
     } catch (e) {}
   },
 
   onNicklistKeyPress: function(aEvent) {
     if (aEvent.keyCode != aEvent.DOM_VK_RETURN)
       return;
 
     let listbox = aEvent.originalTarget;
     if (listbox.selectedCount == 0)
       return;
 
     let conv = document.getElementById("contactlistbox").selectedItem.conv;
+    let newconv;
     for (let i = 0; i < listbox.selectedCount; ++i) {
       let nick = listbox.getSelectedItem(i).chatBuddy.name;
       let name = conv.target.getNormalizedChatBuddyName(nick);
       try {
-        conv.account.createConversation(name);
+        newconv = conv.account.createConversation(name);
       } catch (e) {}
     }
+    // Only focus last of the opened conversations.
+    if (newconv)
+      this.focusConversation(newconv);
   },
 
   _openDialog: function(aType) {
     let features = "chrome,modal,titlebar,centerscreen";
     window.openDialog("chrome://messenger/content/chat/" + aType + ".xul", "",
                       features);
   },
   addBuddy: function() {
--- a/mail/components/im/content/imconversation.xml
+++ b/mail/components/im/content/imconversation.xml
@@ -231,47 +231,53 @@
 
      <method name="sendMsg">
       <parameter name="aMsg"/>
       <body>
       <![CDATA[
         if (!aMsg)
           return;
 
+        let account = this._conv.account;
+
         if (aMsg.startsWith("/")) {
+          let convToFocus = {};
+
           // The /say command is used to bypass command processing
           // (/say can be shortened to just /).
           // "/say" or "/say " should be ignored, as should "/" and "/ ".
           if (aMsg.match(/^\/(?:say)? ?$/)) {
             this.resetInput();
             return;
           }
           else if (aMsg.match(/^\/(?:say)? .*/))
             aMsg = aMsg.slice(aMsg.indexOf(" ") + 1);
-          else if (Services.cmd.executeCommand(aMsg, this._conv.target)) {
+          else if (Services.cmd.executeCommand(aMsg, this._conv.target,
+                                               convToFocus)) {
             this._conv.sendTyping("");
             this.resetInput();
+            if (convToFocus.value)
+              chatHandler.focusConversation(convToFocus.value);
             return;
           }
-          else if (this._conv.account.protocol.slashCommandsNative) {
+          else if (account.protocol.slashCommandsNative && account.connected) {
             let cmd = aMsg.match(/^\/[^ ]+/);
             if (cmd && cmd != "/me") {
               this._conv.systemMessage(
                 this.bundle.formatStringFromName("unknownCommand", [cmd], 1),
                 true);
               return;
             }
           }
         }
 
         let msg = Components.classes["@mozilla.org/txttohtmlconv;1"]
                             .getService(Ci.mozITXTToHTMLConv)
                             .scanTXT(aMsg, 0);
 
-        var account = this._conv.account;
         if (account.HTMLEnabled) {
           msg = msg.replace(/\n/g, "<br/>");
           if (Services.prefs.getBoolPref("messenger.conversations.sendFormat")) {
             let style = MessageFormat.getMessageStyle();
             let proto = this._conv.account.protocol.id;
             if (proto == "prpl-msn") {
               if ("color" in style)
                 msg = "<font color=\"" + style.color + "\">" + msg + "</font>";