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 <telepathy-glib/telepathy-glib.h>
28 #include <extensions/extensions.h>
30 #include "empathy-tp-chat.h"
31 #include "empathy-tp-contact-factory.h"
32 #include "empathy-contact-monitor.h"
33 #include "empathy-contact-list.h"
34 #include "empathy-dispatcher.h"
35 #include "empathy-marshal.h"
36 #include "empathy-time.h"
37 #include "empathy-utils.h"
39 #define DEBUG_FLAG EMPATHY_DEBUG_TP | EMPATHY_DEBUG_CHAT
40 #include "empathy-debug.h"
42 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTpChat)
44 gboolean dispose_has_run;
45 EmpathyTpContactFactory *factory;
46 EmpathyContactMonitor *contact_monitor;
48 EmpathyContact *remote_contact;
51 gboolean listing_pending_messages;
52 /* Queue of messages not signalled yet */
53 GQueue *messages_queue;
54 /* Queue of messages signalled but not acked yet */
55 GQueue *pending_messages_queue;
56 gboolean had_properties_list;
57 GPtrArray *properties;
58 TpChannelPasswordFlags password_flags;
59 /* TRUE if we fetched the password flag of the channel or if it's not needed
60 * (channel doesn't implement the Password interface) */
61 gboolean got_password_flags;
63 gboolean can_upgrade_to_muc;
66 static void tp_chat_iface_init (EmpathyContactListIface *iface);
85 static guint signals[LAST_SIGNAL];
87 G_DEFINE_TYPE_WITH_CODE (EmpathyTpChat, empathy_tp_chat, G_TYPE_OBJECT,
88 G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CONTACT_LIST,
91 static void acknowledge_messages (EmpathyTpChat *chat, GArray *ids);
94 tp_chat_invalidated_cb (TpProxy *proxy,
100 DEBUG ("Channel invalidated: %s", message);
101 g_signal_emit (chat, signals[DESTROY], 0);
105 tp_chat_async_cb (TpChannel *proxy,
108 GObject *weak_object)
111 DEBUG ("Error %s: %s", (gchar *) user_data, error->message);
116 tp_chat_add (EmpathyContactList *list,
117 EmpathyContact *contact,
118 const gchar *message)
120 EmpathyTpChatPriv *priv = GET_PRIV (list);
122 if (tp_proxy_has_interface_by_id (priv->channel,
123 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
125 GArray handles = {(gchar *) &handle, 1};
127 g_return_if_fail (EMPATHY_IS_TP_CHAT (list));
128 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
130 handle = empathy_contact_get_handle (contact);
131 tp_cli_channel_interface_group_call_add_members (priv->channel,
132 -1, &handles, NULL, NULL, NULL, NULL, NULL);
133 } else if (priv->can_upgrade_to_muc) {
134 EmpathyDispatcher *dispatcher;
135 TpConnection *connection;
137 const char *object_path;
138 GPtrArray channels = { (gpointer *) &object_path, 1 };
139 const char *invitees[2] = { NULL, };
141 dispatcher = empathy_dispatcher_dup_singleton ();
142 connection = tp_channel_borrow_connection (priv->channel);
144 invitees[0] = empathy_contact_get_id (contact);
145 object_path = tp_proxy_get_object_path (priv->channel);
148 TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING,
149 TP_IFACE_CHANNEL_TYPE_TEXT,
150 TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_UINT,
152 EMP_IFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels",
153 TP_ARRAY_TYPE_OBJECT_PATH_LIST, &channels,
154 EMP_IFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialInviteeIDs",
155 G_TYPE_STRV, invitees,
156 /* FIXME: InvitationMessage ? */
159 /* Although this is a MUC, it's anonymous, so CreateChannel is
161 * props now belongs to EmpathyDispatcher, don't free it */
162 empathy_dispatcher_create_channel (dispatcher, connection,
165 g_object_unref (dispatcher);
167 g_warning ("Cannot add to this channel");
172 tp_chat_remove (EmpathyContactList *list,
173 EmpathyContact *contact,
174 const gchar *message)
176 EmpathyTpChatPriv *priv = GET_PRIV (list);
178 GArray handles = {(gchar *) &handle, 1};
180 g_return_if_fail (EMPATHY_IS_TP_CHAT (list));
181 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
183 handle = empathy_contact_get_handle (contact);
184 tp_cli_channel_interface_group_call_remove_members (priv->channel, -1,
191 tp_chat_get_members (EmpathyContactList *list)
193 EmpathyTpChatPriv *priv = GET_PRIV (list);
194 GList *members = NULL;
196 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (list), NULL);
199 members = g_list_copy (priv->members);
200 g_list_foreach (members, (GFunc) g_object_ref, NULL);
202 members = g_list_prepend (members, g_object_ref (priv->user));
203 if (priv->remote_contact != NULL)
204 members = g_list_prepend (members, g_object_ref (priv->remote_contact));
210 static EmpathyContactMonitor *
211 tp_chat_get_monitor (EmpathyContactList *list)
213 EmpathyTpChatPriv *priv;
215 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (list), NULL);
217 priv = GET_PRIV (list);
219 if (priv->contact_monitor == NULL) {
220 priv->contact_monitor = empathy_contact_monitor_new_for_iface (list);
223 return priv->contact_monitor;
227 tp_chat_emit_queued_messages (EmpathyTpChat *chat)
229 EmpathyTpChatPriv *priv = GET_PRIV (chat);
230 EmpathyMessage *message;
232 /* Check if we can now emit some queued messages */
233 while ((message = g_queue_peek_head (priv->messages_queue)) != NULL) {
234 if (empathy_message_get_sender (message) == NULL) {
238 DEBUG ("Queued message ready");
239 g_queue_pop_head (priv->messages_queue);
240 g_queue_push_tail (priv->pending_messages_queue, message);
241 g_signal_emit (chat, signals[MESSAGE_RECEIVED], 0, message);
246 tp_chat_got_sender_cb (EmpathyTpContactFactory *factory,
247 EmpathyContact *contact,
252 EmpathyTpChatPriv *priv = GET_PRIV (chat);
255 DEBUG ("Error: %s", error->message);
256 /* Do not block the message queue, just drop this message */
257 g_queue_remove (priv->messages_queue, message);
259 empathy_message_set_sender (message, contact);
262 tp_chat_emit_queued_messages (EMPATHY_TP_CHAT (chat));
266 tp_chat_build_message (EmpathyTpChat *chat,
272 const gchar *message_body,
273 TpChannelTextMessageFlags flags)
275 EmpathyTpChatPriv *priv;
276 EmpathyMessage *message;
278 priv = GET_PRIV (chat);
280 message = empathy_message_new (message_body);
281 empathy_message_set_tptype (message, type);
282 empathy_message_set_receiver (message, priv->user);
283 empathy_message_set_timestamp (message, timestamp);
284 empathy_message_set_id (message, id);
285 empathy_message_set_incoming (message, incoming);
286 empathy_message_set_flags (message, flags);
288 g_queue_push_tail (priv->messages_queue, message);
290 if (from_handle == 0) {
291 empathy_message_set_sender (message, priv->user);
292 tp_chat_emit_queued_messages (chat);
294 empathy_tp_contact_factory_get_from_handle (priv->factory,
296 tp_chat_got_sender_cb,
297 message, NULL, G_OBJECT (chat));
302 tp_chat_received_cb (TpChannel *channel,
308 const gchar *message_body,
312 EmpathyTpChat *chat = EMPATHY_TP_CHAT (chat_);
313 EmpathyTpChatPriv *priv = GET_PRIV (chat);
315 if (priv->channel == NULL)
318 if (priv->listing_pending_messages) {
322 DEBUG ("Message received: %s", message_body);
324 if (message_flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT &&
325 !tp_strdiff (message_body, "")) {
328 DEBUG ("Empty message with NonTextContent, ignoring and acking.");
330 ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
331 g_array_append_val (ids, message_id);
332 acknowledge_messages (chat, ids);
333 g_array_free (ids, TRUE);
338 tp_chat_build_message (chat,
349 tp_chat_sent_cb (TpChannel *channel,
352 const gchar *message_body,
356 EmpathyTpChat *chat = EMPATHY_TP_CHAT (chat_);
357 EmpathyTpChatPriv *priv = GET_PRIV (chat);
359 if (priv->channel == NULL)
362 DEBUG ("Message sent: %s", message_body);
364 tp_chat_build_message (chat,
375 tp_chat_send_error_cb (TpChannel *channel,
379 const gchar *message_body,
383 EmpathyTpChatPriv *priv = GET_PRIV (chat);
385 if (priv->channel == NULL)
388 DEBUG ("Error sending '%s' (%d)", message_body, error_code);
390 g_signal_emit (chat, signals[SEND_ERROR], 0, message_body, error_code);
394 tp_chat_send_cb (TpChannel *proxy,
399 EmpathyMessage *message = EMPATHY_MESSAGE (user_data);
402 DEBUG ("Error: %s", error->message);
403 g_signal_emit (chat, signals[SEND_ERROR], 0,
404 empathy_message_get_body (message),
405 TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN);
411 TpChannelChatState state;
415 tp_chat_state_changed_got_contact_cb (EmpathyTpContactFactory *factory,
416 EmpathyContact *contact,
421 TpChannelChatState state;
424 DEBUG ("Error: %s", error->message);
428 state = GPOINTER_TO_UINT (user_data);
429 DEBUG ("Chat state changed for %s (%d): %d",
430 empathy_contact_get_name (contact),
431 empathy_contact_get_handle (contact), state);
433 g_signal_emit (chat, signals[CHAT_STATE_CHANGED], 0, contact, state);
437 tp_chat_state_changed_cb (TpChannel *channel,
439 TpChannelChatState state,
443 EmpathyTpChatPriv *priv = GET_PRIV (chat);
445 empathy_tp_contact_factory_get_from_handle (priv->factory, handle,
446 tp_chat_state_changed_got_contact_cb, GUINT_TO_POINTER (state),
451 tp_chat_list_pending_messages_cb (TpChannel *channel,
452 const GPtrArray *messages_list,
457 EmpathyTpChat *chat = EMPATHY_TP_CHAT (chat_);
458 EmpathyTpChatPriv *priv = GET_PRIV (chat);
460 GArray *empty_non_text_content_ids = NULL;
462 priv->listing_pending_messages = FALSE;
464 if (priv->channel == NULL)
468 DEBUG ("Error listing pending messages: %s", error->message);
472 for (i = 0; i < messages_list->len; i++) {
473 GValueArray *message_struct;
474 const gchar *message_body;
481 message_struct = g_ptr_array_index (messages_list, i);
483 message_id = g_value_get_uint (g_value_array_get_nth (message_struct, 0));
484 timestamp = g_value_get_uint (g_value_array_get_nth (message_struct, 1));
485 from_handle = g_value_get_uint (g_value_array_get_nth (message_struct, 2));
486 message_type = g_value_get_uint (g_value_array_get_nth (message_struct, 3));
487 message_flags = g_value_get_uint (g_value_array_get_nth (message_struct, 4));
488 message_body = g_value_get_string (g_value_array_get_nth (message_struct, 5));
490 DEBUG ("Message pending: %s", message_body);
492 if (message_flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT &&
493 !tp_strdiff (message_body, "")) {
494 DEBUG ("Empty message with NonTextContent, ignoring and acking.");
496 if (empty_non_text_content_ids == NULL) {
497 empty_non_text_content_ids = g_array_new (FALSE, FALSE, sizeof (guint));
500 g_array_append_val (empty_non_text_content_ids, message_id);
504 tp_chat_build_message (chat,
514 if (empty_non_text_content_ids != NULL) {
515 acknowledge_messages (chat, empty_non_text_content_ids);
516 g_array_free (empty_non_text_content_ids, TRUE);
521 tp_chat_property_flags_changed_cb (TpProxy *proxy,
522 const GPtrArray *properties,
526 EmpathyTpChatPriv *priv = GET_PRIV (chat);
529 if (priv->channel == NULL)
532 if (!priv->had_properties_list || !properties) {
536 for (i = 0; i < properties->len; i++) {
537 GValueArray *prop_struct;
538 EmpathyTpChatProperty *property;
542 prop_struct = g_ptr_array_index (properties, i);
543 id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
544 flags = g_value_get_uint (g_value_array_get_nth (prop_struct, 1));
546 for (j = 0; j < priv->properties->len; j++) {
547 property = g_ptr_array_index (priv->properties, j);
548 if (property->id == id) {
549 property->flags = flags;
550 DEBUG ("property %s flags changed: %d",
551 property->name, property->flags);
559 tp_chat_properties_changed_cb (TpProxy *proxy,
560 const GPtrArray *properties,
564 EmpathyTpChatPriv *priv = GET_PRIV (chat);
567 if (priv->channel == NULL)
570 if (!priv->had_properties_list || !properties) {
574 for (i = 0; i < properties->len; i++) {
575 GValueArray *prop_struct;
576 EmpathyTpChatProperty *property;
580 prop_struct = g_ptr_array_index (properties, i);
581 id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
582 src_value = g_value_get_boxed (g_value_array_get_nth (prop_struct, 1));
584 for (j = 0; j < priv->properties->len; j++) {
585 property = g_ptr_array_index (priv->properties, j);
586 if (property->id == id) {
587 if (property->value) {
588 g_value_copy (src_value, property->value);
590 property->value = tp_g_value_slice_dup (src_value);
593 DEBUG ("property %s changed", property->name);
594 g_signal_emit (chat, signals[PROPERTY_CHANGED], 0,
595 property->name, property->value);
603 tp_chat_get_properties_cb (TpProxy *proxy,
604 const GPtrArray *properties,
610 DEBUG ("Error getting properties: %s", error->message);
614 tp_chat_properties_changed_cb (proxy, properties, user_data, chat);
618 tp_chat_list_properties_cb (TpProxy *proxy,
619 const GPtrArray *properties,
624 EmpathyTpChatPriv *priv = GET_PRIV (chat);
628 if (priv->channel == NULL)
631 priv->had_properties_list = TRUE;
634 DEBUG ("Error listing properties: %s", error->message);
638 ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), properties->len);
639 priv->properties = g_ptr_array_sized_new (properties->len);
640 for (i = 0; i < properties->len; i++) {
641 GValueArray *prop_struct;
642 EmpathyTpChatProperty *property;
644 prop_struct = g_ptr_array_index (properties, i);
645 property = g_slice_new0 (EmpathyTpChatProperty);
646 property->id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
647 property->name = g_value_dup_string (g_value_array_get_nth (prop_struct, 1));
648 property->flags = g_value_get_uint (g_value_array_get_nth (prop_struct, 3));
650 DEBUG ("Adding property name=%s id=%d flags=%d",
651 property->name, property->id, property->flags);
652 g_ptr_array_add (priv->properties, property);
653 if (property->flags & TP_PROPERTY_FLAG_READ) {
654 g_array_append_val (ids, property->id);
658 tp_cli_properties_interface_call_get_properties (proxy, -1,
660 tp_chat_get_properties_cb,
664 g_array_free (ids, TRUE);
668 empathy_tp_chat_set_property (EmpathyTpChat *chat,
672 EmpathyTpChatPriv *priv = GET_PRIV (chat);
673 EmpathyTpChatProperty *property;
676 if (!priv->had_properties_list) {
680 for (i = 0; i < priv->properties->len; i++) {
681 property = g_ptr_array_index (priv->properties, i);
682 if (!tp_strdiff (property->name, name)) {
683 GPtrArray *properties;
686 GValue dest_value = {0, };
688 if (!(property->flags & TP_PROPERTY_FLAG_WRITE)) {
692 g_value_init (&id, G_TYPE_UINT);
693 g_value_init (&dest_value, G_TYPE_VALUE);
694 g_value_set_uint (&id, property->id);
695 g_value_set_boxed (&dest_value, value);
697 prop = g_value_array_new (2);
698 g_value_array_append (prop, &id);
699 g_value_array_append (prop, &dest_value);
701 properties = g_ptr_array_sized_new (1);
702 g_ptr_array_add (properties, prop);
704 DEBUG ("Set property %s", name);
705 tp_cli_properties_interface_call_set_properties (priv->channel, -1,
707 (tp_cli_properties_interface_callback_for_set_properties)
709 "Seting property", NULL,
712 g_ptr_array_free (properties, TRUE);
713 g_value_array_free (prop);
720 EmpathyTpChatProperty *
721 empathy_tp_chat_get_property (EmpathyTpChat *chat,
724 EmpathyTpChatPriv *priv = GET_PRIV (chat);
725 EmpathyTpChatProperty *property;
728 if (!priv->had_properties_list) {
732 for (i = 0; i < priv->properties->len; i++) {
733 property = g_ptr_array_index (priv->properties, i);
734 if (!tp_strdiff (property->name, name)) {
743 empathy_tp_chat_get_properties (EmpathyTpChat *chat)
745 EmpathyTpChatPriv *priv = GET_PRIV (chat);
747 return priv->properties;
751 tp_chat_dispose (GObject *object)
753 EmpathyTpChat *self = EMPATHY_TP_CHAT (object);
754 EmpathyTpChatPriv *priv = GET_PRIV (self);
756 if (priv->dispose_has_run)
759 priv->dispose_has_run = TRUE;
761 if (priv->channel != NULL) {
762 g_signal_handlers_disconnect_by_func (priv->channel,
763 tp_chat_invalidated_cb, self);
764 g_object_unref (priv->channel);
766 priv->channel = NULL;
768 if (priv->remote_contact != NULL)
769 g_object_unref (priv->remote_contact);
770 priv->remote_contact = NULL;
772 if (priv->factory != NULL)
773 g_object_unref (priv->factory);
774 priv->factory = NULL;
776 if (priv->user != NULL)
777 g_object_unref (priv->user);
780 if (priv->contact_monitor)
781 g_object_unref (priv->contact_monitor);
782 priv->contact_monitor = NULL;
784 g_queue_foreach (priv->messages_queue, (GFunc) g_object_unref, NULL);
785 g_queue_clear (priv->messages_queue);
787 g_queue_foreach (priv->pending_messages_queue,
788 (GFunc) g_object_unref, NULL);
789 g_queue_clear (priv->pending_messages_queue);
791 if (G_OBJECT_CLASS (empathy_tp_chat_parent_class)->dispose)
792 G_OBJECT_CLASS (empathy_tp_chat_parent_class)->dispose (object);
796 tp_chat_finalize (GObject *object)
798 EmpathyTpChatPriv *priv = GET_PRIV (object);
801 DEBUG ("Finalize: %p", object);
803 if (priv->properties) {
804 for (i = 0; i < priv->properties->len; i++) {
805 EmpathyTpChatProperty *property;
807 property = g_ptr_array_index (priv->properties, i);
808 g_free (property->name);
809 if (property->value) {
810 tp_g_value_slice_free (property->value);
812 g_slice_free (EmpathyTpChatProperty, property);
814 g_ptr_array_free (priv->properties, TRUE);
817 g_queue_free (priv->messages_queue);
818 g_queue_free (priv->pending_messages_queue);
820 G_OBJECT_CLASS (empathy_tp_chat_parent_class)->finalize (object);
824 tp_chat_check_if_ready (EmpathyTpChat *chat)
826 EmpathyTpChatPriv *priv = GET_PRIV (chat);
831 if (priv->user == NULL)
834 if (!priv->got_password_flags)
837 /* We need either the members (room) or the remote contact (private chat).
838 * If the chat is protected by a password we can't get these information so
839 * consider the chat as ready so it can be presented to the user. */
840 if (!empathy_tp_chat_password_needed (chat) && priv->members == NULL &&
841 priv->remote_contact == NULL)
846 tp_cli_channel_type_text_connect_to_received (priv->channel,
849 G_OBJECT (chat), NULL);
850 priv->listing_pending_messages = TRUE;
851 tp_cli_channel_type_text_call_list_pending_messages (priv->channel, -1,
853 tp_chat_list_pending_messages_cb,
857 tp_cli_channel_type_text_connect_to_sent (priv->channel,
860 G_OBJECT (chat), NULL);
861 tp_cli_channel_type_text_connect_to_send_error (priv->channel,
862 tp_chat_send_error_cb,
864 G_OBJECT (chat), NULL);
865 tp_cli_channel_interface_chat_state_connect_to_chat_state_changed (priv->channel,
866 tp_chat_state_changed_cb,
868 G_OBJECT (chat), NULL);
870 g_object_notify (G_OBJECT (chat), "ready");
874 tp_chat_update_remote_contact (EmpathyTpChat *chat)
876 EmpathyTpChatPriv *priv = GET_PRIV (chat);
877 EmpathyContact *contact = NULL;
878 TpHandle self_handle;
879 TpHandleType handle_type;
882 /* If this is a named chatroom, never pretend it is a private chat */
883 tp_channel_get_handle (priv->channel, &handle_type);
884 if (handle_type == TP_HANDLE_TYPE_ROOM) {
888 /* This is an MSN-like chat where anyone can join the chat at anytime.
889 * If there is only one non-self contact member, we are in a private
890 * chat and we set the "remote-contact" property to that contact. If
891 * there are more, set the "remote-contact" property to NULL and the
892 * UI will display a contact list. */
893 self_handle = tp_channel_group_get_self_handle (priv->channel);
894 for (l = priv->members; l; l = l->next) {
895 /* Skip self contact if member */
896 if (empathy_contact_get_handle (l->data) == self_handle) {
900 /* We have more than one remote contact, break */
901 if (contact != NULL) {
906 /* If we didn't find yet a remote contact, keep this one */
910 if (priv->remote_contact == contact) {
914 DEBUG ("Changing remote contact from %p to %p",
915 priv->remote_contact, contact);
917 if (priv->remote_contact) {
918 g_object_unref (priv->remote_contact);
921 priv->remote_contact = contact ? g_object_ref (contact) : NULL;
922 g_object_notify (G_OBJECT (chat), "remote-contact");
926 tp_chat_got_added_contacts_cb (EmpathyTpContactFactory *factory,
928 EmpathyContact * const * contacts,
930 const TpHandle *failed,
935 EmpathyTpChatPriv *priv = GET_PRIV (chat);
937 const TpIntSet *members;
939 EmpathyContact *contact;
942 DEBUG ("Error: %s", error->message);
946 members = tp_channel_group_get_members (priv->channel);
947 for (i = 0; i < n_contacts; i++) {
948 contact = contacts[i];
949 handle = empathy_contact_get_handle (contact);
951 /* Make sure the contact is still member */
952 if (tp_intset_is_member (members, handle)) {
953 priv->members = g_list_prepend (priv->members,
954 g_object_ref (contact));
955 g_signal_emit_by_name (chat, "members-changed",
956 contact, NULL, 0, NULL, TRUE);
960 tp_chat_update_remote_contact (EMPATHY_TP_CHAT (chat));
961 tp_chat_check_if_ready (EMPATHY_TP_CHAT (chat));
964 static EmpathyContact *
965 chat_lookup_contact (EmpathyTpChat *chat,
969 EmpathyTpChatPriv *priv = GET_PRIV (chat);
972 for (l = priv->members; l; l = l->next) {
973 EmpathyContact *c = l->data;
975 if (empathy_contact_get_handle (c) != handle) {
980 /* Caller takes the reference. */
981 priv->members = g_list_delete_link (priv->members, l);
999 static ContactRenameData *
1000 contact_rename_data_new (TpHandle handle,
1002 const gchar* message)
1004 ContactRenameData *data = g_new (ContactRenameData, 1);
1005 data->old_handle = handle;
1006 data->reason = reason;
1007 data->message = g_strdup (message);
1013 contact_rename_data_free (ContactRenameData* data)
1015 g_free (data->message);
1020 tp_chat_got_renamed_contacts_cb (EmpathyTpContactFactory *factory,
1022 EmpathyContact * const * contacts,
1024 const TpHandle *failed,
1025 const GError *error,
1029 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1030 const TpIntSet *members;
1032 EmpathyContact *old = NULL, *new = NULL;
1033 ContactRenameData *rename_data = (ContactRenameData *) user_data;
1036 DEBUG ("Error: %s", error->message);
1040 /* renamed members can only be delivered one at a time */
1041 g_warn_if_fail (n_contacts == 1);
1045 members = tp_channel_group_get_members (priv->channel);
1046 handle = empathy_contact_get_handle (new);
1048 old = chat_lookup_contact (EMPATHY_TP_CHAT (chat),
1049 rename_data->old_handle, TRUE);
1051 /* Make sure the contact is still member */
1052 if (tp_intset_is_member (members, handle)) {
1053 priv->members = g_list_prepend (priv->members,
1054 g_object_ref (new));
1057 g_signal_emit_by_name (chat, "member-renamed",
1058 old, new, rename_data->reason,
1059 rename_data->message);
1060 g_object_unref (old);
1064 tp_chat_update_remote_contact (EMPATHY_TP_CHAT (chat));
1065 tp_chat_check_if_ready (EMPATHY_TP_CHAT (chat));
1070 tp_chat_group_members_changed_cb (TpChannel *self,
1074 GArray *local_pending,
1075 GArray *remote_pending,
1078 EmpathyTpChat *chat)
1080 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1081 EmpathyContact *contact;
1082 EmpathyContact *actor_contact = NULL;
1084 ContactRenameData *rename_data;
1085 TpHandle old_handle;
1087 /* Contact renamed */
1088 if (reason == TP_CHANNEL_GROUP_CHANGE_REASON_RENAMED) {
1089 /* there can only be a single 'added' and a single 'removed' handle */
1090 g_warn_if_fail (removed->len == 1);
1091 g_warn_if_fail (added->len == 1);
1093 old_handle = g_array_index (removed, guint, 0);
1095 rename_data = contact_rename_data_new (old_handle, reason, message);
1096 empathy_tp_contact_factory_get_from_handles (priv->factory,
1097 added->len, (TpHandle *) added->data,
1098 tp_chat_got_renamed_contacts_cb,
1099 rename_data, (GDestroyNotify) contact_rename_data_free,
1105 actor_contact = chat_lookup_contact (chat, actor, FALSE);
1106 if (actor_contact == NULL) {
1107 /* FIXME: handle this a tad more gracefully: perhaps
1108 * the actor was a server op. We could use the
1109 * contact-ids detail of MembersChangedDetailed.
1111 DEBUG ("actor %u not a channel member", actor);
1115 /* Remove contacts that are not members anymore */
1116 for (i = 0; i < removed->len; i++) {
1117 contact = chat_lookup_contact (chat,
1118 g_array_index (removed, TpHandle, i), TRUE);
1120 if (contact != NULL) {
1121 g_signal_emit_by_name (chat, "members-changed", contact,
1122 actor_contact, reason, message,
1124 g_object_unref (contact);
1128 /* Request added contacts */
1129 if (added->len > 0) {
1130 empathy_tp_contact_factory_get_from_handles (priv->factory,
1131 added->len, (TpHandle *) added->data,
1132 tp_chat_got_added_contacts_cb, NULL, NULL,
1136 tp_chat_update_remote_contact (chat);
1138 if (actor_contact != NULL) {
1139 g_object_unref (actor_contact);
1144 tp_chat_got_remote_contact_cb (EmpathyTpContactFactory *factory,
1145 EmpathyContact *contact,
1146 const GError *error,
1150 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1153 DEBUG ("Error: %s", error->message);
1154 empathy_tp_chat_leave (EMPATHY_TP_CHAT (chat));
1158 priv->remote_contact = g_object_ref (contact);
1159 g_object_notify (chat, "remote-contact");
1161 tp_chat_check_if_ready (EMPATHY_TP_CHAT (chat));
1165 tp_chat_got_self_contact_cb (EmpathyTpContactFactory *factory,
1166 EmpathyContact *contact,
1167 const GError *error,
1171 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1174 DEBUG ("Error: %s", error->message);
1175 empathy_tp_chat_leave (EMPATHY_TP_CHAT (chat));
1179 priv->user = g_object_ref (contact);
1180 empathy_contact_set_is_user (priv->user, TRUE);
1181 tp_chat_check_if_ready (EMPATHY_TP_CHAT (chat));
1185 password_flags_changed_cb (TpChannel *channel,
1189 GObject *weak_object)
1191 EmpathyTpChat *self = EMPATHY_TP_CHAT (weak_object);
1192 EmpathyTpChatPriv *priv = GET_PRIV (self);
1193 gboolean was_needed, needed;
1195 was_needed = empathy_tp_chat_password_needed (self);
1197 priv->password_flags |= added;
1198 priv->password_flags ^= removed;
1200 needed = empathy_tp_chat_password_needed (self);
1202 if (was_needed != needed)
1203 g_object_notify (G_OBJECT (self), "password-needed");
1207 got_password_flags_cb (TpChannel *proxy,
1208 guint password_flags,
1209 const GError *error,
1211 GObject *weak_object)
1213 EmpathyTpChat *self = EMPATHY_TP_CHAT (weak_object);
1214 EmpathyTpChatPriv *priv = GET_PRIV (self);
1216 priv->got_password_flags = TRUE;
1217 priv->password_flags = password_flags;
1219 tp_chat_check_if_ready (EMPATHY_TP_CHAT (self));
1223 tp_chat_constructor (GType type,
1225 GObjectConstructParam *props)
1228 EmpathyTpChatPriv *priv;
1229 TpConnection *connection;
1232 chat = G_OBJECT_CLASS (empathy_tp_chat_parent_class)->constructor (type, n_props, props);
1234 priv = GET_PRIV (chat);
1236 connection = tp_channel_borrow_connection (priv->channel);
1237 priv->factory = empathy_tp_contact_factory_dup_singleton (connection);
1238 g_signal_connect (priv->channel, "invalidated",
1239 G_CALLBACK (tp_chat_invalidated_cb),
1242 if (tp_proxy_has_interface_by_id (priv->channel,
1243 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
1244 const TpIntSet *members;
1247 /* Get self contact from the group's self handle */
1248 handle = tp_channel_group_get_self_handle (priv->channel);
1249 empathy_tp_contact_factory_get_from_handle (priv->factory,
1250 handle, tp_chat_got_self_contact_cb,
1253 /* Get initial member contacts */
1254 members = tp_channel_group_get_members (priv->channel);
1255 handles = tp_intset_to_array (members);
1256 empathy_tp_contact_factory_get_from_handles (priv->factory,
1257 handles->len, (TpHandle *) handles->data,
1258 tp_chat_got_added_contacts_cb, NULL, NULL, chat);
1260 priv->can_upgrade_to_muc = FALSE;
1262 g_signal_connect (priv->channel, "group-members-changed",
1263 G_CALLBACK (tp_chat_group_members_changed_cb), chat);
1265 EmpathyDispatcher *dispatcher = empathy_dispatcher_dup_singleton ();
1268 /* Get the self contact from the connection's self handle */
1269 handle = tp_connection_get_self_handle (connection);
1270 empathy_tp_contact_factory_get_from_handle (priv->factory,
1271 handle, tp_chat_got_self_contact_cb,
1274 /* Get the remote contact */
1275 handle = tp_channel_get_handle (priv->channel, NULL);
1276 empathy_tp_contact_factory_get_from_handle (priv->factory,
1277 handle, tp_chat_got_remote_contact_cb,
1280 list = empathy_dispatcher_find_requestable_channel_classes (
1281 dispatcher, connection,
1282 tp_channel_get_channel_type (priv->channel),
1283 TP_HANDLE_TYPE_ROOM, NULL);
1285 for (ptr = list; ptr; ptr = ptr->next) {
1286 GValueArray *array = ptr->data;
1287 const char **oprops = g_value_get_boxed (
1288 g_value_array_get_nth (array, 1));
1290 if (tp_strv_contains (oprops, EMP_IFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels")) {
1291 priv->can_upgrade_to_muc = TRUE;
1297 g_object_unref (dispatcher);
1300 if (tp_proxy_has_interface_by_id (priv->channel,
1301 TP_IFACE_QUARK_PROPERTIES_INTERFACE)) {
1302 tp_cli_properties_interface_call_list_properties (priv->channel, -1,
1303 tp_chat_list_properties_cb,
1306 tp_cli_properties_interface_connect_to_properties_changed (priv->channel,
1307 tp_chat_properties_changed_cb,
1309 G_OBJECT (chat), NULL);
1310 tp_cli_properties_interface_connect_to_property_flags_changed (priv->channel,
1311 tp_chat_property_flags_changed_cb,
1313 G_OBJECT (chat), NULL);
1316 /* Check if the chat is password protected */
1317 if (tp_proxy_has_interface_by_id (priv->channel,
1318 TP_IFACE_QUARK_CHANNEL_INTERFACE_PASSWORD)) {
1319 priv->got_password_flags = FALSE;
1321 tp_cli_channel_interface_password_connect_to_password_flags_changed
1322 (priv->channel, password_flags_changed_cb, chat, NULL,
1323 G_OBJECT (chat), NULL);
1325 tp_cli_channel_interface_password_call_get_password_flags
1326 (priv->channel, -1, got_password_flags_cb, chat, NULL, chat);
1328 /* No Password interface, so no need to fetch the password flags */
1329 priv->got_password_flags = TRUE;
1336 tp_chat_get_property (GObject *object,
1341 EmpathyTpChat *self = EMPATHY_TP_CHAT (object);
1342 EmpathyTpChatPriv *priv = GET_PRIV (object);
1346 g_value_set_object (value, priv->channel);
1348 case PROP_REMOTE_CONTACT:
1349 g_value_set_object (value, priv->remote_contact);
1352 g_value_set_boolean (value, priv->ready);
1354 case PROP_PASSWORD_NEEDED:
1355 g_value_set_boolean (value, empathy_tp_chat_password_needed (self));
1358 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1364 tp_chat_set_property (GObject *object,
1366 const GValue *value,
1369 EmpathyTpChatPriv *priv = GET_PRIV (object);
1373 priv->channel = g_value_dup_object (value);
1376 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1382 empathy_tp_chat_class_init (EmpathyTpChatClass *klass)
1384 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1386 object_class->dispose = tp_chat_dispose;
1387 object_class->finalize = tp_chat_finalize;
1388 object_class->constructor = tp_chat_constructor;
1389 object_class->get_property = tp_chat_get_property;
1390 object_class->set_property = tp_chat_set_property;
1392 g_object_class_install_property (object_class,
1394 g_param_spec_object ("channel",
1395 "telepathy channel",
1396 "The text channel for the chat",
1399 G_PARAM_CONSTRUCT_ONLY));
1401 g_object_class_install_property (object_class,
1402 PROP_REMOTE_CONTACT,
1403 g_param_spec_object ("remote-contact",
1404 "The remote contact",
1405 "The remote contact if there is no group iface on the channel",
1406 EMPATHY_TYPE_CONTACT,
1409 g_object_class_install_property (object_class,
1411 g_param_spec_boolean ("ready",
1412 "Is the object ready",
1413 "This object can't be used until this becomes true",
1417 g_object_class_install_property (object_class,
1418 PROP_PASSWORD_NEEDED,
1419 g_param_spec_boolean ("password-needed",
1421 "TRUE if a password is needed to join the channel",
1426 signals[MESSAGE_RECEIVED] =
1427 g_signal_new ("message-received",
1428 G_TYPE_FROM_CLASS (klass),
1432 g_cclosure_marshal_VOID__OBJECT,
1434 1, EMPATHY_TYPE_MESSAGE);
1436 signals[SEND_ERROR] =
1437 g_signal_new ("send-error",
1438 G_TYPE_FROM_CLASS (klass),
1442 _empathy_marshal_VOID__STRING_UINT,
1444 2, G_TYPE_STRING, G_TYPE_UINT);
1446 signals[CHAT_STATE_CHANGED] =
1447 g_signal_new ("chat-state-changed",
1448 G_TYPE_FROM_CLASS (klass),
1452 _empathy_marshal_VOID__OBJECT_UINT,
1454 2, EMPATHY_TYPE_CONTACT, G_TYPE_UINT);
1456 signals[PROPERTY_CHANGED] =
1457 g_signal_new ("property-changed",
1458 G_TYPE_FROM_CLASS (klass),
1462 _empathy_marshal_VOID__STRING_BOXED,
1464 2, G_TYPE_STRING, G_TYPE_VALUE);
1467 g_signal_new ("destroy",
1468 G_TYPE_FROM_CLASS (klass),
1472 g_cclosure_marshal_VOID__VOID,
1476 g_type_class_add_private (object_class, sizeof (EmpathyTpChatPriv));
1480 empathy_tp_chat_init (EmpathyTpChat *chat)
1482 EmpathyTpChatPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chat,
1483 EMPATHY_TYPE_TP_CHAT, EmpathyTpChatPriv);
1486 priv->contact_monitor = NULL;
1487 priv->messages_queue = g_queue_new ();
1488 priv->pending_messages_queue = g_queue_new ();
1492 tp_chat_iface_init (EmpathyContactListIface *iface)
1494 iface->add = tp_chat_add;
1495 iface->remove = tp_chat_remove;
1496 iface->get_members = tp_chat_get_members;
1497 iface->get_monitor = tp_chat_get_monitor;
1501 empathy_tp_chat_new (TpChannel *channel)
1503 return g_object_new (EMPATHY_TYPE_TP_CHAT,
1509 empathy_tp_chat_close (EmpathyTpChat *chat) {
1510 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1512 /* If there are still messages left, it'll come back..
1513 * We loose the ordering of sent messages though */
1514 tp_cli_channel_call_close (priv->channel, -1, tp_chat_async_cb,
1515 "closing channel", NULL, NULL);
1519 empathy_tp_chat_get_id (EmpathyTpChat *chat)
1521 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1525 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1527 id = tp_channel_get_identifier (priv->channel);
1528 if (!EMP_STR_EMPTY (id))
1530 else if (priv->remote_contact)
1531 return empathy_contact_get_id (priv->remote_contact);
1538 empathy_tp_chat_get_remote_contact (EmpathyTpChat *chat)
1540 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1542 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1543 g_return_val_if_fail (priv->ready, NULL);
1545 return priv->remote_contact;
1549 empathy_tp_chat_get_channel (EmpathyTpChat *chat)
1551 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1553 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1555 return priv->channel;
1559 empathy_tp_chat_get_connection (EmpathyTpChat *chat)
1561 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1563 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1565 return tp_channel_borrow_connection (priv->channel);
1569 empathy_tp_chat_is_ready (EmpathyTpChat *chat)
1571 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1573 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), FALSE);
1579 empathy_tp_chat_send (EmpathyTpChat *chat,
1580 EmpathyMessage *message)
1582 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1583 const gchar *message_body;
1584 TpChannelTextMessageType message_type;
1586 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1587 g_return_if_fail (EMPATHY_IS_MESSAGE (message));
1588 g_return_if_fail (priv->ready);
1590 message_body = empathy_message_get_body (message);
1591 message_type = empathy_message_get_tptype (message);
1593 DEBUG ("Sending message: %s", message_body);
1594 tp_cli_channel_type_text_call_send (priv->channel, -1,
1598 g_object_ref (message),
1599 (GDestroyNotify) g_object_unref,
1604 empathy_tp_chat_set_state (EmpathyTpChat *chat,
1605 TpChannelChatState state)
1607 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1609 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1610 g_return_if_fail (priv->ready);
1612 if (tp_proxy_has_interface_by_id (priv->channel,
1613 TP_IFACE_QUARK_CHANNEL_INTERFACE_CHAT_STATE)) {
1614 DEBUG ("Set state: %d", state);
1615 tp_cli_channel_interface_chat_state_call_set_chat_state (priv->channel, -1,
1618 "setting chat state",
1626 empathy_tp_chat_get_pending_messages (EmpathyTpChat *chat)
1628 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1630 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1631 g_return_val_if_fail (priv->ready, NULL);
1633 return priv->pending_messages_queue->head;
1637 acknowledge_messages (EmpathyTpChat *chat, GArray *ids) {
1638 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1640 tp_cli_channel_type_text_call_acknowledge_pending_messages (
1641 priv->channel, -1, ids, tp_chat_async_cb,
1642 "acknowledging received message", NULL, G_OBJECT (chat));
1646 empathy_tp_chat_acknowledge_message (EmpathyTpChat *chat,
1647 EmpathyMessage *message) {
1648 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1649 GArray *message_ids;
1653 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1654 g_return_if_fail (priv->ready);
1656 if (!empathy_message_is_incoming (message))
1659 message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
1661 id = empathy_message_get_id (message);
1662 g_array_append_val (message_ids, id);
1663 acknowledge_messages (chat, message_ids);
1664 g_array_free (message_ids, TRUE);
1667 m = g_queue_find (priv->pending_messages_queue, message);
1668 g_assert (m != NULL);
1669 g_queue_delete_link (priv->pending_messages_queue, m);
1670 g_object_unref (message);
1674 empathy_tp_chat_acknowledge_messages (EmpathyTpChat *chat,
1675 const GSList *messages) {
1676 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1677 /* Copy messages as the messges list (probably is) our own */
1678 GSList *msgs = g_slist_copy ((GSList *) messages);
1681 GArray *message_ids;
1683 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1684 g_return_if_fail (priv->ready);
1686 length = g_slist_length ((GSList *) messages);
1691 message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), length);
1693 for (l = msgs; l != NULL; l = g_slist_next (l)) {
1696 EmpathyMessage *message = EMPATHY_MESSAGE (l->data);
1698 m = g_queue_find (priv->pending_messages_queue, message);
1699 g_assert (m != NULL);
1700 g_queue_delete_link (priv->pending_messages_queue, m);
1702 if (empathy_message_is_incoming (message)) {
1703 guint id = empathy_message_get_id (message);
1704 g_array_append_val (message_ids, id);
1706 g_object_unref (message);
1709 if (message_ids->len > 0)
1710 acknowledge_messages (chat, message_ids);
1712 g_array_free (message_ids, TRUE);
1713 g_slist_free (msgs);
1717 empathy_tp_chat_acknowledge_all_messages (EmpathyTpChat *chat)
1719 empathy_tp_chat_acknowledge_messages (chat,
1720 (GSList *) empathy_tp_chat_get_pending_messages (chat));
1724 empathy_tp_chat_password_needed (EmpathyTpChat *self)
1726 EmpathyTpChatPriv *priv = GET_PRIV (self);
1728 return priv->password_flags & TP_CHANNEL_PASSWORD_FLAG_PROVIDE;
1732 provide_password_cb (TpChannel *channel,
1734 const GError *error,
1736 GObject *weak_object)
1738 GSimpleAsyncResult *result = user_data;
1740 if (error != NULL) {
1741 g_simple_async_result_set_from_error (result, error);
1743 else if (!correct) {
1744 /* The current D-Bus API is a bit weird so re-use the
1745 * AuthenticationFailed error */
1746 g_simple_async_result_set_error (result, TP_ERRORS,
1747 TP_ERROR_AUTHENTICATION_FAILED, "Wrong password");
1750 g_simple_async_result_complete (result);
1751 g_object_unref (result);
1755 empathy_tp_chat_provide_password_async (EmpathyTpChat *self,
1756 const gchar *password,
1757 GAsyncReadyCallback callback,
1760 EmpathyTpChatPriv *priv = GET_PRIV (self);
1761 GSimpleAsyncResult *result;
1763 result = g_simple_async_result_new (G_OBJECT (self),
1764 callback, user_data,
1765 empathy_tp_chat_provide_password_finish);
1767 tp_cli_channel_interface_password_call_provide_password
1768 (priv->channel, -1, password, provide_password_cb, result,
1769 NULL, G_OBJECT (self));
1773 empathy_tp_chat_provide_password_finish (EmpathyTpChat *self,
1774 GAsyncResult *result,
1777 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1781 g_return_val_if_fail (g_simple_async_result_is_valid (result,
1782 G_OBJECT (self), empathy_tp_chat_provide_password_finish), FALSE);
1788 * empathy_tp_chat_can_add_contact:
1790 * Returns: %TRUE if empathy_contact_list_add() will work for this channel.
1791 * That is if this chat is a 1-to-1 channel that can be upgraded to
1792 * a MUC using the Conference interface or if the channel is a MUC.
1795 empathy_tp_chat_can_add_contact (EmpathyTpChat *self)
1797 EmpathyTpChatPriv *priv;
1799 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (self), FALSE);
1801 priv = GET_PRIV (self);
1803 return priv->can_upgrade_to_muc ||
1804 tp_proxy_has_interface_by_id (priv->channel,
1805 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP);;
1809 leave_remove_members_cb (TpChannel *proxy,
1810 const GError *error,
1812 GObject *weak_object)
1814 EmpathyTpChat *self = user_data;
1819 DEBUG ("RemoveMembers failed (%s); closing the channel", error->message);
1820 empathy_tp_chat_close (self);
1824 empathy_tp_chat_leave (EmpathyTpChat *self)
1826 EmpathyTpChatPriv *priv = GET_PRIV (self);
1827 TpHandle self_handle;
1830 if (!tp_proxy_has_interface_by_id (priv->channel,
1831 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
1832 empathy_tp_chat_close (self);
1836 self_handle = tp_channel_group_get_self_handle (priv->channel);
1837 if (self_handle == 0) {
1838 /* we are not member of the channel */
1839 empathy_tp_chat_close (self);
1843 array = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), 1);
1844 g_array_insert_val (array, 0, self_handle);
1846 tp_cli_channel_interface_group_call_remove_members (priv->channel, -1, array,
1847 "", leave_remove_members_cb, self, NULL, G_OBJECT (self));
1849 g_array_free (array, TRUE);