pidgin: 9afa0cfd: jabber: Use the newly refactored code to...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Mon Oct 12 14:33:04 EDT 2009


-----------------------------------------------------------------
Revision: 9afa0cfda64ff9907b43b21fe64f17f698d2aa0d
Ancestor: 7fcca1fd557e27ad2c8fcdc8b3fbd2b23682bc97
Author: darkrain42 at pidgin.im
Date: 2009-10-12T18:24:37
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/9afa0cfda64ff9907b43b21fe64f17f698d2aa0d

Modified files:
        libpurple/protocols/jabber/chat.c
        libpurple/protocols/jabber/chat.h
        libpurple/protocols/jabber/google.c

ChangeLog: 

jabber: Use the newly refactored code to simplify "Initiate Chat".

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/chat.c	d4aac95ec71c3ed57e157f7f2500fabbf24dcef3
+++ libpurple/protocols/jabber/chat.c	fb44ee14ab62af879cbb3e64475a5af13ad821ef
@@ -226,10 +226,16 @@ static JabberChat *jabber_chat_new(Jabbe
 	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);
============================================================
--- libpurple/protocols/jabber/chat.h	ea31fc02bf0c88ff332bc53860b53707b5683b96
+++ libpurple/protocols/jabber/chat.h	1297d74d3b11a2cd54a56943bea27859f1413adf
@@ -63,8 +63,8 @@ char *jabber_get_chat_name(GHashTable *d
  * 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,
============================================================
--- libpurple/protocols/jabber/google.c	a1f6f23d223d8571e39ede2b5c86898d94c3954d
+++ libpurple/protocols/jabber/google.c	2d90472f0343782c63ff6571fbe909e94072481a
@@ -1432,10 +1432,7 @@ void google_buddy_node_chat(PurpleBlistN
 	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 @@ void google_buddy_node_chat(PurpleBlistN
 
 	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);
 }


More information about the Commits mailing list