soc.2009.telepathy: 33bbda77: Handle new channels only when dispatched...

sttwister at soc.pidgin.im sttwister at soc.pidgin.im
Tue Jul 28 11:05:23 EDT 2009


-----------------------------------------------------------------
Revision: 33bbda77a3fd14e41b11f645c3d6e0f288e5b281
Ancestor: 5132d2ae2861b5e6fbafff1cad281f3ce3c61ae0
Author: sttwister at soc.pidgin.im
Date: 2009-07-28T15:00:18
Branch: im.pidgin.soc.2009.telepathy
URL: http://d.pidgin.im/viewmtn/revision/info/33bbda77a3fd14e41b11f645c3d6e0f288e5b281

Modified files:
        libpurple/protocols/telepathy/telepathy.c
        libpurple/protocols/telepathy/telepathy.h
        libpurple/protocols/telepathy/telepathy_account.c
        libpurple/protocols/telepathy/telepathy_channel.c
        libpurple/protocols/telepathy/telepathy_client.c

ChangeLog: 

Handle new channels only when dispatched to Client.Handler. NewChannels
now only handles contact list channels.

-------------- next part --------------
============================================================
--- libpurple/protocols/telepathy/telepathy.c	a6971e2a5b910748e84b9b98faf59e50270e3fdf
+++ libpurple/protocols/telepathy/telepathy.c	5305af69cef915b18a696f65b78ac2a870ef0e86
@@ -1191,6 +1191,8 @@ G_MODULE_EXPORT gboolean purple_init_plu
 	if (daemon != NULL)
 		g_object_unref(daemon);
 
+	accounts_Hash_Table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+
 	/* Create the Client.Handler object */
 	telepathy_client_dup_singleton();
 
============================================================
--- libpurple/protocols/telepathy/telepathy.h	481051030c5780fa417cfc9d41a8cdf533285e3d
+++ libpurple/protocols/telepathy/telepathy.h	4fe1d4ed1f55846efc20463ef70a9100748b9d84
@@ -21,9 +21,13 @@
 #ifndef _TELEPATHY_H_
 #define _TELEPATHY_H_
 
+#include <glib.h>
+
 #include <telepathy-glib/account-manager.h>
 #include <telepathy-glib/connection-manager.h>
 
+#include "plugin.h"
+
 #define TELEPATHY_ID "prpl-telepathy"
 #define TELEPATHY_DISPLAY_VERSION "1.0"
 
@@ -31,6 +35,9 @@ TpAccountManager *account_Manager;
 gchar *module_path;
 TpAccountManager *account_Manager;
 
