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 check_ready (EmpathyTpChat *chat)
209 EmpathyTpChatPriv *priv = GET_PRIV (chat);
214 if (g_queue_get_length (priv->messages_queue) > 0)
220 g_object_notify (G_OBJECT (chat), "ready");
224 tp_chat_emit_queued_messages (EmpathyTpChat *chat)
226 EmpathyTpChatPriv *priv = GET_PRIV (chat);
227 EmpathyMessage *message;
229 /* Check if we can now emit some queued messages */
230 while ((message = g_queue_peek_head (priv->messages_queue)) != NULL) {
231 if (empathy_message_get_sender (message) == NULL) {
235 DEBUG ("Queued message ready");
236 g_queue_pop_head (priv->messages_queue);
237 g_queue_push_tail (priv->pending_messages_queue, message);
238 g_signal_emit (chat, signals[MESSAGE_RECEIVED], 0, message);
245 tp_chat_got_sender_cb (TpConnection *connection,
246 EmpathyContact *contact,
251 EmpathyTpChatPriv *priv = GET_PRIV (chat);
254 DEBUG ("Error: %s", error->message);
255 /* Do not block the message queue, just drop this message */
256 g_queue_remove (priv->messages_queue, message);
258 empathy_message_set_sender (message, contact);
261 tp_chat_emit_queued_messages (EMPATHY_TP_CHAT (chat));
265 tp_chat_build_message (EmpathyTpChat *chat,
271 const gchar *message_body,
272 TpChannelTextMessageFlags flags)
274 EmpathyTpChatPriv *priv;
275 EmpathyMessage *message;
277 priv = GET_PRIV (chat);
279 message = empathy_message_new (message_body);
280 empathy_message_set_tptype (message, type);
281 empathy_message_set_receiver (message, priv->user);
282 empathy_message_set_timestamp (message, timestamp);
283 empathy_message_set_id (message, id);
284 empathy_message_set_incoming (message, incoming);
285 empathy_message_set_flags (message, flags);
287 g_queue_push_tail (priv->messages_queue, message);
289 if (from_handle == 0) {
290 empathy_message_set_sender (message, priv->user);
291 tp_chat_emit_queued_messages (chat);
293 empathy_tp_contact_factory_get_from_handle (priv->connection,
295 tp_chat_got_sender_cb,
296 message, NULL, G_OBJECT (chat));
301 tp_chat_received_cb (TpChannel *channel,
307 const gchar *message_body,
311 EmpathyTpChat *chat = EMPATHY_TP_CHAT (chat_);
312 EmpathyTpChatPriv *priv = GET_PRIV (chat);
314 if (priv->channel == NULL)
317 if (priv->listing_pending_messages) {
321 DEBUG ("Message received: %s", message_body);
323 if (message_flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT &&
324 !tp_strdiff (message_body, "")) {
327 DEBUG ("Empty message with NonTextContent, ignoring and acking.");
329 ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
330 g_array_append_val (ids, message_id);
331 acknowledge_messages (chat, ids);
332 g_array_free (ids, TRUE);
337 tp_chat_build_message (chat,
348 tp_chat_sent_cb (TpChannel *channel,
351 const gchar *message_body,
355 EmpathyTpChat *chat = EMPATHY_TP_CHAT (chat_);
356 EmpathyTpChatPriv *priv = GET_PRIV (chat);
358 if (priv->channel == NULL)
361 DEBUG ("Message sent: %s", message_body);
363 tp_chat_build_message (chat,
374 tp_chat_send_error_cb (TpChannel *channel,
378 const gchar *message_body,
382 EmpathyTpChatPriv *priv = GET_PRIV (chat);
384 if (priv->channel == NULL)
387 DEBUG ("Error sending '%s' (%d)", message_body, error_code);
389 g_signal_emit (chat, signals[SEND_ERROR], 0, message_body, error_code);
393 tp_chat_send_cb (TpChannel *proxy,
398 EmpathyMessage *message = EMPATHY_MESSAGE (user_data);
401 DEBUG ("Error: %s", error->message);
402 g_signal_emit (chat, signals[SEND_ERROR], 0,
403 empathy_message_get_body (message),
404 TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN);
410 TpChannelChatState state;
414 tp_chat_state_changed_got_contact_cb (TpConnection *connection,
415 EmpathyContact *contact,
420 TpChannelChatState state;
423 DEBUG ("Error: %s", error->message);
427 state = GPOINTER_TO_UINT (user_data);
428 DEBUG ("Chat state changed for %s (%d): %d",
429 empathy_contact_get_name (contact),
430 empathy_contact_get_handle (contact), state);
432 g_signal_emit (chat, signals[CHAT_STATE_CHANGED], 0, contact, state);
436 tp_chat_state_changed_cb (TpChannel *channel,
438 TpChannelChatState state,
442 EmpathyTpChatPriv *priv = GET_PRIV (chat);
444 empathy_tp_contact_factory_get_from_handle (priv->connection, handle,
445 tp_chat_state_changed_got_contact_cb, GUINT_TO_POINTER (state),
450 tp_chat_list_pending_messages_cb (TpChannel *channel,
451 const GPtrArray *messages_list,
456 EmpathyTpChat *chat = EMPATHY_TP_CHAT (chat_);
457 EmpathyTpChatPriv *priv = GET_PRIV (chat);
459 GArray *empty_non_text_content_ids = NULL;
461 priv->listing_pending_messages = FALSE;
463 if (priv->channel == NULL)
467 DEBUG ("Error listing pending messages: %s", error->message);
471 for (i = 0; i < messages_list->len; i++) {
472 GValueArray *message_struct;
473 const gchar *message_body;
480 message_struct = g_ptr_array_index (messages_list, i);
482 message_id = g_value_get_uint (g_value_array_get_nth (message_struct, 0));
483 timestamp = g_value_get_uint (g_value_array_get_nth (message_struct, 1));
484 from_handle = g_value_get_uint (g_value_array_get_nth (message_struct, 2));
485 message_type = g_value_get_uint (g_value_array_get_nth (message_struct, 3));
486 message_flags = g_value_get_uint (g_value_array_get_nth (message_struct, 4));
487 message_body = g_value_get_string (g_value_array_get_nth (message_struct, 5));
489 DEBUG ("Message pending: %s", message_body);
491 if (message_flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT &&
492 !tp_strdiff (message_body, "")) {
493 DEBUG ("Empty message with NonTextContent, ignoring and acking.");
495 if (empty_non_text_content_ids == NULL) {
496 empty_non_text_content_ids = g_array_new (FALSE, FALSE, sizeof (guint));
499 g_array_append_val (empty_non_text_content_ids, message_id);
503 tp_chat_build_message (chat,
513 if (empty_non_text_content_ids != NULL) {
514 acknowledge_messages (chat, empty_non_text_content_ids);
515 g_array_free (empty_non_text_content_ids, TRUE);
522 tp_chat_property_flags_changed_cb (TpProxy *proxy,
523 const GPtrArray *properties,
527 EmpathyTpChatPriv *priv = GET_PRIV (chat);
530 if (priv->channel == NULL)
533 if (!priv->had_properties_list || !properties) {
537 for (i = 0; i < properties->len; i++) {
538 GValueArray *prop_struct;
539 EmpathyTpChatProperty *property;
543 prop_struct = g_ptr_array_index (properties, i);
544 id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
545 flags = g_value_get_uint (g_value_array_get_nth (prop_struct, 1));
547 for (j = 0; j < priv->properties->len; j++) {
548 property = g_ptr_array_index (priv->properties, j);
549 if (property->id == id) {
550 property->flags = flags;
551 DEBUG ("property %s flags changed: %d",
552 property->name, property->flags);
560 tp_chat_properties_changed_cb (TpProxy *proxy,
561 const GPtrArray *properties,
565 EmpathyTpChatPriv *priv = GET_PRIV (chat);
568 if (priv->channel == NULL)
571 if (!priv->had_properties_list || !properties) {
575 for (i = 0; i < properties->len; i++) {
576 GValueArray *prop_struct;
577 EmpathyTpChatProperty *property;
581 prop_struct = g_ptr_array_index (properties, i);
582 id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
583 src_value = g_value_get_boxed (g_value_array_get_nth (prop_struct, 1));
585 for (j = 0; j < priv->properties->len; j++) {
586 property = g_ptr_array_index (priv->properties, j);
587 if (property->id == id) {
588 if (property->value) {
589 g_value_copy (src_value, property->value);
591 property->value = tp_g_value_slice_dup (src_value);
594 DEBUG ("property %s changed", property->name);
595 g_signal_emit (chat, signals[PROPERTY_CHANGED], 0,
596 property->name, property->value);
604 tp_chat_get_properties_cb (TpProxy *proxy,
605 const GPtrArray *properties,
611 DEBUG ("Error getting properties: %s", error->message);
615 tp_chat_properties_changed_cb (proxy, properties, user_data, chat);
619 tp_chat_list_properties_cb (TpProxy *proxy,
620 const GPtrArray *properties,
625 EmpathyTpChatPriv *priv = GET_PRIV (chat);
629 if (priv->channel == NULL)
632 priv->had_properties_list = TRUE;
635 DEBUG ("Error listing properties: %s", error->message);
639 ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), properties->len);
640 priv->properties = g_ptr_array_sized_new (properties->len);
641 for (i = 0; i < properties->len; i++) {
642 GValueArray *prop_struct;
643 EmpathyTpChatProperty *property;
645 prop_struct = g_ptr_array_index (properties, i);
646 property = g_slice_new0 (EmpathyTpChatProperty);
647 property->id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
648 property->name = g_value_dup_string (g_value_array_get_nth (prop_struct, 1));
649 property->flags = g_value_get_uint (g_value_array_get_nth (prop_struct, 3));
651 DEBUG ("Adding property name=%s id=%d flags=%d",
652 property->name, property->id, property->flags);
653 g_ptr_array_add (priv->properties, property);
654 if (property->flags & TP_PROPERTY_FLAG_READ) {
655 g_array_append_val (ids, property->id);
659 tp_cli_properties_interface_call_get_properties (proxy, -1,
661 tp_chat_get_properties_cb,
665 g_array_free (ids, TRUE);
669 empathy_tp_chat_set_property (EmpathyTpChat *chat,
673 EmpathyTpChatPriv *priv = GET_PRIV (chat);
674 EmpathyTpChatProperty *property;
677 if (!priv->had_properties_list) {
681 for (i = 0; i < priv->properties->len; i++) {
682 property = g_ptr_array_index (priv->properties, i);
683 if (!tp_strdiff (property->name, name)) {
684 GPtrArray *properties;
687 GValue dest_value = {0, };
689 if (!(property->flags & TP_PROPERTY_FLAG_WRITE)) {
693 g_value_init (&id, G_TYPE_UINT);
694 g_value_init (&dest_value, G_TYPE_VALUE);
695 g_value_set_uint (&id, property->id);
696 g_value_set_boxed (&dest_value, value);
698 prop = g_value_array_new (2);
699 g_value_array_append (prop, &id);
700 g_value_array_append (prop, &dest_value);
702 properties = g_ptr_array_sized_new (1);
703 g_ptr_array_add (properties, prop);
705 DEBUG ("Set property %s", name);
706 tp_cli_properties_interface_call_set_properties (priv->channel, -1,
708 (tp_cli_properties_interface_callback_for_set_properties)
710 "Seting property", NULL,
713 g_ptr_array_free (properties, TRUE);
714 g_value_array_free (prop);
721 EmpathyTpChatProperty *
722 empathy_tp_chat_get_property (EmpathyTpChat *chat,
725 EmpathyTpChatPriv *priv = GET_PRIV (chat);
726 EmpathyTpChatProperty *property;
729 if (!priv->had_properties_list) {
733 for (i = 0; i < priv->properties->len; i++) {
734 property = g_ptr_array_index (priv->properties, i);
735 if (!tp_strdiff (property->name, name)) {
744 empathy_tp_chat_get_properties (EmpathyTpChat *chat)
746 EmpathyTpChatPriv *priv = GET_PRIV (chat);
748 return priv->properties;
752 tp_chat_dispose (GObject *object)
754 EmpathyTpChat *self = EMPATHY_TP_CHAT (object);
755 EmpathyTpChatPriv *priv = GET_PRIV (self);
757 if (priv->dispose_has_run)
760 priv->dispose_has_run = TRUE;
762 if (priv->connection != NULL)
763 g_object_unref (priv->connection);
764 priv->connection = NULL;
766 if (priv->channel != NULL) {
767 g_signal_handlers_disconnect_by_func (priv->channel,
768 tp_chat_invalidated_cb, self);
769 g_object_unref (priv->channel);
771 priv->channel = NULL;
773 if (priv->remote_contact != NULL)
774 g_object_unref (priv->remote_contact);
775 priv->remote_contact = NULL;
777 if (priv->user != NULL)
778 g_object_unref (priv->user);
781 g_queue_foreach (priv->messages_queue, (GFunc) g_object_unref, NULL);
782 g_queue_clear (priv->messages_queue);
784 g_queue_foreach (priv->pending_messages_queue,
785 (GFunc) g_object_unref, NULL);
786 g_queue_clear (priv->pending_messages_queue);
788 if (G_OBJECT_CLASS (empathy_tp_chat_parent_class)->dispose)
789 G_OBJECT_CLASS (empathy_tp_chat_parent_class)->dispose (object);
793 tp_chat_finalize (GObject *object)
795 EmpathyTpChatPriv *priv = GET_PRIV (object);
798 DEBUG ("Finalize: %p", object);
800 if (priv->properties) {
801 for (i = 0; i < priv->properties->len; i++) {
802 EmpathyTpChatProperty *property;
804 property = g_ptr_array_index (priv->properties, i);
805 g_free (property->name);
806 if (property->value) {
807 tp_g_value_slice_free (property->value);
809 g_slice_free (EmpathyTpChatProperty, property);
811 g_ptr_array_free (priv->properties, TRUE);
814 g_queue_free (priv->messages_queue);
815 g_queue_free (priv->pending_messages_queue);
817 G_OBJECT_CLASS (empathy_tp_chat_parent_class)->finalize (object);
821 check_almost_ready (EmpathyTpChat *chat)
823 EmpathyTpChatPriv *priv = GET_PRIV (chat);
828 if (priv->user == NULL)
831 if (!priv->got_password_flags)
834 /* We need either the members (room) or the remote contact (private chat).
835 * If the chat is protected by a password we can't get these information so
836 * consider the chat as ready so it can be presented to the user. */
837 if (!empathy_tp_chat_password_needed (chat) && priv->members == NULL &&
838 priv->remote_contact == NULL)
841 tp_cli_channel_type_text_connect_to_received (priv->channel,
844 G_OBJECT (chat), NULL);
845 priv->listing_pending_messages = TRUE;
847 /* TpChat will be ready once ListPendingMessages returned and all the messages
848 * have been added to the pending messages queue. */
849 tp_cli_channel_type_text_call_list_pending_messages (priv->channel, -1,
851 tp_chat_list_pending_messages_cb,
855 tp_cli_channel_type_text_connect_to_sent (priv->channel,
858 G_OBJECT (chat), NULL);
859 tp_cli_channel_type_text_connect_to_send_error (priv->channel,
860 tp_chat_send_error_cb,
862 G_OBJECT (chat), NULL);
863 tp_cli_channel_interface_chat_state_connect_to_chat_state_changed (priv->channel,
864 tp_chat_state_changed_cb,
866 G_OBJECT (chat), NULL);
870 tp_chat_update_remote_contact (EmpathyTpChat *chat)
872 EmpathyTpChatPriv *priv = GET_PRIV (chat);
873 EmpathyContact *contact = NULL;
874 TpHandle self_handle;
875 TpHandleType handle_type;
878 /* If this is a named chatroom, never pretend it is a private chat */
879 tp_channel_get_handle (priv->channel, &handle_type);
880 if (handle_type == TP_HANDLE_TYPE_ROOM) {
884 /* This is an MSN chat, but it's the new style where 1-1 chats don't
885 * have the group interface. If it has the conference interface, then
886 * it is indeed a MUC. */
887 if (tp_proxy_has_interface_by_id (priv->channel,
888 EMP_IFACE_QUARK_CHANNEL_INTERFACE_CONFERENCE)) {
892 /* This is an MSN-like chat where anyone can join the chat at anytime.
893 * If there is only one non-self contact member, we are in a private
894 * chat and we set the "remote-contact" property to that contact. If
895 * there are more, set the "remote-contact" property to NULL and the
896 * UI will display a contact list. */
897 self_handle = tp_channel_group_get_self_handle (priv->channel);
898 for (l = priv->members; l; l = l->next) {
899 /* Skip self contact if member */
900 if (empathy_contact_get_handle (l->data) == self_handle) {
904 /* We have more than one remote contact, break */
905 if (contact != NULL) {
910 /* If we didn't find yet a remote contact, keep this one */
914 if (priv->remote_contact == contact) {
918 DEBUG ("Changing remote contact from %p to %p",
919 priv->remote_contact, contact);
921 if (priv->remote_contact) {
922 g_object_unref (priv->remote_contact);
925 priv->remote_contact = contact ? g_object_ref (contact) : NULL;
926 g_object_notify (G_OBJECT (chat), "remote-contact");
930 tp_chat_got_added_contacts_cb (TpConnection *connection,
932 EmpathyContact * const * contacts,
934 const TpHandle *failed,
939 EmpathyTpChatPriv *priv = GET_PRIV (chat);
941 const TpIntSet *members;
943 EmpathyContact *contact;
946 DEBUG ("Error: %s", error->message);
950 members = tp_channel_group_get_members (priv->channel);
951 for (i = 0; i < n_contacts; i++) {
952 contact = contacts[i];
953 handle = empathy_contact_get_handle (contact);
955 /* Make sure the contact is still member */
956 if (tp_intset_is_member (members, handle)) {
957 priv->members = g_list_prepend (priv->members,
958 g_object_ref (contact));
959 g_signal_emit_by_name (chat, "members-changed",
960 contact, NULL, 0, NULL, TRUE);
964 tp_chat_update_remote_contact (EMPATHY_TP_CHAT (chat));
965 check_almost_ready (EMPATHY_TP_CHAT (chat));
968 static EmpathyContact *
969 chat_lookup_contact (EmpathyTpChat *chat,
973 EmpathyTpChatPriv *priv = GET_PRIV (chat);
976 for (l = priv->members; l; l = l->next) {
977 EmpathyContact *c = l->data;
979 if (empathy_contact_get_handle (c) != handle) {
984 /* Caller takes the reference. */
985 priv->members = g_list_delete_link (priv->members, l);
1001 } ContactRenameData;
1003 static ContactRenameData *
1004 contact_rename_data_new (TpHandle handle,
1006 const gchar* message)
1008 ContactRenameData *data = g_new (ContactRenameData, 1);
1009 data->old_handle = handle;
1010 data->reason = reason;
1011 data->message = g_strdup (message);
1017 contact_rename_data_free (ContactRenameData* data)
1019 g_free (data->message);
1024 tp_chat_got_renamed_contacts_cb (TpConnection *connection,
1026 EmpathyContact * const * contacts,
1028 const TpHandle *failed,
1029 const GError *error,
1033 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1034 const TpIntSet *members;
1036 EmpathyContact *old = NULL, *new = NULL;
1037 ContactRenameData *rename_data = (ContactRenameData *) user_data;
1040 DEBUG ("Error: %s", error->message);
1044 /* renamed members can only be delivered one at a time */
1045 g_warn_if_fail (n_contacts == 1);
1049 members = tp_channel_group_get_members (priv->channel);
1050 handle = empathy_contact_get_handle (new);
1052 old = chat_lookup_contact (EMPATHY_TP_CHAT (chat),
1053 rename_data->old_handle, TRUE);
1055 /* Make sure the contact is still member */
1056 if (tp_intset_is_member (members, handle)) {
1057 priv->members = g_list_prepend (priv->members,
1058 g_object_ref (new));
1061 g_signal_emit_by_name (chat, "member-renamed",
1062 old, new, rename_data->reason,
1063 rename_data->message);
1064 g_object_unref (old);
1068 if (priv->user == old) {
1069 /* We change our nick */
1070 g_object_unref (priv->user);
1071 priv->user = g_object_ref (new);
1074 tp_chat_update_remote_contact (EMPATHY_TP_CHAT (chat));
1075 check_almost_ready (EMPATHY_TP_CHAT (chat));
1080 tp_chat_group_members_changed_cb (TpChannel *self,
1084 GArray *local_pending,
1085 GArray *remote_pending,
1088 EmpathyTpChat *chat)
1090 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1091 EmpathyContact *contact;
1092 EmpathyContact *actor_contact = NULL;
1094 ContactRenameData *rename_data;
1095 TpHandle old_handle;
1097 /* Contact renamed */
1098 if (reason == TP_CHANNEL_GROUP_CHANGE_REASON_RENAMED) {
1099 /* there can only be a single 'added' and a single 'removed' handle */
1100 g_warn_if_fail (removed->len == 1);
1101 g_warn_if_fail (added->len == 1);
1103 old_handle = g_array_index (removed, guint, 0);
1105 rename_data = contact_rename_data_new (old_handle, reason, message);
1106 empathy_tp_contact_factory_get_from_handles (priv->connection,
1107 added->len, (TpHandle *) added->data,
1108 tp_chat_got_renamed_contacts_cb,
1109 rename_data, (GDestroyNotify) contact_rename_data_free,
1115 actor_contact = chat_lookup_contact (chat, actor, FALSE);
1116 if (actor_contact == NULL) {
1117 /* FIXME: handle this a tad more gracefully: perhaps
1118 * the actor was a server op. We could use the
1119 * contact-ids detail of MembersChangedDetailed.
1121 DEBUG ("actor %u not a channel member", actor);
1125 /* Remove contacts that are not members anymore */
1126 for (i = 0; i < removed->len; i++) {
1127 contact = chat_lookup_contact (chat,
1128 g_array_index (removed, TpHandle, i), TRUE);
1130 if (contact != NULL) {
1131 g_signal_emit_by_name (chat, "members-changed", contact,
1132 actor_contact, reason, message,
1134 g_object_unref (contact);
1138 /* Request added contacts */
1139 if (added->len > 0) {
1140 empathy_tp_contact_factory_get_from_handles (priv->connection,
1141 added->len, (TpHandle *) added->data,
1142 tp_chat_got_added_contacts_cb, NULL, NULL,
1146 tp_chat_update_remote_contact (chat);
1148 if (actor_contact != NULL) {
1149 g_object_unref (actor_contact);
1154 tp_chat_got_remote_contact_cb (TpConnection *connection,
1155 EmpathyContact *contact,
1156 const GError *error,
1160 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1163 DEBUG ("Error: %s", error->message);
1164 empathy_tp_chat_leave (EMPATHY_TP_CHAT (chat));
1168 priv->remote_contact = g_object_ref (contact);
1169 g_object_notify (chat, "remote-contact");
1171 check_almost_ready (EMPATHY_TP_CHAT (chat));
1175 tp_chat_got_self_contact_cb (TpConnection *connection,
1176 EmpathyContact *contact,
1177 const GError *error,
1181 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1184 DEBUG ("Error: %s", error->message);
1185 empathy_tp_chat_leave (EMPATHY_TP_CHAT (chat));
1189 priv->user = g_object_ref (contact);
1190 empathy_contact_set_is_user (priv->user, TRUE);
1191 check_almost_ready (EMPATHY_TP_CHAT (chat));
1195 password_flags_changed_cb (TpChannel *channel,
1199 GObject *weak_object)
1201 EmpathyTpChat *self = EMPATHY_TP_CHAT (weak_object);
1202 EmpathyTpChatPriv *priv = GET_PRIV (self);
1203 gboolean was_needed, needed;
1205 was_needed = empathy_tp_chat_password_needed (self);
1207 priv->password_flags |= added;
1208 priv->password_flags ^= removed;
1210 needed = empathy_tp_chat_password_needed (self);
1212 if (was_needed != needed)
1213 g_object_notify (G_OBJECT (self), "password-needed");
1217 got_password_flags_cb (TpChannel *proxy,
1218 guint password_flags,
1219 const GError *error,
1221 GObject *weak_object)
1223 EmpathyTpChat *self = EMPATHY_TP_CHAT (weak_object);
1224 EmpathyTpChatPriv *priv = GET_PRIV (self);
1226 priv->got_password_flags = TRUE;
1227 priv->password_flags = password_flags;
1229 check_almost_ready (EMPATHY_TP_CHAT (self));
1233 tp_chat_constructor (GType type,
1235 GObjectConstructParam *props)
1238 EmpathyTpChatPriv *priv;
1241 chat = G_OBJECT_CLASS (empathy_tp_chat_parent_class)->constructor (type, n_props, props);
1243 priv = GET_PRIV (chat);
1245 priv->connection = g_object_ref (tp_channel_borrow_connection (priv->channel));
1246 g_signal_connect (priv->channel, "invalidated",
1247 G_CALLBACK (tp_chat_invalidated_cb),
1250 if (tp_proxy_has_interface_by_id (priv->channel,
1251 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
1252 const TpIntSet *members;
1255 /* Get self contact from the group's self handle */
1256 handle = tp_channel_group_get_self_handle (priv->channel);
1257 empathy_tp_contact_factory_get_from_handle (priv->connection,
1258 handle, tp_chat_got_self_contact_cb,
1261 /* Get initial member contacts */
1262 members = tp_channel_group_get_members (priv->channel);
1263 handles = tp_intset_to_array (members);
1264 empathy_tp_contact_factory_get_from_handles (priv->connection,
1265 handles->len, (TpHandle *) handles->data,
1266 tp_chat_got_added_contacts_cb, NULL, NULL, chat);
1268 priv->can_upgrade_to_muc = FALSE;
1270 g_signal_connect (priv->channel, "group-members-changed",
1271 G_CALLBACK (tp_chat_group_members_changed_cb), chat);
1273 EmpathyDispatcher *dispatcher = empathy_dispatcher_dup_singleton ();
1276 /* Get the self contact from the connection's self handle */
1277 handle = tp_connection_get_self_handle (priv->connection);
1278 empathy_tp_contact_factory_get_from_handle (priv->connection,
1279 handle, tp_chat_got_self_contact_cb,
1282 /* Get the remote contact */
1283 handle = tp_channel_get_handle (priv->channel, NULL);
1284 empathy_tp_contact_factory_get_from_handle (priv->connection,
1285 handle, tp_chat_got_remote_contact_cb,
1288 list = empathy_dispatcher_find_requestable_channel_classes (
1289 dispatcher, priv->connection,
1290 tp_channel_get_channel_type (priv->channel),
1291 TP_UNKNOWN_HANDLE_TYPE, NULL);
1293 for (ptr = list; ptr; ptr = ptr->next) {
1294 GValueArray *array = ptr->data;
1295 const char **oprops = g_value_get_boxed (
1296 g_value_array_get_nth (array, 1));
1298 if (tp_strv_contains (oprops, EMP_IFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels")) {
1299 priv->can_upgrade_to_muc = TRUE;
1305 g_object_unref (dispatcher);
1308 if (tp_proxy_has_interface_by_id (priv->channel,
1309 TP_IFACE_QUARK_PROPERTIES_INTERFACE)) {
1310 tp_cli_properties_interface_call_list_properties (priv->channel, -1,
1311 tp_chat_list_properties_cb,
1314 tp_cli_properties_interface_connect_to_properties_changed (priv->channel,
1315 tp_chat_properties_changed_cb,
1317 G_OBJECT (chat), NULL);
1318 tp_cli_properties_interface_connect_to_property_flags_changed (priv->channel,
1319 tp_chat_property_flags_changed_cb,
1321 G_OBJECT (chat), NULL);
1324 /* Check if the chat is password protected */
1325 if (tp_proxy_has_interface_by_id (priv->channel,
1326 TP_IFACE_QUARK_CHANNEL_INTERFACE_PASSWORD)) {
1327 priv->got_password_flags = FALSE;
1329 tp_cli_channel_interface_password_connect_to_password_flags_changed
1330 (priv->channel, password_flags_changed_cb, chat, NULL,
1331 G_OBJECT (chat), NULL);
1333 tp_cli_channel_interface_password_call_get_password_flags
1334 (priv->channel, -1, got_password_flags_cb, chat, NULL, chat);
1336 /* No Password interface, so no need to fetch the password flags */
1337 priv->got_password_flags = TRUE;
1344 tp_chat_get_property (GObject *object,
1349 EmpathyTpChat *self = EMPATHY_TP_CHAT (object);
1350 EmpathyTpChatPriv *priv = GET_PRIV (object);
1354 g_value_set_object (value, priv->channel);
1356 case PROP_REMOTE_CONTACT:
1357 g_value_set_object (value, priv->remote_contact);
1360 g_value_set_boolean (value, priv->ready);
1362 case PROP_PASSWORD_NEEDED:
1363 g_value_set_boolean (value, empathy_tp_chat_password_needed (self));
1366 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1372 tp_chat_set_property (GObject *object,
1374 const GValue *value,
1377 EmpathyTpChatPriv *priv = GET_PRIV (object);
1381 priv->channel = g_value_dup_object (value);
1384 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1390 empathy_tp_chat_class_init (EmpathyTpChatClass *klass)
1392 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1394 object_class->dispose = tp_chat_dispose;
1395 object_class->finalize = tp_chat_finalize;
1396 object_class->constructor = tp_chat_constructor;
1397 object_class->get_property = tp_chat_get_property;
1398 object_class->set_property = tp_chat_set_property;
1400 g_object_class_install_property (object_class,
1402 g_param_spec_object ("channel",
1403 "telepathy channel",
1404 "The text channel for the chat",
1407 G_PARAM_CONSTRUCT_ONLY));
1409 g_object_class_install_property (object_class,
1410 PROP_REMOTE_CONTACT,
1411 g_param_spec_object ("remote-contact",
1412 "The remote contact",
1413 "The remote contact if there is no group iface on the channel",
1414 EMPATHY_TYPE_CONTACT,
1417 g_object_class_install_property (object_class,
1419 g_param_spec_boolean ("ready",
1420 "Is the object ready",
1421 "This object can't be used until this becomes true",
1425 g_object_class_install_property (object_class,
1426 PROP_PASSWORD_NEEDED,
1427 g_param_spec_boolean ("password-needed",
1429 "TRUE if a password is needed to join the channel",
1434 signals[MESSAGE_RECEIVED] =
1435 g_signal_new ("message-received",
1436 G_TYPE_FROM_CLASS (klass),
1440 g_cclosure_marshal_VOID__OBJECT,
1442 1, EMPATHY_TYPE_MESSAGE);
1444 signals[SEND_ERROR] =
1445 g_signal_new ("send-error",
1446 G_TYPE_FROM_CLASS (klass),
1450 _empathy_marshal_VOID__STRING_UINT,
1452 2, G_TYPE_STRING, G_TYPE_UINT);
1454 signals[CHAT_STATE_CHANGED] =
1455 g_signal_new ("chat-state-changed",
1456 G_TYPE_FROM_CLASS (klass),
1460 _empathy_marshal_VOID__OBJECT_UINT,
1462 2, EMPATHY_TYPE_CONTACT, G_TYPE_UINT);
1464 signals[PROPERTY_CHANGED] =
1465 g_signal_new ("property-changed",
1466 G_TYPE_FROM_CLASS (klass),
1470 _empathy_marshal_VOID__STRING_BOXED,
1472 2, G_TYPE_STRING, G_TYPE_VALUE);
1475 g_signal_new ("destroy",
1476 G_TYPE_FROM_CLASS (klass),
1480 g_cclosure_marshal_VOID__VOID,
1484 g_type_class_add_private (object_class, sizeof (EmpathyTpChatPriv));
1488 empathy_tp_chat_init (EmpathyTpChat *chat)
1490 EmpathyTpChatPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chat,
1491 EMPATHY_TYPE_TP_CHAT, EmpathyTpChatPriv);
1494 priv->messages_queue = g_queue_new ();
1495 priv->pending_messages_queue = g_queue_new ();
1499 tp_chat_iface_init (EmpathyContactListIface *iface)
1501 iface->add = tp_chat_add;
1502 iface->remove = tp_chat_remove;
1503 iface->get_members = tp_chat_get_members;
1507 empathy_tp_chat_new (TpChannel *channel)
1509 return g_object_new (EMPATHY_TYPE_TP_CHAT,
1515 empathy_tp_chat_close (EmpathyTpChat *chat) {
1516 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1518 /* If there are still messages left, it'll come back..
1519 * We loose the ordering of sent messages though */
1520 tp_cli_channel_call_close (priv->channel, -1, tp_chat_async_cb,
1521 "closing channel", NULL, NULL);
1525 empathy_tp_chat_get_id (EmpathyTpChat *chat)
1527 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1531 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1533 id = tp_channel_get_identifier (priv->channel);
1534 if (!EMP_STR_EMPTY (id))
1536 else if (priv->remote_contact)
1537 return empathy_contact_get_id (priv->remote_contact);
1544 empathy_tp_chat_get_remote_contact (EmpathyTpChat *chat)
1546 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1548 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1549 g_return_val_if_fail (priv->ready, NULL);
1551 return priv->remote_contact;
1555 empathy_tp_chat_get_channel (EmpathyTpChat *chat)
1557 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1559 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1561 return priv->channel;
1565 empathy_tp_chat_get_connection (EmpathyTpChat *chat)
1567 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1569 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1571 return tp_channel_borrow_connection (priv->channel);
1575 empathy_tp_chat_is_ready (EmpathyTpChat *chat)
1577 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1579 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), FALSE);
1585 empathy_tp_chat_send (EmpathyTpChat *chat,
1586 EmpathyMessage *message)
1588 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1589 const gchar *message_body;
1590 TpChannelTextMessageType message_type;
1592 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1593 g_return_if_fail (EMPATHY_IS_MESSAGE (message));
1594 g_return_if_fail (priv->ready);
1596 message_body = empathy_message_get_body (message);
1597 message_type = empathy_message_get_tptype (message);
1599 DEBUG ("Sending message: %s", message_body);
1600 tp_cli_channel_type_text_call_send (priv->channel, -1,
1604 g_object_ref (message),
1605 (GDestroyNotify) g_object_unref,
1610 empathy_tp_chat_set_state (EmpathyTpChat *chat,
1611 TpChannelChatState state)
1613 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1615 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1616 g_return_if_fail (priv->ready);
1618 if (tp_proxy_has_interface_by_id (priv->channel,
1619 TP_IFACE_QUARK_CHANNEL_INTERFACE_CHAT_STATE)) {
1620 DEBUG ("Set state: %d", state);
1621 tp_cli_channel_interface_chat_state_call_set_chat_state (priv->channel, -1,
1624 "setting chat state",
1632 empathy_tp_chat_get_pending_messages (EmpathyTpChat *chat)
1634 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1636 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1637 g_return_val_if_fail (priv->ready, NULL);
1639 return priv->pending_messages_queue->head;
1643 acknowledge_messages (EmpathyTpChat *chat, GArray *ids) {
1644 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1646 tp_cli_channel_type_text_call_acknowledge_pending_messages (
1647 priv->channel, -1, ids, tp_chat_async_cb,
1648 "acknowledging received message", NULL, G_OBJECT (chat));
1652 empathy_tp_chat_acknowledge_message (EmpathyTpChat *chat,
1653 EmpathyMessage *message) {
1654 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1655 GArray *message_ids;
1659 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1660 g_return_if_fail (priv->ready);
1662 if (!empathy_message_is_incoming (message))
1665 message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
1667 id = empathy_message_get_id (message);
1668 g_array_append_val (message_ids, id);
1669 acknowledge_messages (chat, message_ids);
1670 g_array_free (message_ids, TRUE);
1673 m = g_queue_find (priv->pending_messages_queue, message);
1674 g_assert (m != NULL);
1675 g_queue_delete_link (priv->pending_messages_queue, m);
1676 g_object_unref (message);
1680 empathy_tp_chat_acknowledge_messages (EmpathyTpChat *chat,
1681 const GSList *messages) {
1682 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1683 /* Copy messages as the messges list (probably is) our own */
1684 GSList *msgs = g_slist_copy ((GSList *) messages);
1687 GArray *message_ids;
1689 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1690 g_return_if_fail (priv->ready);
1692 length = g_slist_length ((GSList *) messages);
1697 message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), length);
1699 for (l = msgs; l != NULL; l = g_slist_next (l)) {
1702 EmpathyMessage *message = EMPATHY_MESSAGE (l->data);
1704 m = g_queue_find (priv->pending_messages_queue, message);
1705 g_assert (m != NULL);
1706 g_queue_delete_link (priv->pending_messages_queue, m);
1708 if (empathy_message_is_incoming (message)) {
1709 guint id = empathy_message_get_id (message);
1710 g_array_append_val (message_ids, id);
1712 g_object_unref (message);
1715 if (message_ids->len > 0)
1716 acknowledge_messages (chat, message_ids);
1718 g_array_free (message_ids, TRUE);
1719 g_slist_free (msgs);
1723 empathy_tp_chat_acknowledge_all_messages (EmpathyTpChat *chat)
1725 empathy_tp_chat_acknowledge_messages (chat,
1726 (GSList *) empathy_tp_chat_get_pending_messages (chat));
1730 empathy_tp_chat_password_needed (EmpathyTpChat *self)
1732 EmpathyTpChatPriv *priv = GET_PRIV (self);
1734 return priv->password_flags & TP_CHANNEL_PASSWORD_FLAG_PROVIDE;
1738 provide_password_cb (TpChannel *channel,
1740 const GError *error,
1742 GObject *weak_object)
1744 GSimpleAsyncResult *result = user_data;
1746 if (error != NULL) {
1747 g_simple_async_result_set_from_error (result, error);
1749 else if (!correct) {
1750 /* The current D-Bus API is a bit weird so re-use the
1751 * AuthenticationFailed error */
1752 g_simple_async_result_set_error (result, TP_ERRORS,
1753 TP_ERROR_AUTHENTICATION_FAILED, "Wrong password");
1756 g_simple_async_result_complete (result);
1757 g_object_unref (result);
1761 empathy_tp_chat_provide_password_async (EmpathyTpChat *self,
1762 const gchar *password,
1763 GAsyncReadyCallback callback,
1766 EmpathyTpChatPriv *priv = GET_PRIV (self);
1767 GSimpleAsyncResult *result;
1769 result = g_simple_async_result_new (G_OBJECT (self),
1770 callback, user_data,
1771 empathy_tp_chat_provide_password_finish);
1773 tp_cli_channel_interface_password_call_provide_password
1774 (priv->channel, -1, password, provide_password_cb, result,
1775 NULL, G_OBJECT (self));
1779 empathy_tp_chat_provide_password_finish (EmpathyTpChat *self,
1780 GAsyncResult *result,
1783 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1787 g_return_val_if_fail (g_simple_async_result_is_valid (result,
1788 G_OBJECT (self), empathy_tp_chat_provide_password_finish), FALSE);
1794 * empathy_tp_chat_can_add_contact:
1796 * Returns: %TRUE if empathy_contact_list_add() will work for this channel.
1797 * That is if this chat is a 1-to-1 channel that can be upgraded to
1798 * a MUC using the Conference interface or if the channel is a MUC.
1801 empathy_tp_chat_can_add_contact (EmpathyTpChat *self)
1803 EmpathyTpChatPriv *priv;
1805 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (self), FALSE);
1807 priv = GET_PRIV (self);
1809 return priv->can_upgrade_to_muc ||
1810 tp_proxy_has_interface_by_id (priv->channel,
1811 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP);;
1815 leave_remove_members_cb (TpChannel *proxy,
1816 const GError *error,
1818 GObject *weak_object)
1820 EmpathyTpChat *self = user_data;
1825 DEBUG ("RemoveMembers failed (%s); closing the channel", error->message);
1826 empathy_tp_chat_close (self);
1830 empathy_tp_chat_leave (EmpathyTpChat *self)
1832 EmpathyTpChatPriv *priv = GET_PRIV (self);
1833 TpHandle self_handle;
1836 if (!tp_proxy_has_interface_by_id (priv->channel,
1837 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
1838 empathy_tp_chat_close (self);
1842 self_handle = tp_channel_group_get_self_handle (priv->channel);
1843 if (self_handle == 0) {
1844 /* we are not member of the channel */
1845 empathy_tp_chat_close (self);
1849 array = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), 1);
1850 g_array_insert_val (array, 0, self_handle);
1852 tp_cli_channel_interface_group_call_remove_members (priv->channel, -1, array,
1853 "", leave_remove_members_cb, self, NULL, G_OBJECT (self));
1855 g_array_free (array, TRUE);
1859 add_members_cb (TpChannel *proxy,
1860 const GError *error,
1862 GObject *weak_object)
1864 EmpathyTpChatPriv *priv = GET_PRIV (weak_object);
1866 if (error != NULL) {
1867 DEBUG ("Failed to join chat (%s): %s",
1868 tp_channel_get_identifier (priv->channel), error->message);
1873 empathy_tp_chat_join (EmpathyTpChat *self)
1875 EmpathyTpChatPriv *priv = GET_PRIV (self);
1876 TpHandle self_handle;
1879 self_handle = tp_channel_group_get_self_handle (priv->channel);
1881 members = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), 1);
1882 g_array_append_val (members, self_handle);
1884 tp_cli_channel_interface_group_call_add_members (priv->channel, -1, members,
1885 "", add_members_cb, NULL, NULL, G_OBJECT (self));
1887 g_array_free (members, TRUE);
1891 empathy_tp_chat_is_invited (EmpathyTpChat *self,
1894 EmpathyTpChatPriv *priv = GET_PRIV (self);
1895 TpHandle self_handle;
1897 if (!tp_proxy_has_interface (priv->channel, TP_IFACE_CHANNEL_INTERFACE_GROUP))
1900 self_handle = tp_channel_group_get_self_handle (priv->channel);
1901 if (self_handle == 0)
1904 return tp_channel_group_get_local_pending_info (priv->channel, self_handle,
1905 inviter, NULL, NULL);