about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-04-10 22:47:01 +0100
committerJames Booth <boothj5@gmail.com>2013-04-10 22:47:01 +0100
commit202bc6b427c05f2ec06ef984848f05bfea78b42d (patch)
tree2e6ee3a1b8d2f530b6c7fc4200e96b776bb536ae
parentf4041f049ce4f66ad6fa9ef167e0a095b35d9f60 (diff)
downloadprofani-tty-202bc6b427c05f2ec06ef984848f05bfea78b42d.tar.gz
Guess conference server if not supplied when joining room (/join)
"@conference.<domain-part>" will be appended to the /join argument where
<domain-part> is the domainpart of the users jid. E.g. the user
"user@server.org" typing "/join chatroom" is equivalent to "/join
chatroom@conference.server.org"
-rw-r--r--src/command/command.c38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 58b241f1..d3279a01 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -324,16 +324,18 @@ static struct cmd_t main_commands[] =
 
     { "/join",
         _cmd_join, parse_args_with_freetext, 1, 2,
-        { "/join room [nick]", "Join a chat room.",
-        { "/join room [nick]",
-          "-----------------",
+        { "/join room[@server] [nick]", "Join a chat room.",
+        { "/join room[@server] [nick]",
+          "--------------------------",
           "Join a chat room at the conference server.",
           "If nick is specified you will join with this nickname.",
           "Otherwise the 'localpart' of your JID (before the @) will be used.",
+          "If no server is supplied, it will default to 'conference.<domain-part>'",
           "If the room doesn't exist, and the server allows it, a new one will be created.",
           "",
           "Example : /join jdev@conference.jabber.org",
           "Example : /join jdev@conference.jabber.org mynick",
+          "Example : /join jdev (as user@jabber.org will join jdev@conference.jabber.org)",
           NULL } } },
 
     { "/rooms",
@@ -2078,16 +2080,32 @@ _cmd_join(gchar **args, struct cmd_help_t help)
         return TRUE;
     }
 
-    char *room = args[0];
+    int num_args = g_strv_length(args);
+    char *room = NULL;
     char *nick = NULL;
+    Jid *room_arg = jid_create(args[0]);
+    GString *room_str = g_string_new("");
+    Jid *my_jid = jid_create(jabber_get_jid());
 
-    int num_args = g_strv_length(args);
+    // full room jid supplied (room@server)
+    if (room_arg->localpart != NULL) {
+        room = args[0];
+
+    // server not supplied (room), guess conference.<users-domain-part>
+    } else {
+        g_string_append(room_str, args[0]);
+        g_string_append(room_str, "@conference.");
+        g_string_append(room_str, strdup(my_jid->domainpart));
+        room = room_str->str;
+    }
+
+    // nick supplied
     if (num_args == 2) {
         nick = args[1];
+
+    // use localpart for nick
     } else {
-        Jid *jid = jid_create(jabber_get_jid());
-        nick = strdup(jid->localpart);
-        jid_destroy(jid);
+        nick = my_jid->localpart;
     }
 
     Jid *room_jid = jid_create_from_bare_and_resource(room, nick);
@@ -2097,6 +2115,10 @@ _cmd_join(gchar **args, struct cmd_help_t help)
     }
     win_join_chat(room_jid);
 
+    jid_destroy(room_jid);
+    jid_destroy(my_jid);
+    g_string_free(room_str, TRUE);
+
     return TRUE;
 }