changeset 31756:9d8a47ca14a1

jabber: Add support for joining a room based not on the current server. An extension of a patch from Solarius, mcepl, and wyuka; I added in jabber_id_new parsing. Fixes #4526. I'll tweak the context help after the string freeze.
author Paul Aurich <paul@darkrain42.org>
date Sun, 06 Mar 2011 22:53:15 +0000
parents b44e3c2e83e1
children f178a7df417a
files ChangeLog libpurple/protocols/jabber/jabber.c
diffstat 2 files changed, 33 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Mar 06 22:38:45 2011 +0000
+++ b/ChangeLog	Sun Mar 06 22:53:15 2011 +0000
@@ -28,6 +28,8 @@
 	  2.7.10).  (#13329)
 	* Don't treat the on-join status storms as 'new arrivals'.  (Thijs
 	  Alkemade) (#a14527)
+	* Extend the /join command to support room JIDs, enabling you to join
+	  a room on any server.  (Solarius, Matěj Cepl, wyuka) (#4526)
 
 version 2.7.10 (02/06/2011):
 	General:
--- a/libpurple/protocols/jabber/jabber.c	Sun Mar 06 22:38:45 2011 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Sun Mar 06 22:53:15 2011 +0000
@@ -3008,21 +3008,44 @@
 {
 	JabberChat *chat = jabber_chat_find_by_conv(conv);
 	GHashTable *components;
-
-	if(!chat || !args || !args[0])
+	JabberID *jid;
+	const char *room = NULL, *server = NULL, *handle = NULL;
+
+	if (!chat || !args || !args[0])
 		return PURPLE_CMD_RET_FAILED;
 
 	components = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
 
-	g_hash_table_replace(components, "room", args[0]);
-	g_hash_table_replace(components, "server", chat->server);
-	g_hash_table_replace(components, "handle", chat->handle);
-	if(args[1])
-		g_hash_table_replace(components, "password", args[1]);
+	jid = jabber_id_new(args[0]);
+	if (jid) {
+		room   = jid->node;
+		server = jid->domain;
+		handle = jid->resource ? jid->resource : chat->handle;
+	} else {
+		/* If jabber_id_new failed, the user may have just passed in
+		 * a room name.  For backward compatibility, handle that here.
+		 */
+		if (strchr(args[0], '@')) {
+			*error = g_strdup(_("Invalid XMPP ID"));
+			return PURPLE_CMD_RET_FAILED;
+		}
+
+		room   = args[0];
+		server = chat->server;
+		handle = chat->handle;
+	}
+
+	g_hash_table_insert(components, "room", (gpointer)room);
+	g_hash_table_insert(components, "server", (gpointer)server);
+	g_hash_table_insert(components, "handle", (gpointer)handle);
+
+	if (args[1])
+		g_hash_table_insert(components, "password", args[1]);
 
 	jabber_chat_join(purple_conversation_get_gc(conv), components);
 
 	g_hash_table_destroy(components);
+	jabber_id_free(jid);
 	return PURPLE_CMD_RET_OK;
 }
 
@@ -3650,6 +3673,7 @@
 	                  PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
 	                  jabber_cmd_chat_join,
 	                  _("join: &lt;room&gt; [password]:  Join a chat on this server."),
+	                  /* _("join: &lt;room[@server]&gt; [password]:  Join a chat."), */
 	                  NULL);
 	commands = g_slist_prepend(commands, GUINT_TO_POINTER(id));