soc.2009.telepathy: 9ad163e1: Can now also add buddy to a new group

sttwister at soc.pidgin.im sttwister at soc.pidgin.im
Sun Jul 5 07:31:57 EDT 2009


-----------------------------------------------------------------
Revision: 9ad163e1b7292856abe4cafa0672f9d1e29dfd17
Ancestor: 5eda19313b5b9c60d11f31a67c3050f6055a4270
Author: sttwister at soc.pidgin.im
Date: 2009-07-05T11:24:58
Branch: im.pidgin.soc.2009.telepathy
URL: http://d.pidgin.im/viewmtn/revision/info/9ad163e1b7292856abe4cafa0672f9d1e29dfd17

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

ChangeLog: 

Can now also add buddy to a new group

-------------- next part --------------
============================================================
--- libpurple/protocols/telepathy/telepathy.c	9c390c47560fca4a09feb0ff25626f3e2d0cbb6a
+++ libpurple/protocols/telepathy/telepathy.c	9230aa1a6a06237b3cfdbadec44c5ea0533dff6a
@@ -499,9 +499,14 @@ telepathy_add_buddy (PurpleConnection *g
 		purple_debug_info("telepathy", "Group %s does not exist. Creating it!\n",
 				group_name);
 
+		/* We need to store the buddy name so we can add it later after the group is ready */
+		g_hash_table_insert(data->buddy_to_be_added,
+				g_strdup(group_name), g_strdup(buddy_name));
+
+		/* Create the group channel */
 		tp_cli_connection_interface_requests_call_create_channel(data->connection, -1,
-				request, create_group_channel_cb, g_strdup(buddy_name), g_free,
-				NULL);
+				request, create_group_channel_cb, data,
+				NULL, NULL);
 
 		g_hash_table_destroy(request);
 	}
