soc.2009.telepathy: bd253c07: Request IM channel via ChannelDispatcher

sttwister at gmail.com sttwister at gmail.com
Sun Aug 9 13:10:43 EDT 2009


-----------------------------------------------------------------
Revision: bd253c0766d5b766a489c89d47c4f3e342116dc9
Ancestor: 7cf614ac98c45ad6e1589c9410f091e959fb15c1
Author: sttwister at gmail.com
Date: 2009-08-09T17:06:21
Branch: im.pidgin.soc.2009.telepathy
URL: http://d.pidgin.im/viewmtn/revision/info/bd253c0766d5b766a489c89d47c4f3e342116dc9

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

ChangeLog: 

Request IM channel via ChannelDispatcher

-------------- next part --------------
============================================================
--- libpurple/protocols/telepathy/telepathy.c	19b213736b918d496f8ca58ca47a9df413db2606
+++ libpurple/protocols/telepathy/telepathy.c	9b0cbe15175fc911c5bb4394b52c5a9508f20e3f
@@ -271,6 +271,8 @@ telepathy_send_im (PurpleConnection *gc,
 	}
 	else
 	{
+		telepathy_account *tp_account = data->account_data;
+
 		/* if this is the first message, we need to create the channel */
 		GHashTable *map = tp_asv_new (
 			TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
@@ -281,9 +283,11 @@ telepathy_send_im (PurpleConnection *gc,
 		tp_channel = g_new0(telepathy_text_channel, 1);
 		g_hash_table_insert(data->text_Channels, g_strdup(who), tp_channel);
 
-		purple_debug_info("telepathy", "Creating text channel for %s\n", who);
+		purple_debug_info("telepathy", "Requesting text channel for %s\n", who);
 
-		tp_cli_connection_interface_requests_call_ensure_channel(data->connection, -1, map, ensure_channel_cb, data, NULL, NULL);
+		tp_cli_channel_dispatcher_call_create_channel(channel_Dispatcher, -1,
+			tp_account->obj_Path, map, time(NULL), "",
+			create_channel_cb, data, NULL, NULL); 
 	}
 
 	purple_debug_info("telepathy", "Sending \"%s\" (stripped: \"%s\") to %s\n", message, stripped_message, who);
@@ -308,11 +312,17 @@ telepathy_send_typing (PurpleConnection 
 telepathy_send_typing (PurpleConnection *gc, const char *name, PurpleTypingState state)
 {
 	telepathy_connection *data = purple_connection_get_protocol_data(gc);
-	telepathy_text_channel *tp_channel = g_hash_table_lookup(data->text_Channels, name);
-
 	TpChannel *channel = NULL;
 	TpChannelChatState tp_state;
 	
+	if (data == NULL)
+	{
+		purple_debug_error("telepathy", "PurpleConnection has no protocol data!\n");
+		return;
+	}
+
+	telepathy_text_channel *tp_channel = g_hash_table_lookup(data->text_Channels, name);
+
 	if (tp_channel == NULL)
 	{
 		purple_debug_warning("telepathy", "Received typing notification for %s who doesn't have a cached telepathy_channel struct\n", name);
============================================================
--- libpurple/protocols/telepathy/telepathy_channel.c	d31cf6c6d9426b26721a72a133876e6f7f7e482e
+++ libpurple/protocols/telepathy/telepathy_channel.c	f3818c7df5370e5801880dd26e958c84823bda3c
@@ -20,6 +20,8 @@
 
 #include "telepathy_channel.h"
 
+#include <telepathy-glib/channel-request.h>
+#include <telepathy-glib/dbus.h>
 #include <telepathy-glib/interfaces.h>
 
 #include "internal.h"
@@ -31,7 +33,67 @@
 #include "telepathy_channel_text.h"
 #include "telepathy_contact.h"
 
+static void
+proceed_cb (TpChannelRequest *proxy,
+            const GError *error,
+            gpointer user_data,
+            GObject *weak_object)
+{
+	if (error != NULL)
+	{
+		purple_debug_error("telepathy", "Proceed error: %s\n", error->message);
+		return;
+	}
+
+	purple_debug_info("telepathy", "Proceed succeeded!\n");
+}
+
 void
+create_channel_cb (TpChannelDispatcher *proxy,
+                   const gchar *out_Request,
+                   const GError *error,
+                   gpointer user_data,
+                   GObject *weak_object)
+{
+	GError *err = NULL;
+	TpDBusDaemon *bus_daemon;
+	TpChannelRequest *request;
+
+	if (error != NULL)
+	{
+		purple_debug_error("telepathy", "CreateChannel error: %s\n", error->message);
+		return;
+	}
+
+	purple_debug_info("telepathy", "CreateChannel succeeded!\n");
+
+	bus_daemon = tp_dbus_daemon_dup(&err);
+
+	if (err != NULL)
+	{
+		purple_debug_error("telepathy", "Error dupping dbus daemon: %s\n",
+			err->message);
+		g_error_free(err);
+		g_object_unref(bus_daemon);
+		return;
+	}
+
+	request = tp_channel_request_new(bus_daemon, out_Request, NULL, &err);
+
+	if (err != NULL)
+	{
+		purple_debug_error("telepathy", "Error creating ChannelRequest proxy: %s\n",
+			err->message);
+		g_error_free(err);
+		g_object_unref(bus_daemon);
+		g_object_unref(request);
+		return;
+	}
+
+	tp_cli_channel_request_call_proceed(request, -1, proceed_cb, user_data, NULL, NULL);
+}
+
+void
 channel_ready_cb (TpChannel *channel,
                   const GError *error,
                   gpointer user_data)
============================================================
--- libpurple/protocols/telepathy/telepathy_channel.h	826f04d11dd59ace93e28ce1c4d7b495230938cd
+++ libpurple/protocols/telepathy/telepathy_channel.h	60378fed9ff34438c8537ef5e6946d09d9d4d012
@@ -24,10 +24,18 @@
 #include <glib.h>
 
 #include <telepathy-glib/channel.h>
+#include <telepathy-glib/channel-dispatcher.h>
 
 #include "telepathy_connection.h"
 
 void
+create_channel_cb (TpChannelDispatcher *proxy,
+                   const gchar *out_Request,
+                   const GError *error,
+                   gpointer user_data,
+                   GObject *weak_object);
+
+void
 channel_ready_cb (TpChannel *channel,
                   const GError *error,
                   gpointer user_data);
============================================================
--- libpurple/protocols/telepathy/telepathy_connection.c	73bb957cd1d1e5b5e7537e772a372e16c55581df
+++ libpurple/protocols/telepathy/telepathy_connection.c	37ed27522a641a10a4e2797535b1f1b0938db81a
@@ -216,6 +216,7 @@ got_connection_object (gchar *connection
 	connection_data->connection = tp_connection_new(daemon, NULL, connection_object, &error);
 	connection_data->gc = gc;
 	connection_data->acct = acct;
+	connection_data->account_data = account_data;
 
 	account_data->connection_data = connection_data;
 
============================================================
--- libpurple/protocols/telepathy/telepathy_connection.h	90fd6570845e7df8ed0c820e0a1370c15a9ee905
+++ libpurple/protocols/telepathy/telepathy_connection.h	506c2cc1efd89c5189fc16422ca8a218c1f5ef55
@@ -36,6 +36,8 @@ typedef struct
 	PurpleConnection *gc;
 	PurpleAccount *acct;
 
+	gpointer account_data;
+
 	TpHandle self_handle;
 
 	/* This flag avoids having a channel processed twice via both NewChannels and quering the Channels property */


More information about the Commits mailing list