1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007-2008 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
26 #include <glib/gi18n.h>
28 #include <telepathy-glib/enums.h>
29 #include <telepathy-glib/connection.h>
30 #include <telepathy-glib/util.h>
31 #include <telepathy-glib/dbus.h>
32 #include <telepathy-glib/proxy-subclass.h>
34 #include <libmissioncontrol/mission-control.h>
35 #include <libmissioncontrol/mc-account.h>
37 #include <extensions/extensions.h>
39 #include "empathy-dispatcher.h"
40 #include "empathy-utils.h"
41 #include "empathy-tube-handler.h"
42 #include "empathy-contact-factory.h"
43 #include "empathy-tp-group.h"
44 #include "empathy-chatroom-manager.h"
45 #include "empathy-utils.h"
47 #define DEBUG_FLAG EMPATHY_DEBUG_DISPATCHER
48 #include <libempathy/empathy-debug.h>
50 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyDispatcher)
52 GHashTable *connections;
56 EmpathyChatroomManager *chatroom_mgr;
57 } EmpathyDispatcherPriv;
59 G_DEFINE_TYPE (EmpathyDispatcher, empathy_dispatcher, G_TYPE_OBJECT);
68 static guint signals[LAST_SIGNAL];
69 static EmpathyDispatcher *dispatcher = NULL;
72 empathy_dispatcher_channel_process (EmpathyDispatcher *dispatcher,
75 g_signal_emit (dispatcher, signals[DISPATCH_CHANNEL], 0, channel);
79 EmpathyDispatcherTube public;
80 EmpathyContactFactory *factory;
88 empathy_dispatcher_tube_get_type (void)
90 static GType type_id = 0;
93 type_id = g_boxed_type_register_static ("EmpathyDispatcherTube",
94 (GBoxedCopyFunc) empathy_dispatcher_tube_ref,
95 (GBoxedFreeFunc) empathy_dispatcher_tube_unref);
101 EmpathyDispatcherTube *
102 empathy_dispatcher_tube_ref (EmpathyDispatcherTube *data)
104 DispatcherTube *tube = (DispatcherTube*) data;
106 g_return_val_if_fail (tube != NULL, NULL);
114 empathy_dispatcher_tube_unref (EmpathyDispatcherTube *data)
116 DispatcherTube *tube = (DispatcherTube*) data;
118 g_return_if_fail (tube != NULL);
120 if (--tube->ref_count == 0) {
121 if (!tube->handled) {
122 DEBUG ("Tube can't be handled, closing");
123 tp_cli_channel_type_tubes_call_close_tube (tube->public.channel, -1,
129 g_free (tube->bus_name);
130 g_free (tube->object_path);
131 g_object_unref (tube->factory);
132 g_object_unref (tube->public.channel);
133 g_object_unref (tube->public.initiator);
134 g_slice_free (DispatcherTube, tube);
139 dispatcher_tubes_handle_tube_cb (TpProxy *channel,
144 DispatcherTube *tube = user_data;
147 DEBUG ("Error: %s", error->message);
149 tube->handled = TRUE;
154 empathy_dispatcher_tube_process (EmpathyDispatcher *dispatcher,
155 EmpathyDispatcherTube *user_data)
157 DispatcherTube *tube = (DispatcherTube*) user_data;
159 if (tube->public.activatable) {
166 /* Create the proxy for the tube handler */
167 thandler = g_object_new (TP_TYPE_PROXY,
168 "dbus-connection", tp_get_bus (),
169 "bus-name", tube->bus_name,
170 "object-path", tube->object_path,
172 tp_proxy_add_interface_by_id (thandler, EMP_IFACE_QUARK_TUBE_HANDLER);
174 /* Give the tube to the handler */
175 g_object_get (tube->public.channel,
176 "connection", &connection,
177 "object-path", &object_path,
178 "handle_type", &handle_type,
182 DEBUG ("Dispatching tube");
183 emp_cli_tube_handler_call_handle_tube (thandler, -1,
184 connection->bus_name,
185 connection->object_path,
186 object_path, handle_type,
187 handle, tube->public.id,
188 dispatcher_tubes_handle_tube_cb,
189 empathy_dispatcher_tube_ref (user_data),
190 (GDestroyNotify) empathy_dispatcher_tube_unref,
191 G_OBJECT (dispatcher));
193 g_object_unref (thandler);
194 g_object_unref (connection);
195 g_free (object_path);
200 dispatcher_tubes_new_tube_cb (TpChannel *channel,
204 const gchar *service,
205 GHashTable *parameters,
210 static TpDBusDaemon *daemon = NULL;
211 DispatcherTube *tube;
215 gboolean running = FALSE;
216 GError *error = NULL;
218 /* Increase tube count */
219 number = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (channel), "tube-count"));
220 g_object_set_data (G_OBJECT (channel), "tube-count", GUINT_TO_POINTER (++number));
221 DEBUG ("Increased tube count for channel %p: %d", channel, number);
223 /* We dispatch only local pending tubes */
224 if (state != TP_TUBE_STATE_LOCAL_PENDING) {
229 daemon = tp_dbus_daemon_new (tp_get_bus ());
232 account = empathy_channel_get_account (channel);
233 tube = g_slice_new (DispatcherTube);
235 tube->handled = FALSE;
236 tube->factory = empathy_contact_factory_new ();
237 tube->bus_name = empathy_tube_handler_build_bus_name (type, service);
238 tube->object_path = empathy_tube_handler_build_object_path (type, service);
239 tube->public.activatable = FALSE;
240 tube->public.id = id;
241 tube->public.channel = g_object_ref (channel);
242 tube->public.initiator = empathy_contact_factory_get_from_handle (tube->factory,
245 g_object_unref (account);
247 /* Check if that bus-name has an owner, if it has one that means the
248 * app is already running and we can directly give the channel. */
249 tp_cli_dbus_daemon_run_name_has_owner (daemon, -1, tube->bus_name,
250 &running, NULL, NULL);
252 DEBUG ("Tube handler running");
253 tube->public.activatable = TRUE;
254 empathy_dispatcher_tube_process (EMPATHY_DISPATCHER (dispatcher),
255 (EmpathyDispatcherTube*) tube);
256 empathy_dispatcher_tube_unref ((EmpathyDispatcherTube*) tube);
260 /* Check if that bus-name is activatable, if not that means the
261 * application needed to handle this tube isn't installed. */
262 if (!tp_cli_dbus_daemon_run_list_activatable_names (daemon, -1,
265 DEBUG ("Error listing activatable names: %s", error->message);
266 g_clear_error (&error);
270 for (name = names; *name; name++) {
271 if (!tp_strdiff (*name, tube->bus_name)) {
272 tube->public.activatable = TRUE;
279 g_signal_emit (dispatcher, signals[FILTER_TUBE], 0, tube);
280 empathy_dispatcher_tube_unref ((EmpathyDispatcherTube*) tube);
284 dispatcher_tubes_list_tubes_cb (TpChannel *channel,
285 const GPtrArray *tubes,
293 DEBUG ("Error: %s", error->message);
297 for (i = 0; i < tubes->len; i++) {
300 values = g_ptr_array_index (tubes, i);
301 dispatcher_tubes_new_tube_cb (channel,
302 g_value_get_uint (g_value_array_get_nth (values, 0)),
303 g_value_get_uint (g_value_array_get_nth (values, 1)),
304 g_value_get_uint (g_value_array_get_nth (values, 2)),
305 g_value_get_string (g_value_array_get_nth (values, 3)),
306 g_value_get_boxed (g_value_array_get_nth (values, 4)),
307 g_value_get_uint (g_value_array_get_nth (values, 5)),
308 user_data, dispatcher);
313 dispatcher_tubes_channel_invalidated_cb (TpProxy *proxy,
317 EmpathyDispatcher *dispatcher)
319 EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
321 DEBUG ("%s", message);
323 priv->tubes = g_slist_remove (priv->tubes, proxy);
324 g_object_unref (proxy);
328 dispatcher_tubes_tube_closed_cb (TpChannel *channel,
335 number = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (channel), "tube-count"));
337 DEBUG ("No more tube, closing channel");
338 tp_cli_channel_call_close (channel, -1, NULL, NULL, NULL, NULL);
340 else if (number > 1) {
341 DEBUG ("Decrease tube count: %d", number);
342 g_object_set_data (G_OBJECT (channel), "tube-count", GUINT_TO_POINTER (--number));
347 dispatcher_tubes_handle_channel (EmpathyDispatcher *dispatcher,
350 EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
354 priv->tubes = g_slist_prepend (priv->tubes, g_object_ref (channel));
355 g_signal_connect (channel, "invalidated",
356 G_CALLBACK (dispatcher_tubes_channel_invalidated_cb),
359 tp_cli_channel_type_tubes_connect_to_tube_closed (channel,
360 dispatcher_tubes_tube_closed_cb,
362 G_OBJECT (dispatcher), NULL);
363 tp_cli_channel_type_tubes_connect_to_new_tube (channel,
364 dispatcher_tubes_new_tube_cb,
366 G_OBJECT (dispatcher), NULL);
367 tp_cli_channel_type_tubes_call_list_tubes (channel, -1,
368 dispatcher_tubes_list_tubes_cb,
370 G_OBJECT (dispatcher));
374 dispatcher_file_handle_channel (EmpathyDispatcher *dispatcher,
377 DEBUG ("New file channel");
379 /* handle new file channel here */
383 dispatcher_connection_invalidated_cb (TpConnection *connection,
387 EmpathyDispatcher *dispatcher)
389 EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
393 DEBUG ("Error: %s", message);
395 g_hash_table_iter_init (&iter, priv->connections);
396 while (g_hash_table_iter_next (&iter, &key, &value)) {
397 if (value == connection) {
398 g_hash_table_remove (priv->connections, key);
406 EmpathyDispatcher *self;
407 EmpathyChatroom *chatroom;
408 } dispatcher_connection_invalidated_cb_ctx;
410 static dispatcher_connection_invalidated_cb_ctx *
411 dispatcher_connection_invalidated_cb_ctx_new (EmpathyDispatcher *dispatcher,
412 EmpathyChatroom *chatroom)
414 dispatcher_connection_invalidated_cb_ctx *ctx;
416 ctx = g_slice_new (dispatcher_connection_invalidated_cb_ctx);
418 ctx->self = g_object_ref (dispatcher);
419 ctx->chatroom = g_object_ref (chatroom);
425 dispatcher_connection_invalidated_cb_ctx_free (
426 dispatcher_connection_invalidated_cb_ctx *ctx)
428 g_object_unref (ctx->self);
429 g_object_unref (ctx->chatroom);
431 g_slice_free (dispatcher_connection_invalidated_cb_ctx, ctx);
434 static void dispatcher_chatroom_invalidated_cb (
439 dispatcher_connection_invalidated_cb_ctx *ctx)
441 EmpathyDispatcherPriv *priv = GET_PRIV (ctx->self);
444 g_object_get (ctx->chatroom, "favorite", &favorite, NULL);
448 /* Chatroom is in favorites so don't remove it from the manager */
449 g_object_set (ctx->chatroom, "tp-channel", NULL, NULL);
453 empathy_chatroom_manager_remove (priv->chatroom_mgr, ctx->chatroom);
458 dispatcher_connection_new_channel_cb (TpConnection *connection,
459 const gchar *object_path,
460 const gchar *channel_type,
463 gboolean suppress_handler,
467 EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (object);
468 EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
470 gpointer had_channels;
472 had_channels = g_object_get_data (G_OBJECT (connection), "had-channels");
473 if (had_channels == NULL) {
474 /* ListChannels didn't return yet, return to avoid duplicate
479 channel = tp_channel_new (connection, object_path, channel_type,
480 handle_type, handle, NULL);
481 tp_channel_run_until_ready (channel, NULL, NULL);
483 if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_TUBES)) {
484 dispatcher_tubes_handle_channel (dispatcher, channel);
485 } else if (!tp_strdiff (channel_type, EMP_IFACE_CHANNEL_TYPE_FILE)) {
486 dispatcher_file_handle_channel (dispatcher, channel);
489 if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_TEXT) &&
490 handle_type == TP_HANDLE_TYPE_ROOM)
492 /* Add the chatroom to the chatroom manager */
493 EmpathyChatroom *chatroom;
498 dispatcher_connection_invalidated_cb_ctx *ctx;
500 handles = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), 1);
501 g_array_append_val (handles, handle);
503 tp_cli_connection_run_inspect_handles (connection, -1,
504 TP_HANDLE_TYPE_ROOM, handles, &room_ids, NULL, NULL);
506 mc = empathy_mission_control_new ();
507 account = mission_control_get_account_for_tpconnection (mc, connection,
510 chatroom = empathy_chatroom_manager_find (priv->chatroom_mgr, account,
512 if (chatroom == NULL)
514 chatroom = empathy_chatroom_new (account);
515 empathy_chatroom_set_name (chatroom, room_ids[0]);
516 empathy_chatroom_manager_add (priv->chatroom_mgr, chatroom);
520 g_object_ref (chatroom);
523 g_object_set (chatroom, "tp-channel", channel, NULL);
525 ctx = dispatcher_connection_invalidated_cb_ctx_new (dispatcher, chatroom);
527 g_signal_connect_data (channel, "invalidated",
528 G_CALLBACK (dispatcher_chatroom_invalidated_cb), ctx,
529 (GClosureNotify) dispatcher_connection_invalidated_cb_ctx_free, 0);
531 g_free (room_ids[0]);
533 g_array_free (handles, TRUE);
535 g_object_unref (account);
536 g_object_unref (chatroom);
539 if (suppress_handler) {
540 g_signal_emit (dispatcher, signals[DISPATCH_CHANNEL], 0, channel);
542 g_signal_emit (dispatcher, signals[FILTER_CHANNEL], 0, channel);
545 g_object_unref (channel);
549 dispatcher_connection_list_channels_cb (TpConnection *connection,
550 const GPtrArray *channels,
558 DEBUG ("Error: %s", error->message);
562 g_object_set_data (G_OBJECT (connection), "had-channels",
563 GUINT_TO_POINTER (1));
565 for (i = 0; i < channels->len; i++) {
568 values = g_ptr_array_index (channels, i);
569 dispatcher_connection_new_channel_cb (connection,
570 g_value_get_boxed (g_value_array_get_nth (values, 0)),
571 g_value_get_string (g_value_array_get_nth (values, 1)),
572 g_value_get_uint (g_value_array_get_nth (values, 2)),
573 g_value_get_uint (g_value_array_get_nth (values, 3)),
574 FALSE, user_data, dispatcher);
579 dispatcher_connection_advertise_capabilities_cb (TpConnection *connection,
580 const GPtrArray *capabilities,
586 DEBUG ("Error: %s", error->message);
591 dispatcher_connection_ready_cb (TpConnection *connection,
595 GPtrArray *capabilities;
598 const gchar *remove = NULL;
601 dispatcher_connection_invalidated_cb (connection,
609 g_signal_connect (connection, "invalidated",
610 G_CALLBACK (dispatcher_connection_invalidated_cb),
612 tp_cli_connection_connect_to_new_channel (connection,
613 dispatcher_connection_new_channel_cb,
615 G_OBJECT (dispatcher), NULL);
616 tp_cli_connection_call_list_channels (connection, -1,
617 dispatcher_connection_list_channels_cb,
619 G_OBJECT (dispatcher));
621 /* Advertise VoIP capabilities */
622 capabilities = g_ptr_array_sized_new (1);
623 cap_type = dbus_g_type_get_struct ("GValueArray", G_TYPE_STRING,
624 G_TYPE_UINT, G_TYPE_INVALID);
625 g_value_init (&cap, cap_type);
626 g_value_take_boxed (&cap, dbus_g_type_specialized_construct (cap_type));
627 dbus_g_type_struct_set (&cap,
628 0, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
629 1, TP_CHANNEL_MEDIA_CAPABILITY_AUDIO |
630 TP_CHANNEL_MEDIA_CAPABILITY_VIDEO |
631 TP_CHANNEL_MEDIA_CAPABILITY_NAT_TRAVERSAL_STUN |
632 TP_CHANNEL_MEDIA_CAPABILITY_NAT_TRAVERSAL_GTALK_P2P,
634 g_ptr_array_add (capabilities, g_value_get_boxed (&cap));
636 tp_cli_connection_interface_capabilities_call_advertise_capabilities (
638 capabilities, &remove,
639 dispatcher_connection_advertise_capabilities_cb,
640 NULL, NULL, G_OBJECT (dispatcher));
641 /* FIXME: Is that leaked? */
645 dispatcher_update_account (EmpathyDispatcher *dispatcher,
648 EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
649 TpConnection *connection;
651 connection = g_hash_table_lookup (priv->connections, account);
656 connection = mission_control_get_tpconnection (priv->mc, account, NULL);
661 g_hash_table_insert (priv->connections, g_object_ref (account), connection);
662 tp_connection_call_when_ready (connection,
663 dispatcher_connection_ready_cb,
668 dispatcher_status_changed_cb (MissionControl *mc,
669 TpConnectionStatus status,
671 TpConnectionStatusReason reason,
672 const gchar *unique_name,
673 EmpathyDispatcher *dispatcher)
677 account = mc_account_lookup (unique_name);
678 dispatcher_update_account (dispatcher, account);
679 g_object_unref (account);
683 dispatcher_finalize (GObject *object)
685 EmpathyDispatcherPriv *priv = GET_PRIV (object);
688 empathy_disconnect_account_status_changed (priv->token);
689 g_object_unref (priv->mc);
691 for (l = priv->tubes; l; l = l->next) {
692 g_signal_handlers_disconnect_by_func (l->data,
693 dispatcher_tubes_channel_invalidated_cb,
695 g_object_unref (l->data);
697 g_slist_free (priv->tubes);
699 g_hash_table_destroy (priv->connections);
701 g_object_unref (priv->chatroom_mgr);
705 empathy_dispatcher_class_init (EmpathyDispatcherClass *klass)
707 GObjectClass *object_class = G_OBJECT_CLASS (klass);
709 object_class->finalize = dispatcher_finalize;
711 signals[DISPATCH_CHANNEL] =
712 g_signal_new ("dispatch-channel",
713 G_TYPE_FROM_CLASS (klass),
717 g_cclosure_marshal_VOID__OBJECT,
720 signals[FILTER_CHANNEL] =
721 g_signal_new ("filter-channel",
722 G_TYPE_FROM_CLASS (klass),
726 g_cclosure_marshal_VOID__OBJECT,
729 signals[FILTER_TUBE] =
730 g_signal_new ("filter-tube",
731 G_TYPE_FROM_CLASS (klass),
735 g_cclosure_marshal_VOID__BOXED,
737 1, EMPATHY_TYPE_DISPATCHER_TUBE);
739 g_type_class_add_private (object_class, sizeof (EmpathyDispatcherPriv));
743 empathy_dispatcher_init (EmpathyDispatcher *dispatcher)
746 EmpathyDispatcherPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (dispatcher,
747 EMPATHY_TYPE_DISPATCHER, EmpathyDispatcherPriv);
749 dispatcher->priv = priv;
750 priv->mc = empathy_mission_control_new ();
751 priv->token = empathy_connect_to_account_status_changed (priv->mc,
752 G_CALLBACK (dispatcher_status_changed_cb),
755 priv->connections = g_hash_table_new_full (empathy_account_hash,
756 empathy_account_equal,
759 accounts = mc_accounts_list_by_enabled (TRUE);
760 for (l = accounts; l; l = l->next) {
761 dispatcher_update_account (dispatcher, l->data);
762 g_object_unref (l->data);
764 g_list_free (accounts);
766 priv->chatroom_mgr = empathy_chatroom_manager_new (NULL);
770 empathy_dispatcher_new (void)
773 dispatcher = g_object_new (EMPATHY_TYPE_DISPATCHER, NULL);
774 g_object_add_weak_pointer (G_OBJECT (dispatcher), (gpointer) &dispatcher);
776 g_object_ref (dispatcher);
783 const gchar *channel_type;
786 } DispatcherRequestData;
789 dispatcher_request_channel_cb (TpConnection *connection,
790 const gchar *object_path,
793 GObject *weak_object)
795 DispatcherRequestData *data = (DispatcherRequestData*) user_data;
798 DEBUG ("Error: %s", error->message);
805 channel = tp_channel_new (connection, object_path,
810 g_signal_emit (dispatcher, signals[DISPATCH_CHANNEL], 0, channel);
815 empathy_dispatcher_call_with_contact (EmpathyContact *contact)
819 TpConnection *connection;
822 EmpathyContactFactory *factory;
823 EmpathyTpGroup *group;
824 EmpathyContact *self_contact;
825 GError *error = NULL;
827 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
829 mc = empathy_mission_control_new ();
830 account = empathy_contact_get_account (contact);
831 connection = mission_control_get_tpconnection (mc, account, NULL);
832 tp_connection_run_until_ready (connection, FALSE, NULL, NULL);
835 /* We abuse of suppress_handler, TRUE means OUTGOING. The channel
836 * will be catched in EmpathyFilter */
837 if (!tp_cli_connection_run_request_channel (connection, -1,
838 TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
845 DEBUG ("Couldn't request channel: %s",
846 error ? error->message : "No error given");
847 g_clear_error (&error);
848 g_object_unref (connection);
852 channel = tp_channel_new (connection,
853 object_path, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
854 TP_HANDLE_TYPE_NONE, 0, NULL);
856 group = empathy_tp_group_new (channel);
857 empathy_run_until_ready (group);
859 factory = empathy_contact_factory_new ();
860 self_contact = empathy_contact_factory_get_user (factory, account);
861 empathy_contact_run_until_ready (self_contact,
862 EMPATHY_CONTACT_READY_HANDLE,
865 empathy_tp_group_add_member (group, contact, "");
866 empathy_tp_group_add_member (group, self_contact, "");
868 g_object_unref (factory);
869 g_object_unref (self_contact);
870 g_object_unref (group);
871 g_object_unref (connection);
872 g_object_unref (channel);
873 g_free (object_path);
877 empathy_dispatcher_call_with_contact_id (McAccount *account, const gchar *contact_id)
879 EmpathyContactFactory *factory;
880 EmpathyContact *contact;
882 factory = empathy_contact_factory_new ();
883 contact = empathy_contact_factory_get_from_id (factory, account, contact_id);
884 empathy_contact_run_until_ready (contact, EMPATHY_CONTACT_READY_HANDLE, NULL);
886 empathy_dispatcher_call_with_contact (contact);
888 g_object_unref (contact);
889 g_object_unref (factory);
893 empathy_dispatcher_chat_with_contact (EmpathyContact *contact)
897 TpConnection *connection;
898 DispatcherRequestData *data;
900 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
902 mc = empathy_mission_control_new ();
903 account = empathy_contact_get_account (contact);
904 connection = mission_control_get_tpconnection (mc, account, NULL);
905 tp_connection_run_until_ready (connection, FALSE, NULL, NULL);
908 /* We abuse of suppress_handler, TRUE means OUTGOING. */
909 data = g_new (DispatcherRequestData, 1);
910 data->channel_type = TP_IFACE_CHANNEL_TYPE_TEXT;
911 data->handle_type = TP_HANDLE_TYPE_CONTACT;
912 data->handle = empathy_contact_get_handle (contact);
913 tp_cli_connection_call_request_channel (connection, -1,
918 dispatcher_request_channel_cb,
921 g_object_unref (connection);
925 empathy_dispatcher_chat_with_contact_id (McAccount *account,
926 const gchar *contact_id)
928 EmpathyContactFactory *factory;
929 EmpathyContact *contact;
931 factory = empathy_contact_factory_new ();
932 contact = empathy_contact_factory_get_from_id (factory, account, contact_id);
933 empathy_contact_run_until_ready (contact, EMPATHY_CONTACT_READY_HANDLE, NULL);
935 empathy_dispatcher_chat_with_contact (contact);
937 g_object_unref (contact);
938 g_object_unref (factory);