changeset 28742:63dc67b32577

jabber: Use the newly refactored code to simplify "Initiate Chat".
author Paul Aurich <paul@darkrain42.org>
date Mon, 12 Oct 2009 18:24:37 +0000
parents 724e77faee1a
children d54834e7ad0f ff66496188e0 3fec904938a2
files libpurple/protocols/jabber/chat.c libpurple/protocols/jabber/chat.h libpurple/protocols/jabber/google.c
diffstat 3 files changed, 19 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/chat.c	Mon Oct 12 18:11:32 2009 +0000
+++ b/libpurple/protocols/jabber/chat.c	Mon Oct 12 18:24:37 2009 +0000
@@ -226,10 +226,16 @@
 	chat->handle = g_strdup(handle);
 
 	/* Copy the data hash table to chat->components */
-	/* TODO: Create entries in data table if data is NULL... */
 	chat->components = g_hash_table_new_full(g_str_hash, g_str_equal,
 			g_free, g_free);
-	g_hash_table_foreach(data, insert_in_hash_table, chat->components);
+	if (data == NULL) {
+		g_hash_table_insert(chat->components, g_strdup("handle"), g_strdup(handle));
+		g_hash_table_insert(chat->components, g_strdup("room"), g_strdup(room));
+		g_hash_table_insert(chat->components, g_strdup("server"), g_strdup(server));
+		/* g_hash_table_insert(chat->components, g_strdup("password"), g_strdup(server)); */
+	} else {
+		g_hash_table_foreach(data, insert_in_hash_table, chat->components);
+	}
 
 	chat->members = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
 			(GDestroyNotify)jabber_chat_member_free);
--- a/libpurple/protocols/jabber/chat.h	Mon Oct 12 18:11:32 2009 +0000
+++ b/libpurple/protocols/jabber/chat.h	Mon Oct 12 18:24:37 2009 +0000
@@ -63,8 +63,8 @@
  * into a hash table.
  *
  * @param password The password (if required) to join the room. May be NULL.
- * @param data     A hash table (since it's still required for the core
- *                 interface API).
+ * @param data     The chat hash table.  May be NULL (it will be generated
+ *                 for current core<>prpl API interface.)
  */
 JabberChat *jabber_join_chat(JabberStream *js, const char *room,
                              const char *server, const char *handle,
--- a/libpurple/protocols/jabber/google.c	Mon Oct 12 18:11:32 2009 +0000
+++ b/libpurple/protocols/jabber/google.c	Mon Oct 12 18:24:37 2009 +0000
@@ -1432,10 +1432,7 @@
 	PurpleBuddy *buddy;
 	PurpleConnection *gc;
 	JabberStream *js;
-	JabberChat *jc;
-	GHashTable *chat_info;
-	gchar *chat_name;
-	gchar *uuid;
+	JabberChat *chat;
 	gchar *room;
 	guint32 tmp, a, b;
 
@@ -1443,36 +1440,29 @@
 
 	buddy = PURPLE_BUDDY(node);
 	gc = purple_account_get_connection(purple_buddy_get_account(buddy));
+	g_return_if_fail(gc != NULL);
 	js = purple_connection_get_protocol_data(gc);
 
+	/* Generate a version 4 UUID */
 	tmp = g_random_int();
 	a = 0x4000 | (tmp & 0xFFF); /* 0x4000 to 0x4FFF */
 	tmp >>= 12;
 	b = ((1 << 3) << 12) | (tmp & 0x3FFF); /* 0x8000 to 0xBFFF */
 
 	tmp = g_random_int();
-	uuid = g_strdup_printf("%08x-%04x-%04x-%04x-%04x%08x",
+	room = g_strdup_printf("private-chat-%08x-%04x-%04x-%04x-%04x%08x",
 			g_random_int(),
 			tmp & 0xFFFF,
 			a,
 			b,
 			(tmp >> 16) & 0xFFFF, g_random_int());
 
-	room = g_strdup_printf("private-chat-%s", uuid);
-	chat_name = g_strdup_printf("%s@%s", room, GOOGLE_GROUPCHAT_SERVER);
-	chat_info = jabber_chat_info_defaults(gc, chat_name);
-	if (chat_info) {
-		jabber_chat_join(gc, chat_info);
-		jc = jabber_chat_find(js, room, GOOGLE_GROUPCHAT_SERVER);
-		if (jc)
-		{
-			jc->muc = TRUE;
-			jabber_chat_invite(gc, jc->id, "", buddy->name);
-		}
-		g_hash_table_destroy(chat_info);
+	chat = jabber_join_chat(js, room, GOOGLE_GROUPCHAT_SERVER, js->user->node,
+	                        NULL, NULL);
+	if (chat) {
+		chat->muc = TRUE;
+		jabber_chat_invite(gc, chat->id, "", buddy->name);
 	}
 
 	g_free(room);
-	g_free(uuid);
-	g_free(chat_name);
 }