Bug 1172360 - Handle join MUC command without passing server domain in XMPP. r=aleth
authorAbdelrhman Ahmed <a.ahmed1026@gmail.com>
Fri, 26 Jun 2015 15:12:00 +0200
changeset 22814 59ae2306da5684907c1e72e1e1c5a14d2088702a
parent 22813 a88a7d21371a6ea937b76bedea68313b462900c4
child 22815 2050599157633c448481a7dd83255353384a02d1
push id1443
push usermbanner@mozilla.com
push dateMon, 10 Aug 2015 18:31:17 +0000
treeherdercomm-beta@8fe07d686c22 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaleth
bugs1172360
Bug 1172360 - Handle join MUC command without passing server domain in XMPP. r=aleth
chat/locales/en-US/xmpp.properties
chat/protocols/xmpp/xmpp-commands.jsm
chat/protocols/xmpp/xmpp.jsm
--- a/chat/locales/en-US/xmpp.properties
+++ b/chat/locales/en-US/xmpp.properties
@@ -126,11 +126,11 @@ gtalk.usernameHint=email address
 # LOCALIZATION NOTE (odnoklassniki.usernameHint):
 #  This is displayed inside the accountUsernameInfoWithDescription
 #  string defined in imAccounts.properties when the user is
 #  configuring a Odnoklassniki account.
 odnoklassniki.usernameHint=Profile ID
 
 # LOCALZIATION NOTE (command.*):
 #  These are the help messages for each command.
-command.join2=%S [&lt;room@server&gt;][/&lt;nick&gt;] [&lt;password&gt;]: Join a room, optionally providing a different nickname, or the room password.
+command.join3=%S [&lt;room&gt;[@&lt;server&gt;][/&lt;nick&gt;]] [&lt;password&gt;]: Join a room, optionally providing a different server, or nickname, or the room password.
 command.part2=%S [&lt;message&gt;]: Leave the current room with an optional message.
 command.topic=%S [&lt;new topic&gt;]: Set this room's topic.
--- a/chat/protocols/xmpp/xmpp-commands.jsm
+++ b/chat/protocols/xmpp/xmpp-commands.jsm
@@ -16,17 +16,17 @@ XPCOMUtils.defineLazyGetter(this, "_", f
 function getConv(aConv) aConv.wrappedJSObject;
 
 // Get account object.
 function getAccount(aConv) getConv(aConv)._account;
 
 var commands = [
   {
     name: "join",
-    get helpString() _("command.join2", "join"),
+    get helpString() _("command.join3", "join"),
     run: function(aMsg, aConv, aReturnedConv) {
       let account = getAccount(aConv);
       let params = aMsg.trim();
       let conv;
 
       if (!params) {
         conv = getConv(aConv);
         if (!conv.isChat)
--- a/chat/protocols/xmpp/xmpp.jsm
+++ b/chat/protocols/xmpp/xmpp.jsm
@@ -891,19 +891,27 @@ const XMPPAccountPrototype = {
     password: {get label() _("chatRoomField.password"), isPassword: true}
   },
   parseDefaultChatName: function(aDefaultChatName) {
     if (!aDefaultChatName)
       return {nick: this._jid.node};
 
     let params = aDefaultChatName.trim().split(/\s+/);
     let jid = this._parseJID(params[0]);
+
+    // We swap node and domain as domain is required for parseJID, but node and
+    // resource are optional. In MUC join command, Node is required as it
+    // represents a room, but domain and resource are optional as we get muc
+    // domain from service discovery.
+    if (!jid.node && jid.domain)
+      [jid.node, jid.domain] = [jid.domain, jid.node];
+
     let chatFields = {
       room: jid.node,
-      server: jid.domain,
+      server: jid.domain || this._mucService,
       nick: jid.resource || this._jid.node
     };
     if (params.length > 1)
       chatFields.password = params[1];
     return chatFields;
   },
   getChatRoomDefaultFieldValues: function(aDefaultChatName) {
     let rv = GenericAccountPrototype.getChatRoomDefaultFieldValues