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-list.h"
33 #include "empathy-dispatcher.h"
34 #include "empathy-marshal.h"
35 #include "empathy-time.h"
36 #include "empathy-utils.h"
38 #define DEBUG_FLAG EMPATHY_DEBUG_TP | EMPATHY_DEBUG_CHAT
39 #include "empathy-debug.h"
41 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTpChat)
43 gboolean dispose_has_run;
44 TpConnection *connection;
46 EmpathyContact *remote_contact;
49 gboolean listing_pending_messages;
50 /* Queue of messages not signalled yet */
51 GQueue *messages_queue;
52 /* Queue of messages signalled but not acked yet */
53 GQueue *pending_messages_queue;
54 gboolean had_properties_list;
55 GPtrArray *properties;
56 TpChannelPasswordFlags password_flags;
57 /* TRUE if we fetched the password flag of the channel or if it's not needed
58 * (channel doesn't implement the Password interface) */
59 gboolean got_password_flags;
61 gboolean can_upgrade_to_muc;
64 static void tp_chat_iface_init (EmpathyContactListIface *iface);
83 static guint signals[LAST_SIGNAL];
85 G_DEFINE_TYPE_WITH_CODE (EmpathyTpChat, empathy_tp_chat, G_TYPE_OBJECT,
86 G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CONTACT_LIST,
89 static void acknowledge_messages (EmpathyTpChat *chat, GArray *ids);
92 tp_chat_invalidated_cb (TpProxy *proxy,
98 DEBUG ("Channel invalidated: %s", message);
99 g_signal_emit (chat, signals[DESTROY], 0);
103 tp_chat_async_cb (TpChannel *proxy,
106 GObject *weak_object)
109 DEBUG ("Error %s: %s", (gchar *) user_data, error->message);
114 tp_chat_add (EmpathyContactList *list,
115 EmpathyContact *contact,
116 const gchar *message)
118 EmpathyTpChatPriv *priv = GET_PRIV (list);
120 if (tp_proxy_has_interface_by_id (priv->channel,
121 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
123 GArray handles = {(gchar *) &handle, 1};
125 g_return_if_fail (EMPATHY_IS_TP_CHAT (list));
126 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
128 handle = empathy_contact_get_handle (contact);
129 tp_cli_channel_interface_group_call_add_members (priv->channel,
130 -1, &handles, NULL, NULL, NULL, NULL, NULL);
131 } else if (priv->can_upgrade_to_muc) {
132 EmpathyDispatcher *dispatcher;
134 const char *object_path;
135 GPtrArray channels = { (gpointer *) &object_path, 1 };
136 const char *invitees[2] = { NULL, };
138 dispatcher = empathy_dispatcher_dup_singleton ();
140 invitees[0] = empathy_contact_get_id (contact);
141 object_path = tp_proxy_get_object_path (priv->channel);
144 TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING,
145 TP_IFACE_CHANNEL_TYPE_TEXT,
146 TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_UINT,
148 EMP_IFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels",
149 TP_ARRAY_TYPE_OBJECT_PATH_LIST, &channels,
150 EMP_IFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialInviteeIDs",
151 G_TYPE_STRV, invitees,
152 /* FIXME: InvitationMessage ? */
155 /* Although this is a MUC, it's anonymous, so CreateChannel is
157 * props now belongs to EmpathyDispatcher, don't free it */
158 empathy_dispatcher_create_channel (dispatcher, priv->connection,
159 props, EMPATHY_DISPATCHER_NON_USER_ACTION, NULL, NULL);
161 g_object_unref (dispatcher);
163 g_warning ("Cannot add to this channel");
168 tp_chat_remove (EmpathyContactList *list,
169 EmpathyContact *contact,
170 const gchar *message)
172 EmpathyTpChatPriv *priv = GET_PRIV (list);
174 GArray handles = {(gchar *) &handle, 1};
176 g_return_if_fail (EMPATHY_IS_TP_CHAT (list));
177 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
179 handle = empathy_contact_get_handle (contact);
180 tp_cli_channel_interface_group_call_remove_members (priv->channel, -1,
187 tp_chat_get_members (EmpathyContactList *list)
189 EmpathyTpChatPriv *priv = GET_PRIV (list);
190 GList *members = NULL;
192 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (list), NULL);
195 members = g_list_copy (priv->members);
196 g_list_foreach (members, (GFunc) g_object_ref, NULL);
198 members = g_list_prepend (members, g_object_ref (priv->user));
199 if (priv->remote_contact != NULL)
200 members = g_list_prepend (members, g_object_ref (priv->remote_contact));
207 tp_chat_emit_queued_messages (EmpathyTpChat *chat)
209 EmpathyTpChatPriv *priv = GET_PRIV (chat);
210 EmpathyMessage *message;
212 /* Check if we can now emit some queued messages */
213 while ((message = g_queue_peek_head (priv->messages_queue)) != NULL) {
214 if (empathy_message_get_sender (message) == NULL) {
218 DEBUG ("Queued message ready");
219 g_queue_pop_head (priv->messages_queue);
220 g_queue_push_tail (priv->pending_messages_queue, message);
221 g_signal_emit (chat, signals[MESSAGE_RECEIVED], 0, message);
226 tp_chat_got_sender_cb (TpConnection *connection,
227 EmpathyContact *contact,
232 EmpathyTpChatPriv *priv = GET_PRIV (chat);
235 DEBUG ("Error: %s", error->message);
236 /* Do not block the message queue, just drop this message */
237 g_queue_remove (priv->messages_queue, message);
239 empathy_message_set_sender (message, contact);
242 tp_chat_emit_queued_messages (EMPATHY_TP_CHAT (chat));
246 tp_chat_build_message (EmpathyTpChat *chat,
252 const gchar *message_body,
253 TpChannelTextMessageFlags flags)
255 EmpathyTpChatPriv *priv;
256 EmpathyMessage *message;
258 priv = GET_PRIV (chat);
260 message = empathy_message_new (message_body);
261 empathy_message_set_tptype (message, type);
262 empathy_message_set_receiver (message, priv->user);
263 empathy_message_set_timestamp (message, timestamp);
264 empathy_message_set_id (message, id);
265 empathy_message_set_incoming (message, incoming);
266 empathy_message_set_flags (message, flags);
268 g_queue_push_tail (priv->messages_queue, message);
270 if (from_handle == 0) {
271 empathy_message_set_sender (message, priv->user);
272 tp_chat_emit_queued_messages (chat);
274 empathy_tp_contact_factory_get_from_handle (priv->connection,
276 tp_chat_got_sender_cb,
277 message, NULL, G_OBJECT (chat));
282 tp_chat_received_cb (TpChannel *channel,
288 const gchar *message_body,
292 EmpathyTpChat *chat = EMPATHY_TP_CHAT (chat_);
293 EmpathyTpChatPriv *priv = GET_PRIV (chat);
295 if (priv->channel == NULL)
298 if (priv->listing_pending_messages) {
302 DEBUG ("Message received: %s", message_body);
304 if (message_flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT &&
305 !tp_strdiff (message_body, "")) {
308 DEBUG ("Empty message with NonTextContent, ignoring and acking.");
310 ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
311 g_array_append_val (ids, message_id);
312 acknowledge_messages (chat, ids);
313 g_array_free (ids, TRUE);
318 tp_chat_build_message (chat,
329 tp_chat_sent_cb (TpChannel *channel,
332 const gchar *message_body,
336 EmpathyTpChat *chat = EMPATHY_TP_CHAT (chat_);
337 EmpathyTpChatPriv *priv = GET_PRIV (chat);
339 if (priv->channel == NULL)
342 DEBUG ("Message sent: %s", message_body);
344 tp_chat_build_message (chat,
355 tp_chat_send_error_cb (TpChannel *channel,
359 const gchar *message_body,
363 EmpathyTpChatPriv *priv = GET_PRIV (chat);
365 if (priv->channel == NULL)
368 DEBUG ("Error sending '%s' (%d)", message_body, error_code);
370 g_signal_emit (chat, signals[SEND_ERROR], 0, message_body, error_code);
374 tp_chat_send_cb (TpChannel *proxy,
379 EmpathyMessage *message = EMPATHY_MESSAGE (user_data);
382 DEBUG ("Error: %s", error->message);
383 g_signal_emit (chat, signals[SEND_ERROR], 0,
384 empathy_message_get_body (message),
385 TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN);
391 TpChannelChatState state;
395 tp_chat_state_changed_got_contact_cb (TpConnection *connection,
396 EmpathyContact *contact,
401 TpChannelChatState state;
404 DEBUG ("Error: %s", error->message);
408 state = GPOINTER_TO_UINT (user_data);
409 DEBUG ("Chat state changed for %s (%d): %d",
410 empathy_contact_get_name (contact),
411 empathy_contact_get_handle (contact), state);
413 g_signal_emit (chat, signals[CHAT_STATE_CHANGED], 0, contact, state);
417 tp_chat_state_changed_cb (TpChannel *channel,
419 TpChannelChatState state,
423 EmpathyTpChatPriv *priv = GET_PRIV (chat);
425 empathy_tp_contact_factory_get_from_handle (priv->connection, handle,
426 tp_chat_state_changed_got_contact_cb, GUINT_TO_POINTER (state),
431 tp_chat_list_pending_messages_cb (TpChannel *channel,
432 const GPtrArray *messages_list,
437 EmpathyTpChat *chat = EMPATHY_TP_CHAT (chat_);
438 EmpathyTpChatPriv *priv = GET_PRIV (chat);
440 GArray *empty_non_text_content_ids = NULL;
442 priv->listing_pending_messages = FALSE;
444 if (priv->channel == NULL)
448 DEBUG ("Error listing pending messages: %s", error->message);
452 for (i = 0; i < messages_list->len; i++) {
453 GValueArray *message_struct;
454 const gchar *message_body;
461 message_struct = g_ptr_array_index (messages_list, i);
463 message_id = g_value_get_uint (g_value_array_get_nth (message_struct, 0));
464 timestamp = g_value_get_uint (g_value_array_get_nth (message_struct, 1));
465 from_handle = g_value_get_uint (g_value_array_get_nth (message_struct, 2));
466 message_type = g_value_get_uint (g_value_array_get_nth (message_struct, 3));
467 message_flags = g_value_get_uint (g_value_array_get_nth (message_struct, 4));
468 message_body = g_value_get_string (g_value_array_get_nth (message_struct, 5));
470 DEBUG ("Message pending: %s", message_body);
472 if (message_flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT &&
473 !tp_strdiff (message_body, "")) {
474 DEBUG ("Empty message with NonTextContent, ignoring and acking.");
476 if (empty_non_text_content_ids == NULL) {
477 empty_non_text_content_ids = g_array_new (FALSE, FALSE, sizeof (guint));
480 g_array_append_val (empty_non_text_content_ids, message_id);
484 tp_chat_build_message (chat,
494 if (empty_non_text_content_ids != NULL) {
495 acknowledge_messages (chat, empty_non_text_content_ids);
496 g_array_free (empty_non_text_content_ids, TRUE);
501 tp_chat_property_flags_changed_cb (TpProxy *proxy,
502 const GPtrArray *properties,
506 EmpathyTpChatPriv *priv = GET_PRIV (chat);
509 if (priv->channel == NULL)
512 if (!priv->had_properties_list || !properties) {
516 for (i = 0; i < properties->len; i++) {
517 GValueArray *prop_struct;
518 EmpathyTpChatProperty *property;
522 prop_struct = g_ptr_array_index (properties, i);
523 id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
524 flags = g_value_get_uint (g_value_array_get_nth (prop_struct, 1));
526 for (j = 0; j < priv->properties->len; j++) {
527 property = g_ptr_array_index (priv->properties, j);
528 if (property->id == id) {
529 property->flags = flags;
530 DEBUG ("property %s flags changed: %d",
531 property->name, property->flags);
539 tp_chat_properties_changed_cb (TpProxy *proxy,
540 const GPtrArray *properties,
544 EmpathyTpChatPriv *priv = GET_PRIV (chat);
547 if (priv->channel == NULL)
550 if (!priv->had_properties_list || !properties) {
554 for (i = 0; i < properties->len; i++) {
555 GValueArray *prop_struct;
556 EmpathyTpChatProperty *property;
560 prop_struct = g_ptr_array_index (properties, i);
561 id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
562 src_value = g_value_get_boxed (g_value_array_get_nth (prop_struct, 1));
564 for (j = 0; j < priv->properties->len; j++) {
565 property = g_ptr_array_index (priv->properties, j);
566 if (property->id == id) {
567 if (property->value) {
568 g_value_copy (src_value, property->value);
570 property->value = tp_g_value_slice_dup (src_value);
573 DEBUG ("property %s changed", property->name);
574 g_signal_emit (chat, signals[PROPERTY_CHANGED], 0,
575 property->name, property->value);
583 tp_chat_get_properties_cb (TpProxy *proxy,
584 const GPtrArray *properties,
590 DEBUG ("Error getting properties: %s", error->message);
594 tp_chat_properties_changed_cb (proxy, properties, user_data, chat);
598 tp_chat_list_properties_cb (TpProxy *proxy,
599 const GPtrArray *properties,
604 EmpathyTpChatPriv *priv = GET_PRIV (chat);
608 if (priv->channel == NULL)
611 priv->had_properties_list = TRUE;
614 DEBUG ("Error listing properties: %s", error->message);
618 ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), properties->len);
619 priv->properties = g_ptr_array_sized_new (properties->len);
620 for (i = 0; i < properties->len; i++) {
621 GValueArray *prop_struct;
622 EmpathyTpChatProperty *property;
624 prop_struct = g_ptr_array_index (properties, i);
625 property = g_slice_new0 (EmpathyTpChatProperty);
626 property->id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
627 property->name = g_value_dup_string (g_value_array_get_nth (prop_struct, 1));
628 property->flags = g_value_get_uint (g_value_array_get_nth (prop_struct, 3));
630 DEBUG ("Adding property name=%s id=%d flags=%d",
631 property->name, property->id, property->flags);
632 g_ptr_array_add (priv->properties, property);
633 if (property->flags & TP_PROPERTY_FLAG_READ) {
634 g_array_append_val (ids, property->id);
638 tp_cli_properties_interface_call_get_properties (proxy, -1,
640 tp_chat_get_properties_cb,
644 g_array_free (ids, TRUE);
648 empathy_tp_chat_set_property (EmpathyTpChat *chat,
652 EmpathyTpChatPriv *priv = GET_PRIV (chat);
653 EmpathyTpChatProperty *property;
656 if (!priv->had_properties_list) {
660 for (i = 0; i < priv->properties->len; i++) {
661 property = g_ptr_array_index (priv->properties, i);
662 if (!tp_strdiff (property->name, name)) {
663 GPtrArray *properties;
666 GValue dest_value = {0, };
668 if (!(property->flags & TP_PROPERTY_FLAG_WRITE)) {
672 g_value_init (&id, G_TYPE_UINT);
673 g_value_init (&dest_value, G_TYPE_VALUE);
674 g_value_set_uint (&id, property->id);
675 g_value_set_boxed (&dest_value, value);
677 prop = g_value_array_new (2);
678 g_value_array_append (prop, &id);
679 g_value_array_append (prop, &dest_value);
681 properties = g_ptr_array_sized_new (1);
682 g_ptr_array_add (properties, prop);
684 DEBUG ("Set property %s", name);
685 tp_cli_properties_interface_call_set_properties (priv->channel, -1,
687 (tp_cli_properties_interface_callback_for_set_properties)
689 "Seting property", NULL,
692 g_ptr_array_free (properties, TRUE);
693 g_value_array_free (prop);
700 EmpathyTpChatProperty *
701 empathy_tp_chat_get_property (EmpathyTpChat *chat,
704 EmpathyTpChatPriv *priv = GET_PRIV (chat);
705 EmpathyTpChatProperty *property;
708 if (!priv->had_properties_list) {
712 for (i = 0; i < priv->properties->len; i++) {
713 property = g_ptr_array_index (priv->properties, i);
714 if (!tp_strdiff (property->name, name)) {
723 empathy_tp_chat_get_properties (EmpathyTpChat *chat)
725 EmpathyTpChatPriv *priv = GET_PRIV (chat);
727 return priv->properties;
731 tp_chat_dispose (GObject *object)
733 EmpathyTpChat *self = EMPATHY_TP_CHAT (object);
734 EmpathyTpChatPriv *priv = GET_PRIV (self);
736 if (priv->dispose_has_run)
739 priv->dispose_has_run = TRUE;
741 if (priv->connection != NULL)
742 g_object_unref (priv->connection);
743 priv->connection = NULL;
745 if (priv->channel != NULL) {
746 g_signal_handlers_disconnect_by_func (priv->channel,
747 tp_chat_invalidated_cb, self);
748 g_object_unref (priv->channel);
750 priv->channel = NULL;
752 if (priv->remote_contact != NULL)
753 g_object_unref (priv->remote_contact);
754 priv->remote_contact = NULL;
756 if (priv->user != NULL)
757 g_object_unref (priv->user);
760 g_queue_foreach (priv->messages_queue, (GFunc) g_object_unref, NULL);
761 g_queue_clear (priv->messages_queue);
763 g_queue_foreach (priv->pending_messages_queue,
764 (GFunc) g_object_unref, NULL);
765 g_queue_clear (priv->pending_messages_queue);
767 if (G_OBJECT_CLASS (empathy_tp_chat_parent_class)->dispose)
768 G_OBJECT_CLASS (empathy_tp_chat_parent_class)->dispose (object);
772 tp_chat_finalize (GObject *object)
774 EmpathyTpChatPriv *priv = GET_PRIV (object);
777 DEBUG ("Finalize: %p", object);
779 if (priv->properties) {
780 for (i = 0; i < priv->properties->len; i++) {
781 EmpathyTpChatProperty *property;
783 property = g_ptr_array_index (priv->properties, i);
784 g_free (property->name);
785 if (property->value) {
786 tp_g_value_slice_free (property->value);
788 g_slice_free (EmpathyTpChatProperty, property);
790 g_ptr_array_free (priv->properties, TRUE);
793 g_queue_free (priv->messages_queue);
794 g_queue_free (priv->pending_messages_queue);
796 G_OBJECT_CLASS (empathy_tp_chat_parent_class)->finalize (object);
800 tp_chat_check_if_ready (EmpathyTpChat *chat)
802 EmpathyTpChatPriv *priv = GET_PRIV (chat);
807 if (priv->user == NULL)
810 if (!priv->got_password_flags)
813 /* We need either the members (room) or the remote contact (private chat).
814 * If the chat is protected by a password we can't get these information so
815 * consider the chat as ready so it can be presented to the user. */
816 if (!empathy_tp_chat_password_needed (chat) && priv->members == NULL &&
817 priv->remote_contact == NULL)
822 tp_cli_channel_type_text_connect_to_received (priv->channel,
825 G_OBJECT (chat), NULL);
826 priv->listing_pending_messages = TRUE;
827 tp_cli_channel_type_text_call_list_pending_messages (priv->channel, -1,
829 tp_chat_list_pending_messages_cb,
833 tp_cli_channel_type_text_connect_to_sent (priv->channel,
836 G_OBJECT (chat), NULL);
837 tp_cli_channel_type_text_connect_to_send_error (priv->channel,
838 tp_chat_send_error_cb,
840 G_OBJECT (chat), NULL);
841 tp_cli_channel_interface_chat_state_connect_to_chat_state_changed (priv->channel,
842 tp_chat_state_changed_cb,
844 G_OBJECT (chat), NULL);
846 g_object_notify (G_OBJECT (chat), "ready");
850 tp_chat_update_remote_contact (EmpathyTpChat *chat)
852 EmpathyTpChatPriv *priv = GET_PRIV (chat);
853 EmpathyContact *contact = NULL;
854 TpHandle self_handle;
855 TpHandleType handle_type;
858 /* If this is a named chatroom, never pretend it is a private chat */
859 tp_channel_get_handle (priv->channel, &handle_type);
860 if (handle_type == TP_HANDLE_TYPE_ROOM) {
864 /* This is an MSN chat, but it's the new style where 1-1 chats don't
865 * have the group interface. If it has the conference interface, then
866 * it is indeed a MUC. */
867 if (tp_proxy_has_interface_by_id (priv->channel,
868 EMP_IFACE_QUARK_CHANNEL_INTERFACE_CONFERENCE)) {
872 /* This is an MSN-like chat where anyone can join the chat at anytime.
873 * If there is only one non-self contact member, we are in a private
874 * chat and we set the "remote-contact" property to that contact. If
875 * there are more, set the "remote-contact" property to NULL and the
876 * UI will display a contact list. */
877 self_handle = tp_channel_group_get_self_handle (priv->channel);
878 for (l = priv->members; l; l = l->next) {
879 /* Skip self contact if member */
880 if (empathy_contact_get_handle (l->data) == self_handle) {
884 /* We have more than one remote contact, break */
885 if (contact != NULL) {
890 /* If we didn't find yet a remote contact, keep this one */
894 if (priv->remote_contact == contact) {
898 DEBUG ("Changing remote contact from %p to %p",
899 priv->remote_contact, contact);
901 if (priv->remote_contact) {
902 g_object_unref (priv->remote_contact);
905 priv->remote_contact = contact ? g_object_ref (contact) : NULL;
906 g_object_notify (G_OBJECT (chat), "remote-contact");
910 tp_chat_got_added_contacts_cb (TpConnection *connection,
912 EmpathyContact * const * contacts,
914 const TpHandle *failed,
919 EmpathyTpChatPriv *priv = GET_PRIV (chat);
921 const TpIntSet *members;
923 EmpathyContact *contact;
926 DEBUG ("Error: %s", error->message);
930 members = tp_channel_group_get_members (priv->channel);
931 for (i = 0; i < n_contacts; i++) {
932 contact = contacts[i];
933 handle = empathy_contact_get_handle (contact);
935 /* Make sure the contact is still member */
936 if (tp_intset_is_member (members, handle)) {
937 priv->members = g_list_prepend (priv->members,
938 g_object_ref (contact));
939 g_signal_emit_by_name (chat, "members-changed",
940 contact, NULL, 0, NULL, TRUE);
944 tp_chat_update_remote_contact (EMPATHY_TP_CHAT (chat));
945 tp_chat_check_if_ready (EMPATHY_TP_CHAT (chat));
948 static EmpathyContact *
949 chat_lookup_contact (EmpathyTpChat *chat,
953 EmpathyTpChatPriv *priv = GET_PRIV (chat);
956 for (l = priv->members; l; l = l->next) {
957 EmpathyContact *c = l->data;
959 if (empathy_contact_get_handle (c) != handle) {
964 /* Caller takes the reference. */
965 priv->members = g_list_delete_link (priv->members, l);
983 static ContactRenameData *
984 contact_rename_data_new (TpHandle handle,
986 const gchar* message)
988 ContactRenameData *data = g_new (ContactRenameData, 1);
989 data->old_handle = handle;
990 data->reason = reason;
991 data->message = g_strdup (message);
997 contact_rename_data_free (ContactRenameData* data)
999 g_free (data->message);
1004 tp_chat_got_renamed_contacts_cb (TpConnection *connection,
1006 EmpathyContact * const * contacts,
1008 const TpHandle *failed,
1009 const GError *error,
1013 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1014 const TpIntSet *members;
1016 EmpathyContact *old = NULL, *new = NULL;
1017 ContactRenameData *rename_data = (ContactRenameData *) user_data;
1020 DEBUG ("Error: %s", error->message);
1024 /* renamed members can only be delivered one at a time */
1025 g_warn_if_fail (n_contacts == 1);
1029 members = tp_channel_group_get_members (priv->channel);
1030 handle = empathy_contact_get_handle (new);
1032 old = chat_lookup_contact (EMPATHY_TP_CHAT (chat),
1033 rename_data->old_handle, TRUE);
1035 /* Make sure the contact is still member */
1036 if (tp_intset_is_member (members, handle)) {
1037 priv->members = g_list_prepend (priv->members,
1038 g_object_ref (new));
1041 g_signal_emit_by_name (chat, "member-renamed",
1042 old, new, rename_data->reason,
1043 rename_data->message);
1044 g_object_unref (old);
1048 if (priv->user == old) {
1049 /* We change our nick */
1050 g_object_unref (priv->user);
1051 priv->user = g_object_ref (new);
1054 tp_chat_update_remote_contact (EMPATHY_TP_CHAT (chat));
1055 tp_chat_check_if_ready (EMPATHY_TP_CHAT (chat));
1060 tp_chat_group_members_changed_cb (TpChannel *self,
1064 GArray *local_pending,
1065 GArray *remote_pending,
1068 EmpathyTpChat *chat)
1070 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1071 EmpathyContact *contact;
1072 EmpathyContact *actor_contact = NULL;
1074 ContactRenameData *rename_data;
1075 TpHandle old_handle;
1077 /* Contact renamed */
1078 if (reason == TP_CHANNEL_GROUP_CHANGE_REASON_RENAMED) {
1079 /* there can only be a single 'added' and a single 'removed' handle */
1080 g_warn_if_fail (removed->len == 1);
1081 g_warn_if_fail (added->len == 1);
1083 old_handle = g_array_index (removed, guint, 0);
1085 rename_data = contact_rename_data_new (old_handle, reason, message);
1086 empathy_tp_contact_factory_get_from_handles (priv->connection,
1087 added->len, (TpHandle *) added->data,
1088 tp_chat_got_renamed_contacts_cb,
1089 rename_data, (GDestroyNotify) contact_rename_data_free,
1095 actor_contact = chat_lookup_contact (chat, actor, FALSE);
1096 if (actor_contact == NULL) {
1097 /* FIXME: handle this a tad more gracefully: perhaps
1098 * the actor was a server op. We could use the
1099 * contact-ids detail of MembersChangedDetailed.
1101 DEBUG ("actor %u not a channel member", actor);
1105 /* Remove contacts that are not members anymore */
1106 for (i = 0; i < removed->len; i++) {
1107 contact = chat_lookup_contact (chat,
1108 g_array_index (removed, TpHandle, i), TRUE);
1110 if (contact != NULL) {
1111 g_signal_emit_by_name (chat, "members-changed", contact,
1112 actor_contact, reason, message,
1114 g_object_unref (contact);
1118 /* Request added contacts */
1119 if (added->len > 0) {
1120 empathy_tp_contact_factory_get_from_handles (priv->connection,
1121 added->len, (TpHandle *) added->data,
1122 tp_chat_got_added_contacts_cb, NULL, NULL,
1126 tp_chat_update_remote_contact (chat);
1128 if (actor_contact != NULL) {
1129 g_object_unref (actor_contact);
1134 tp_chat_got_remote_contact_cb (TpConnection *connection,
1135 EmpathyContact *contact,
1136 const GError *error,
1140 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1143 DEBUG ("Error: %s", error->message);
1144 empathy_tp_chat_leave (EMPATHY_TP_CHAT (chat));
1148 priv->remote_contact = g_object_ref (contact);
1149 g_object_notify (chat, "remote-contact");
1151 tp_chat_check_if_ready (EMPATHY_TP_CHAT (chat));
1155 tp_chat_got_self_contact_cb (TpConnection *connection,
1156 EmpathyContact *contact,
1157 const GError *error,
1161 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1164 DEBUG ("Error: %s", error->message);
1165 empathy_tp_chat_leave (EMPATHY_TP_CHAT (chat));
1169 priv->user = g_object_ref (contact);
1170 empathy_contact_set_is_user (priv->user, TRUE);
1171 tp_chat_check_if_ready (EMPATHY_TP_CHAT (chat));
1175 password_flags_changed_cb (TpChannel *channel,
1179 GObject *weak_object)
1181 EmpathyTpChat *self = EMPATHY_TP_CHAT (weak_object);
1182 EmpathyTpChatPriv *priv = GET_PRIV (self);
1183 gboolean was_needed, needed;
1185 was_needed = empathy_tp_chat_password_needed (self);
1187 priv->password_flags |= added;
1188 priv->password_flags ^= removed;
1190 needed = empathy_tp_chat_password_needed (self);
1192 if (was_needed != needed)
1193 g_object_notify (G_OBJECT (self), "password-needed");
1197 got_password_flags_cb (TpChannel *proxy,
1198 guint password_flags,
1199 const GError *error,
1201 GObject *weak_object)
1203 EmpathyTpChat *self = EMPATHY_TP_CHAT (weak_object);
1204 EmpathyTpChatPriv *priv = GET_PRIV (self);
1206 priv->got_password_flags = TRUE;
1207 priv->password_flags = password_flags;
1209 tp_chat_check_if_ready (EMPATHY_TP_CHAT (self));
1213 tp_chat_constructor (GType type,
1215 GObjectConstructParam *props)
1218 EmpathyTpChatPriv *priv;
1221 chat = G_OBJECT_CLASS (empathy_tp_chat_parent_class)->constructor (type, n_props, props);
1223 priv = GET_PRIV (chat);
1225 priv->connection = g_object_ref (tp_channel_borrow_connection (priv->channel));
1226 g_signal_connect (priv->channel, "invalidated",
1227 G_CALLBACK (tp_chat_invalidated_cb),
1230 if (tp_proxy_has_interface_by_id (priv->channel,
1231 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
1232 const TpIntSet *members;
1235 /* Get self contact from the group's self handle */
1236 handle = tp_channel_group_get_self_handle (priv->channel);
1237 empathy_tp_contact_factory_get_from_handle (priv->connection,
1238 handle, tp_chat_got_self_contact_cb,
1241 /* Get initial member contacts */
1242 members = tp_channel_group_get_members (priv->channel);
1243 handles = tp_intset_to_array (members);
1244 empathy_tp_contact_factory_get_from_handles (priv->connection,
1245 handles->len, (TpHandle *) handles->data,
1246 tp_chat_got_added_contacts_cb, NULL, NULL, chat);
1248 priv->can_upgrade_to_muc = FALSE;
1250 g_signal_connect (priv->channel, "group-members-changed",
1251 G_CALLBACK (tp_chat_group_members_changed_cb), chat);
1253 EmpathyDispatcher *dispatcher = empathy_dispatcher_dup_singleton ();
1256 /* Get the self contact from the connection's self handle */
1257 handle = tp_connection_get_self_handle (priv->connection);
1258 empathy_tp_contact_factory_get_from_handle (priv->connection,
1259 handle, tp_chat_got_self_contact_cb,
1262 /* Get the remote contact */
1263 handle = tp_channel_get_handle (priv->channel, NULL);
1264 empathy_tp_contact_factory_get_from_handle (priv->connection,
1265 handle, tp_chat_got_remote_contact_cb,
1268 list = empathy_dispatcher_find_requestable_channel_classes (
1269 dispatcher, priv->connection,
1270 tp_channel_get_channel_type (priv->channel),
1271 TP_UNKNOWN_HANDLE_TYPE, NULL);
1273 for (ptr = list; ptr; ptr = ptr->next) {
1274 GValueArray *array = ptr->data;
1275 const char **oprops = g_value_get_boxed (
1276 g_value_array_get_nth (array, 1));
1278 if (tp_strv_contains (oprops, EMP_IFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels")) {
1279 priv->can_upgrade_to_muc = TRUE;
1285 g_object_unref (dispatcher);
1288 if (tp_proxy_has_interface_by_id (priv->channel,
1289 TP_IFACE_QUARK_PROPERTIES_INTERFACE)) {
1290 tp_cli_properties_interface_call_list_properties (priv->channel, -1,
1291 tp_chat_list_properties_cb,
1294 tp_cli_properties_interface_connect_to_properties_changed (priv->channel,
1295 tp_chat_properties_changed_cb,
1297 G_OBJECT (chat), NULL);
1298 tp_cli_properties_interface_connect_to_property_flags_changed (priv->channel,
1299 tp_chat_property_flags_changed_cb,
1301 G_OBJECT (chat), NULL);
1304 /* Check if the chat is password protected */
1305 if (tp_proxy_has_interface_by_id (priv->channel,
1306 TP_IFACE_QUARK_CHANNEL_INTERFACE_PASSWORD)) {
1307 priv->got_password_flags = FALSE;
1309 tp_cli_channel_interface_password_connect_to_password_flags_changed
1310 (priv->channel, password_flags_changed_cb, chat, NULL,
1311 G_OBJECT (chat), NULL);
1313 tp_cli_channel_interface_password_call_get_password_flags
1314 (priv->channel, -1, got_password_flags_cb, chat, NULL, chat);
1316 /* No Password interface, so no need to fetch the password flags */
1317 priv->got_password_flags = TRUE;
1324 tp_chat_get_property (GObject *object,
1329 EmpathyTpChat *self = EMPATHY_TP_CHAT (object);
1330 EmpathyTpChatPriv *priv = GET_PRIV (object);
1334 g_value_set_object (value, priv->channel);
1336 case PROP_REMOTE_CONTACT:
1337 g_value_set_object (value, priv->remote_contact);
1340 g_value_set_boolean (value, priv->ready);
1342 case PROP_PASSWORD_NEEDED:
1343 g_value_set_boolean (value, empathy_tp_chat_password_needed (self));
1346 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1352 tp_chat_set_property (GObject *object,
1354 const GValue *value,
1357 EmpathyTpChatPriv *priv = GET_PRIV (object);
1361 priv->channel = g_value_dup_object (value);
1364 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1370 empathy_tp_chat_class_init (EmpathyTpChatClass *klass)
1372 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1374 object_class->dispose = tp_chat_dispose;
1375 object_class->finalize = tp_chat_finalize;
1376 object_class->constructor = tp_chat_constructor;
1377 object_class->get_property = tp_chat_get_property;
1378 object_class->set_property = tp_chat_set_property;
1380 g_object_class_install_property (object_class,
1382 g_param_spec_object ("channel",
1383 "telepathy channel",
1384 "The text channel for the chat",
1387 G_PARAM_CONSTRUCT_ONLY));
1389 g_object_class_install_property (object_class,
1390 PROP_REMOTE_CONTACT,
1391 g_param_spec_object ("remote-contact",
1392 "The remote contact",
1393 "The remote contact if there is no group iface on the channel",
1394 EMPATHY_TYPE_CONTACT,
1397 g_object_class_install_property (object_class,
1399 g_param_spec_boolean ("ready",
1400 "Is the object ready",
1401 "This object can't be used until this becomes true",
1405 g_object_class_install_property (object_class,
1406 PROP_PASSWORD_NEEDED,
1407 g_param_spec_boolean ("password-needed",
1409 "TRUE if a password is needed to join the channel",
1414 signals[MESSAGE_RECEIVED] =
1415 g_signal_new ("message-received",
1416 G_TYPE_FROM_CLASS (klass),
1420 g_cclosure_marshal_VOID__OBJECT,
1422 1, EMPATHY_TYPE_MESSAGE);
1424 signals[SEND_ERROR] =
1425 g_signal_new ("send-error",
1426 G_TYPE_FROM_CLASS (klass),
1430 _empathy_marshal_VOID__STRING_UINT,
1432 2, G_TYPE_STRING, G_TYPE_UINT);
1434 signals[CHAT_STATE_CHANGED] =
1435 g_signal_new ("chat-state-changed",
1436 G_TYPE_FROM_CLASS (klass),
1440 _empathy_marshal_VOID__OBJECT_UINT,
1442 2, EMPATHY_TYPE_CONTACT, G_TYPE_UINT);
1444 signals[PROPERTY_CHANGED] =
1445 g_signal_new ("property-changed",
1446 G_TYPE_FROM_CLASS (klass),
1450 _empathy_marshal_VOID__STRING_BOXED,
1452 2, G_TYPE_STRING, G_TYPE_VALUE);
1455 g_signal_new ("destroy",
1456 G_TYPE_FROM_CLASS (klass),
1460 g_cclosure_marshal_VOID__VOID,
1464 g_type_class_add_private (object_class, sizeof (EmpathyTpChatPriv));
1468 empathy_tp_chat_init (EmpathyTpChat *chat)
1470 EmpathyTpChatPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chat,
1471 EMPATHY_TYPE_TP_CHAT, EmpathyTpChatPriv);
1474 priv->messages_queue = g_queue_new ();
1475 priv->pending_messages_queue = g_queue_new ();
1479 tp_chat_iface_init (EmpathyContactListIface *iface)
1481 iface->add = tp_chat_add;
1482 iface->remove = tp_chat_remove;
1483 iface->get_members = tp_chat_get_members;
1487 empathy_tp_chat_new (TpChannel *channel)
1489 return g_object_new (EMPATHY_TYPE_TP_CHAT,
1495 empathy_tp_chat_close (EmpathyTpChat *chat) {
1496 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1498 /* If there are still messages left, it'll come back..
1499 * We loose the ordering of sent messages though */
1500 tp_cli_channel_call_close (priv->channel, -1, tp_chat_async_cb,
1501 "closing channel", NULL, NULL);
1505 empathy_tp_chat_get_id (EmpathyTpChat *chat)
1507 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1511 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1513 id = tp_channel_get_identifier (priv->channel);
1514 if (!EMP_STR_EMPTY (id))
1516 else if (priv->remote_contact)
1517 return empathy_contact_get_id (priv->remote_contact);
1524 empathy_tp_chat_get_remote_contact (EmpathyTpChat *chat)
1526 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1528 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1529 g_return_val_if_fail (priv->ready, NULL);
1531 return priv->remote_contact;
1535 empathy_tp_chat_get_channel (EmpathyTpChat *chat)
1537 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1539 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1541 return priv->channel;
1545 empathy_tp_chat_get_connection (EmpathyTpChat *chat)
1547 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1549 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1551 return tp_channel_borrow_connection (priv->channel);
1555 empathy_tp_chat_is_ready (EmpathyTpChat *chat)
1557 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1559 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), FALSE);
1565 empathy_tp_chat_send (EmpathyTpChat *chat,
1566 EmpathyMessage *message)
1568 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1569 const gchar *message_body;
1570 TpChannelTextMessageType message_type;
1572 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1573 g_return_if_fail (EMPATHY_IS_MESSAGE (message));
1574 g_return_if_fail (priv->ready);
1576 message_body = empathy_message_get_body (message);
1577 message_type = empathy_message_get_tptype (message);
1579 DEBUG ("Sending message: %s", message_body);
1580 tp_cli_channel_type_text_call_send (priv->channel, -1,
1584 g_object_ref (message),
1585 (GDestroyNotify) g_object_unref,
1590 empathy_tp_chat_set_state (EmpathyTpChat *chat,
1591 TpChannelChatState state)
1593 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1595 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1596 g_return_if_fail (priv->ready);
1598 if (tp_proxy_has_interface_by_id (priv->channel,
1599 TP_IFACE_QUARK_CHANNEL_INTERFACE_CHAT_STATE)) {
1600 DEBUG ("Set state: %d", state);
1601 tp_cli_channel_interface_chat_state_call_set_chat_state (priv->channel, -1,
1604 "setting chat state",
1612 empathy_tp_chat_get_pending_messages (EmpathyTpChat *chat)
1614 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1616 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1617 g_return_val_if_fail (priv->ready, NULL);
1619 return priv->pending_messages_queue->head;
1623 acknowledge_messages (EmpathyTpChat *chat, GArray *ids) {
1624 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1626 tp_cli_channel_type_text_call_acknowledge_pending_messages (
1627 priv->channel, -1, ids, tp_chat_async_cb,
1628 "acknowledging received message", NULL, G_OBJECT (chat));
1632 empathy_tp_chat_acknowledge_message (EmpathyTpChat *chat,
1633 EmpathyMessage *message) {
1634 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1635 GArray *message_ids;
1639 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1640 g_return_if_fail (priv->ready);
1642 if (!empathy_message_is_incoming (message))
1645 message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
1647 id = empathy_message_get_id (message);
1648 g_array_append_val (message_ids, id);
1649 acknowledge_messages (chat, message_ids);
1650 g_array_free (message_ids, TRUE);
1653 m = g_queue_find (priv->pending_messages_queue, message);
1654 g_assert (m != NULL);
1655 g_queue_delete_link (priv->pending_messages_queue, m);
1656 g_object_unref (message);
1660 empathy_tp_chat_acknowledge_messages (EmpathyTpChat *chat,
1661 const GSList *messages) {
1662 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1663 /* Copy messages as the messges list (probably is) our own */
1664 GSList *msgs = g_slist_copy ((GSList *) messages);
1667 GArray *message_ids;
1669 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1670 g_return_if_fail (priv->ready);
1672 length = g_slist_length ((GSList *) messages);
1677 message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), length);
1679 for (l = msgs; l != NULL; l = g_slist_next (l)) {
1682 EmpathyMessage *message = EMPATHY_MESSAGE (l->data);
1684 m = g_queue_find (priv->pending_messages_queue, message);
1685 g_assert (m != NULL);
1686 g_queue_delete_link (priv->pending_messages_queue, m);
1688 if (empathy_message_is_incoming (message)) {
1689 guint id = empathy_message_get_id (message);
1690 g_array_append_val (message_ids, id);
1692 g_object_unref (message);
1695 if (message_ids->len > 0)
1696 acknowledge_messages (chat, message_ids);
1698 g_array_free (message_ids, TRUE);
1699 g_slist_free (msgs);
1703 empathy_tp_chat_acknowledge_all_messages (EmpathyTpChat *chat)
1705 empathy_tp_chat_acknowledge_messages (chat,
1706 (GSList *) empathy_tp_chat_get_pending_messages (chat));
1710 empathy_tp_chat_password_needed (EmpathyTpChat *self)
1712 EmpathyTpChatPriv *priv = GET_PRIV (self);
1714 return priv->password_flags & TP_CHANNEL_PASSWORD_FLAG_PROVIDE;
1718 provide_password_cb (TpChannel *channel,
1720 const GError *error,
1722 GObject *weak_object)
1724 GSimpleAsyncResult *result = user_data;
1726 if (error != NULL) {
1727 g_simple_async_result_set_from_error (result, error);
1729 else if (!correct) {
1730 /* The current D-Bus API is a bit weird so re-use the
1731 * AuthenticationFailed error */
1732 g_simple_async_result_set_error (result, TP_ERRORS,
1733 TP_ERROR_AUTHENTICATION_FAILED, "Wrong password");
1736 g_simple_async_result_complete (result);
1737 g_object_unref (result);
1741 empathy_tp_chat_provide_password_async (EmpathyTpChat *self,
1742 const gchar *password,
1743 GAsyncReadyCallback callback,
1746 EmpathyTpChatPriv *priv = GET_PRIV (self);
1747 GSimpleAsyncResult *result;
1749 result = g_simple_async_result_new (G_OBJECT (self),
1750 callback, user_data,
1751 empathy_tp_chat_provide_password_finish);
1753 tp_cli_channel_interface_password_call_provide_password
1754 (priv->channel, -1, password, provide_password_cb, result,
1755 NULL, G_OBJECT (self));
1759 empathy_tp_chat_provide_password_finish (EmpathyTpChat *self,
1760 GAsyncResult *result,
1763 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1767 g_return_val_if_fail (g_simple_async_result_is_valid (result,
1768 G_OBJECT (self), empathy_tp_chat_provide_password_finish), FALSE);
1774 * empathy_tp_chat_can_add_contact:
1776 * Returns: %TRUE if empathy_contact_list_add() will work for this channel.
1777 * That is if this chat is a 1-to-1 channel that can be upgraded to
1778 * a MUC using the Conference interface or if the channel is a MUC.
1781 empathy_tp_chat_can_add_contact (EmpathyTpChat *self)
1783 EmpathyTpChatPriv *priv;
1785 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (self), FALSE);
1787 priv = GET_PRIV (self);
1789 return priv->can_upgrade_to_muc ||
1790 tp_proxy_has_interface_by_id (priv->channel,
1791 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP);;
1795 leave_remove_members_cb (TpChannel *proxy,
1796 const GError *error,
1798 GObject *weak_object)
1800 EmpathyTpChat *self = user_data;
1805 DEBUG ("RemoveMembers failed (%s); closing the channel", error->message);
1806 empathy_tp_chat_close (self);
1810 empathy_tp_chat_leave (EmpathyTpChat *self)
1812 EmpathyTpChatPriv *priv = GET_PRIV (self);
1813 TpHandle self_handle;
1816 if (!tp_proxy_has_interface_by_id (priv->channel,
1817 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
1818 empathy_tp_chat_close (self);
1822 self_handle = tp_channel_group_get_self_handle (priv->channel);
1823 if (self_handle == 0) {
1824 /* we are not member of the channel */
1825 empathy_tp_chat_close (self);
1829 array = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), 1);
1830 g_array_insert_val (array, 0, self_handle);
1832 tp_cli_channel_interface_group_call_remove_members (priv->channel, -1, array,
1833 "", leave_remove_members_cb, self, NULL, G_OBJECT (self));
1835 g_array_free (array, TRUE);
1839 add_members_cb (TpChannel *proxy,
1840 const GError *error,
1842 GObject *weak_object)
1844 EmpathyTpChatPriv *priv = GET_PRIV (weak_object);
1846 if (error != NULL) {
1847 DEBUG ("Failed to join chat (%s): %s",
1848 tp_channel_get_identifier (priv->channel), error->message);
1853 empathy_tp_chat_join (EmpathyTpChat *self)
1855 EmpathyTpChatPriv *priv = GET_PRIV (self);
1856 TpHandle self_handle;
1859 self_handle = tp_channel_group_get_self_handle (priv->channel);
1861 members = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), 1);
1862 g_array_append_val (members, self_handle);
1864 tp_cli_channel_interface_group_call_add_members (priv->channel, -1, members,
1865 "", add_members_cb, NULL, NULL, G_OBJECT (self));
1867 g_array_free (members, TRUE);
1871 empathy_tp_chat_is_invited (EmpathyTpChat *self)
1873 EmpathyTpChatPriv *priv = GET_PRIV (self);
1874 TpHandle self_handle;
1876 if (!tp_proxy_has_interface (priv->channel, TP_IFACE_CHANNEL_INTERFACE_GROUP))
1879 self_handle = tp_channel_group_get_self_handle (priv->channel);
1880 if (self_handle == 0)
1883 return tp_channel_group_get_local_pending_info (priv->channel, self_handle,