]> git.0d.be Git - empathy.git/commitdiff
Add request muc channels to the dispatcher
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>
Fri, 9 Jan 2009 16:12:57 +0000 (16:12 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Fri, 9 Jan 2009 16:12:57 +0000 (16:12 +0000)
Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
svn path=/trunk/; revision=2143

libempathy/empathy-dispatcher.c
libempathy/empathy-dispatcher.h

index c4fa0e147ee5a80224f987c2b45d7643a5f974de..c1ff62f14071308c36835a783d30f37522a5bc32 100644 (file)
@@ -1401,7 +1401,6 @@ dispatcher_connection_new_requested_channel (EmpathyDispatcher *dispatcher,
 out:
   dispatcher_flush_outstanding_operations (request_data->dispatcher,
     conn_data);
-
 }
 
 static void
@@ -1432,12 +1431,8 @@ empathy_dispatcher_call_with_contact_id (McAccount *account,
 }
 
 static void
-dispatcher_chat_with_contact_cb (EmpathyContact *contact, gpointer user_data)
+dispatcher_request_channel (DispatcherRequestData *request_data)
 {
-  DispatcherRequestData *request_data = (DispatcherRequestData *) user_data;
-
-  request_data->handle = empathy_contact_get_handle (contact);
-
   tp_cli_connection_call_request_channel (request_data->connection, -1,
     request_data->channel_type,
     request_data->handle_type,
@@ -1446,6 +1441,16 @@ dispatcher_chat_with_contact_cb (EmpathyContact *contact, gpointer user_data)
     request_data, NULL, G_OBJECT (request_data->dispatcher));
 }
 
+static void
+dispatcher_chat_with_contact_cb (EmpathyContact *contact, gpointer user_data)
+{
+  DispatcherRequestData *request_data = (DispatcherRequestData *) user_data;
+
+  request_data->handle = empathy_contact_get_handle (contact);
+
+  dispatcher_request_channel (request_data);
+}
+
 void
 empathy_dispatcher_chat_with_contact (EmpathyContact *contact,
   EmpathyDispatcherRequestCb *callback, gpointer user_data)
@@ -1491,6 +1496,66 @@ empathy_dispatcher_chat_with_contact_id (McAccount *account, const gchar
   g_object_unref (dispatcher);
 }
 
+
+static void
+dispatcher_request_handles_cb (TpConnection *connection,
+   const GArray *handles, const GError *error, gpointer user_data,
+   GObject *object)
+{
+  DispatcherRequestData *request_data = (DispatcherRequestData *) user_data;
+
+  if (error != NULL)
+    {
+      EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (object);
+      EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
+      ConnectionData *cd;
+
+      cd = g_hash_table_lookup (priv->connections, request_data->connection);
+
+      if (request_data->cb)
+        request_data->cb (NULL, error, request_data->user_data);
+
+      cd->outstanding_requests = g_list_remove (cd->outstanding_requests,
+        request_data);
+
+      free_dispatcher_request_data (request_data);
+
+      dispatcher_flush_outstanding_operations (dispatcher, cd);
+      return;
+    }
+
+  request_data->handle = g_array_index (handles, guint, 0);
+  dispatcher_request_channel (request_data);
+}
+
+void
+empathy_dispatcher_join_muc (McAccount *account, const gchar *roomname,
+  EmpathyDispatcherRequestCb *callback, gpointer user_data)
+{
+  EmpathyDispatcher *dispatcher = empathy_get_dispatcher();
+  EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
+  DispatcherRequestData *request_data;
+  TpConnection *connection = g_hash_table_lookup (priv->accounts, account);
+  ConnectionData *connection_data =
+    g_hash_table_lookup (priv->connections, connection);
+  const gchar *names[] = { roomname, NULL };
+
+  /* Don't know the room handle yet */
+  request_data  = new_dispatcher_request_data (dispatcher, connection,
+    TP_IFACE_CHANNEL_TYPE_TEXT, TP_HANDLE_TYPE_ROOM, 0, NULL,
+    NULL, callback, user_data);
+
+  connection_data->outstanding_requests = g_list_prepend
+    (connection_data->outstanding_requests, request_data);
+
+  tp_cli_connection_call_request_handles (connection, -1,
+    TP_HANDLE_TYPE_ROOM, names,
+    dispatcher_request_handles_cb, request_data, NULL,
+    G_OBJECT (dispatcher));
+
+  g_object_unref (dispatcher);
+}
+
 #if 0
 typedef struct {
        GFile *gfile;
index e1617c33bc8685c474ecf7442a6653daa23d2d0b..d43dcf89de7738afec12a4fb7de24a7a98b102d3 100644 (file)
@@ -68,35 +68,35 @@ typedef void (EmpathyDispatcherRequestCb) (
 
 GType empathy_dispatcher_get_type             (void) G_GNUC_CONST;
 
+/* Requesting 1 to 1 stream media channels */
 void empathy_dispatcher_call_with_contact (EmpathyContact *contact,
   EmpathyDispatcherRequestCb *callback, gpointer user_data);
 void empathy_dispatcher_call_with_contact_id (McAccount *account,
   const gchar           *contact_id, EmpathyDispatcherRequestCb *callback,
   gpointer user_data);
 
+/* Requesting 1 to 1 text channels */
 void empathy_dispatcher_chat_with_contact_id (McAccount *account,
   const gchar *contact_id, EmpathyDispatcherRequestCb *callback,
   gpointer user_data);
 void  empathy_dispatcher_chat_with_contact (EmpathyContact *contact,
   EmpathyDispatcherRequestCb *callback, gpointer user_data);
 
-void empathy_dispatcher_chat_with_contact_id (McAccount *account,
-  const gchar *contact_id, EmpathyDispatcherRequestCb *callback,
-  gpointer user_data);
-void  empathy_dispatcher_chat_with_contact (EmpathyContact *contact,
-  EmpathyDispatcherRequestCb *callback, gpointer user_data);
-
+/* Request a file channel to a specific contact */
 void empathy_dispatcher_send_file_to_contact (EmpathyContact *contact,
   const gchar *filename, guint64 size, guint64 date,
   const gchar *content_type, EmpathyDispatcherRequestCb *callback,
   gpointer user_data);
 
+/* Request a muc channel */
+void empathy_dispatcher_join_muc (McAccount *account,
+  const gchar *roomname, EmpathyDispatcherRequestCb *callback,
+  gpointer user_data);
 
 /* Get the dispatcher singleton */
 EmpathyDispatcher *    empathy_get_dispatcher (void);
 GType                  empathy_dispatcher_tube_get_type        (void);
 
-
 /* tube stuff */
 EmpathyDispatcherTube *empathy_dispatcher_tube_ref             (EmpathyDispatcherTube *tube);
 void                   empathy_dispatcher_tube_unref           (EmpathyDispatcherTube *tube);