+/* This maps account object path to account_data struct */
+GHashTable *accounts_Hash_Table;
+
 typedef struct
 {
 	TpConnectionManager *cm;
============================================================
--- libpurple/protocols/telepathy/telepathy_account.c	cdc7f72ed98b2b6211cd3f651578c4dff6b8fd78
+++ libpurple/protocols/telepathy/telepathy_account.c	2aab2305e53300fca6d0ddc5b79e616915c1d071
@@ -525,7 +525,10 @@ create_account_cb (TpAccountManager *pro
 	account_data->obj_Path = g_strdup((gchar *)out_Account);
 	account_data->tp_account = tp_account;
 
+	purple_debug_info("telepathy", "Caching account %s\n", out_Account);
 
+	g_hash_table_insert(accounts_Hash_Table, g_strdup(out_Account), account_data);
+
 	tp_cli_account_connect_to_account_property_changed(tp_account,
 		account_property_changed_cb, account_data,
 		NULL, NULL, &err);
@@ -711,6 +714,10 @@ get_valid_accounts_cb (TpProxy *proxy,
 		account_data->properties = g_hash_table_new_full (g_str_hash, g_str_equal,
 			NULL, (GDestroyNotify) tp_g_value_slice_free);
 
+		purple_debug_info("telepathy", "Caching account %s\n", obj_Path);
+
+		g_hash_table_insert(accounts_Hash_Table, g_strdup(obj_Path), account_data);
+
 		/* Get all properties and sync the accounts with libpurple */
 		tp_cli_account_connect_to_account_property_changed(account,
 				account_property_changed_cb, account_data,
============================================================
--- libpurple/protocols/telepathy/telepathy_channel.c	bfd65c2c37f142efbd42435199415da13ba532a0
+++ libpurple/protocols/telepathy/telepathy_channel.c	d31cf6c6d9426b26721a72a133876e6f7f7e482e
@@ -78,8 +78,27 @@ handle_new_channel (telepathy_connection
 
 	GError *error = NULL;
 	TpConnection *connection = data->connection;
-	TpChannel *channel = tp_channel_new_from_properties(connection, object_Path, map, &error);
 
+	TpChannel *channel;
+	const gchar *channel_Type = g_value_get_string(
+		g_hash_table_lookup(map, TP_IFACE_CHANNEL ".ChannelType"));
+
+	if (channel_Type == NULL)
+	{
+		purple_debug_error("telepathy", "Channel has no type!\n");
+		return;
+	}
+
+	/* We only listen to contact list channels via the NewChannels signal */
+	if (g_strcmp0(channel_Type, TP_IFACE_CHANNEL_TYPE_CONTACT_LIST) != 0)
+	{
+		purple_debug_info("telepathy", "NewChannels received non contact list channel (%s),"
+			" dropping it!\n", channel_Type);
+		return;
+	}
+
+	channel = tp_channel_new_from_properties(connection, object_Path, map, &error);
+
 	if (error != NULL)
 	{
 		purple_debug_error("telepathy", "Error while creating TpChannel: %s\n", error->message);
@@ -106,8 +125,6 @@ new_channels_cb (TpConnection *proxy,
 	if (data->listing_channels)
 		return;
 
-	purple_debug_info("telepathy", "NewChannels:\n");
-
 	for (i = 0; i < arg_Channels->len; i++)
 	{
 		GValueArray *channel = g_ptr_array_index(arg_Channels, i);
============================================================
--- libpurple/protocols/telepathy/telepathy_client.c	a96bc6e4f3b84ce805708348928d2a2392a527f8
+++ libpurple/protocols/telepathy/telepathy_client.c	a265d48dad7ab53177afc32a941b48bb46b8fed6
@@ -30,6 +30,11 @@
 
 #include "debug.h"
 
+#include "telepathy.h"
+#include "telepathy_account.h"
+#include "telepathy_channel.h"
+#include "telepathy_connection.h"
+
 #define CLIENT_BUS_NAME TP_CLIENT_BUS_NAME_BASE "prpl_telepathy"
 #define CLIENT_OBJECT_PATH TP_CLIENT_OBJECT_PATH_BASE "prpl_telepathy"
 
@@ -330,16 +335,50 @@ telepathy_client_handle_channels (TpSvcC
 		GValueArray *arr = g_ptr_array_index (channels, i);
 		const gchar *object_path;
 		GHashTable *properties;
+		telepathy_account *account_data;
+		telepathy_connection *connection_data;
+		TpChannel *channel;
+		GError *error = NULL;
 
 		object_path = g_value_get_boxed (g_value_array_get_nth (arr, 0));
 		properties = g_value_get_boxed (g_value_array_get_nth (arr, 1));
 
 		purple_debug_info("telepathy", "HandleChannels: %s\n", object_path);
 
-		/*
-		client_connection_new_channel_with_properties (client,
-			connection, object_path, properties);
-		*/
+		account_data = g_hash_table_lookup(accounts_Hash_Table, account_path);
+
+		if (account_data == NULL)
+		{
+			purple_debug_error("telepathy", "Received channel, but account (%s)"
+				" is not cached!\n", account_path);
+			return;
+		}
+
+		connection_data = account_data->connection_data;
+
+		if (connection_data == NULL)
+		{
+			purple_debug_error("telepathy", "Received channel, but account's connection"
+				" is not cached!\n");
+		}
+
+		channel = tp_channel_new_from_properties(connection_data->connection,
+			object_path, properties, &error);
+
+		if (error != NULL)
+		{
+			purple_debug_error("telepathy", "Error while creating TpChannel: %s\n",
+				error->message);
+			g_error_free(error);
+			return;
+		}
+
+		purple_debug_info("telepathy", "New channel: %s\n", object_path);
+
+		tp_channel_call_when_ready(channel, channel_ready_cb, connection_data);
+
+		g_signal_connect(channel, "invalidated",
+			G_CALLBACK (channel_invalidated_cb), connection_data);
 	}
 
 	tp_svc_client_handler_return_from_handle_channels (context);


More information about the Commits mailing list