============================================================
--- libpurple/protocols/telepathy/telepathy_channel_list.c	043a39d975c9d60555156c9864a80822a8ae3e55
+++ libpurple/protocols/telepathy/telepathy_channel_list.c	815a9403a11248b09337c06dcca5e002938d75dd
@@ -41,10 +41,6 @@ create_group_channel_cb (TpConnection *p
                          gpointer user_data,
                          GObject *weak_object)
 {
-	/* the name of the buddy to add is stored in user_data */
-	gchar *buddy_name = user_data;
-	gchar const *ids[] = { buddy_name, NULL };
-
 	if (error != NULL)
 	{
 		purple_debug_error("telepathy", "CreateChannel for group error: %s\n",
@@ -53,14 +49,6 @@ create_group_channel_cb (TpConnection *p
 	}
 
 	purple_debug_info("telepathy", "Group channel created: %s\n", out_Channel);
-
-	/* TODO: Add the buddy to the newly created group
-
-	tp_connection_request_handles(proxy, -1,
-			TP_HANDLE_TYPE_CONTACT, ids,
-			add_contact_to_group_cb, tp_group,
-			NULL, NULL);
-	*/
 }
 
 void
@@ -80,6 +68,10 @@ handle_list_channel (TpChannel *channel,
 	guint handle;
 	guint handle_type;
 
+	telepathy_group *group;
+	gchar *buddy_name;
+	const gchar *group_name;
+
 	handle = tp_channel_get_handle(channel, &handle_type);
 
 	members = tp_channel_group_get_members(channel);
@@ -95,25 +87,51 @@ handle_list_channel (TpChannel *channel,
 
 	handles = tp_intset_to_array (members);
 
-	/* we want to create a TpContact for each member of this channel */
-	if (handles->len)
-	{
-		/* this struct is needed to pass both the connection data and the channel proxy */
-		telepathy_group *group = g_new0(telepathy_group, 1);
+	/* this struct is needed to pass both the connection data and the channel proxy */
+	group = g_new0(telepathy_group, 1);
 
-		group->channel = channel;
-		group->connection_data = data;
+	group->channel = channel;
+	group->connection_data = data;
 
-		if (handle_type == TP_HANDLE_TYPE_GROUP)
+	group_name = tp_channel_get_identifier(channel);
+
+	if (handle_type == TP_HANDLE_TYPE_GROUP)
+	{
+		/* this is a user-defined group */
+		if (handles->len)
 		{
-			/* this is a user-defined group */
 			tp_connection_get_contacts_by_handle (connection,
 					handles->len, (const TpHandle *) handles->data,
 					G_N_ELEMENTS (features), features,
 					group_contacts_ready_cb,
 					group, NULL, NULL);
+
 		}
-		else
+
+		/* save the group in a hash table for later use */
+		g_hash_table_insert(data->groups, g_strdup(group_name), group);
+
+		/* Check if we need to add any buddy to this group */
+		buddy_name = g_hash_table_lookup(data->buddy_to_be_added, group_name);
+
+		if (buddy_name != NULL)
+		{                                                                     
+			gchar const *ids[] = { buddy_name, NULL };
+
+			purple_debug_info("telepathy", "Adding %s to group %s\n",
+				buddy_name, group_name);
+
+			tp_connection_request_handles(data->connection, -1,
+					TP_HANDLE_TYPE_CONTACT, ids,
+					add_contact_to_group_cb, group,
+					NULL, NULL);
+
+			g_hash_table_remove(data->buddy_to_be_added, group_name);
+		} 
+	}
+	else
+	{
+		if (handles->len)
 		{
 			tp_connection_get_contacts_by_handle (connection,
 					handles->len, (const TpHandle *) handles->data,
@@ -122,6 +140,8 @@ handle_list_channel (TpChannel *channel,
 					group, NULL, NULL);
 		}
 
+		/* save the list in a hash table for later use */
+		g_hash_table_insert(data->lists, g_strdup(group_name), group);
 	}
 
 	tp_cli_connection_interface_avatars_call_get_known_avatar_tokens(data->connection, -1,
============================================================
--- libpurple/protocols/telepathy/telepathy_connection.c	ebdbd8eea914de080b9912db78eb6126d8ac0c07
+++ libpurple/protocols/telepathy/telepathy_connection.c	93c023c765ce92fbace5f98191c0b530ee5b13db
@@ -56,6 +56,8 @@ status_changed_cb (TpConnection *proxy,
 		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);
+		data->buddy_to_be_added = g_hash_table_new_full(g_str_hash, g_str_equal,
+				g_free, g_free);
 	}
 	else if (arg_Status == TP_CONNECTION_STATUS_DISCONNECTED)
 	{
============================================================
--- libpurple/protocols/telepathy/telepathy_connection.h	8f769344615c8cc7c49eaed17c06d2abbc8674ba
+++ libpurple/protocols/telepathy/telepathy_connection.h	768d0676cd74fbc7fe87c50d3e7d0f2c18d99d13
@@ -50,6 +50,11 @@ typedef struct
 
 	/* This will map list name to telepathy_group structs */
 	GHashTable *lists;
+
+	/* This will map a group name to a buddy to be added to that group.
+	 * It's needed when a new group needs to be created as a request to add a buddy.
+	 */
+	GHashTable *buddy_to_be_added;
 	
 } telepathy_connection;
 
============================================================
--- libpurple/protocols/telepathy/telepathy_contact.c	d1e7cf5590501a842b89efacec6b77951688132a
+++ libpurple/protocols/telepathy/telepathy_contact.c	b056e86ca773a8546ab511a0a7476f833b2a9a9f
@@ -257,10 +257,6 @@ 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);
 	}
 }
 
@@ -284,10 +280,6 @@ contacts_ready_cb (TpConnection *connect
 	else
 	{
 		handle_contacts(data->connection_data, n_contacts, contacts, n_failed, NULL);
-
-		/* 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