soc.2009.telepathy: 46c4461f: Cache magic lists on connection. Properl...

sttwister at soc.pidgin.im sttwister at soc.pidgin.im
Thu Jul 2 11:35:34 EDT 2009


-----------------------------------------------------------------
Revision: 46c4461f453d4d6f65b95c80bbc328cf94038da7
Ancestor: febd50e2a1f3fd6eca74c994af61609f9bfaa27e
Author: sttwister at soc.pidgin.im
Date: 2009-07-02T15:25:52
Branch: im.pidgin.soc.2009.telepathy
URL: http://d.pidgin.im/viewmtn/revision/info/46c4461f453d4d6f65b95c80bbc328cf94038da7

Modified files:
        libpurple/protocols/telepathy/telepathy_connection.c
        libpurple/protocols/telepathy/telepathy_connection.h
        libpurple/protocols/telepathy/telepathy_contact.c

ChangeLog: 

Cache magic lists on connection. Properly support adding buddies to existing group

-------------- next part --------------
============================================================
--- libpurple/protocols/telepathy/telepathy_connection.c	74790eeb13411f3e0695fcb245ce1720a49fda21
+++ libpurple/protocols/telepathy/telepathy_connection.c	ebdbd8eea914de080b9912db78eb6126d8ac0c07
@@ -55,6 +55,7 @@ status_changed_cb (TpConnection *proxy,
 		data->text_Channels = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify) destroy_text_channel);
 		data->contacts = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) destroy_contact);
 		data->groups = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify) destroy_group);
+		data->lists = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify) destroy_group);
 	}
 	else if (arg_Status == TP_CONNECTION_STATUS_DISCONNECTED)
 	{
@@ -143,12 +144,25 @@ status_changed_cb (TpConnection *proxy,
 				g_hash_table_destroy(data->text_Channels);
 				data->text_Channels = NULL;
 			}
+
 			if (data->contacts != NULL)
 			{
 				g_hash_table_destroy(data->contacts);
 				data->contacts = NULL;
 			}
 
+			if (data->groups != NULL)
+			{
+				g_hash_table_destroy(data->groups);
+				data->groups = NULL;
+			}
+
+			if (data->lists != NULL)
+			{
+				g_hash_table_destroy(data->lists);
+				data->lists = NULL;
+			}
+
 			g_free(data);
 		}
 
============================================================
--- libpurple/protocols/telepathy/telepathy_connection.h	85d90fc7fc9c404528d1e0a1616d0d1b459cbdc9
+++ libpurple/protocols/telepathy/telepathy_connection.h	8f769344615c8cc7c49eaed17c06d2abbc8674ba
@@ -47,6 +47,9 @@ typedef struct
 
 	/* This will map group name to telepathy_group structs */
 	GHashTable *groups;
+
+	/* This will map list name to telepathy_group structs */
+	GHashTable *lists;
 	
 } telepathy_connection;
 
============================================================
--- libpurple/protocols/telepathy/telepathy_contact.c	2fe26558311ff90427971db842e59213b57ab814
+++ libpurple/protocols/telepathy/telepathy_contact.c	8e5c51ffbc211baa529dbe13e79a5f46b046548d
@@ -67,6 +67,7 @@ add_contact_to_group_cb (TpConnection *c
 	else
 	{
 		telepathy_group *group = user_data;
+		telepathy_group *subscribe_list = user_data; 
 
 		const TpContactFeature features[] = {
 			TP_CONTACT_FEATURE_ALIAS,
@@ -76,15 +77,34 @@ add_contact_to_group_cb (TpConnection *c
 		int i;
 		GArray *arr = g_array_new(0, 0, sizeof(TpHandle));
 
-		purple_debug_info("telepathy", "Contact added!\n");
+		purple_debug_info("telepathy", "Got handle for adding buddy!\n");
 
 		for (i = 0; i<n_handles; ++i)
 		{
 			g_array_append_val(arr, handles[i]);
 		}
 
-		/* TODO: Also add to the subscribe list */
+		/* we need to add the buddy to a group and also the subscribe list */
 
+		subscribe_list = g_hash_table_lookup(group->connection_data->lists,
+				"subscribe");
+
+		if (subscribe_list == NULL)
+		{
+			purple_debug_error("telepathy",
+					"There is no cached subscribe list!\n");
+		}
+		else
+		{
+			/* add buddy to the subscribe list */
+			tp_cli_channel_interface_group_call_add_members(
+					group->channel, -1,
+					arr, NULL,
+					add_member_cb, group->connection_data,
+					NULL, NULL);
+		}
+
+
 		/* this will add the buddy to the specified group */
 		tp_cli_channel_interface_group_call_add_members(group->channel, -1,
 				arr, NULL,
@@ -174,8 +194,8 @@ handle_contacts (telepathy_connection *c
 
 
 			/* we should check if it has statuses for the presence,
-			* since the prpl was not yet loaded when status_types was being called
-			*/
+			 * since the prpl was not yet loaded when status_types was being called
+			 */
 			if (presence != NULL)
 			{
 				if (purple_presence_get_statuses(presence) == NULL)
@@ -238,6 +258,7 @@ group_contacts_ready_cb (TpConnection *c
 
 		handle_contacts(data->connection_data, n_contacts, contacts, n_failed, group);
 
+		/* save the group in a hash table for later use */
 		g_hash_table_insert(data->connection_data->groups,
 				g_strdup(group_name), data);
 	}
@@ -263,9 +284,10 @@ contacts_ready_cb (TpConnection *connect
 	else
 	{
 		handle_contacts(data->connection_data, n_contacts, contacts, n_failed, NULL);
-	}
 
-	/* this isn't used anywhere else except this callback */
-	g_free(data);
+		/* save the list in a hash table for later use */
+		g_hash_table_insert(data->connection_data->lists,
+				(gchar *)tp_channel_get_identifier(data->channel), data);
+	}
 }
 


More information about the Commits mailing list