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 if (flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_SCROLLBACK)
288 empathy_message_set_is_backlog (message, TRUE);
290 g_queue_push_tail (priv->messages_queue, message);
292 if (from_handle == 0) {
293 empathy_message_set_sender (message, priv->user);
294 tp_chat_emit_queued_messages (chat);
296 empathy_tp_contact_factory_get_from_handle (priv->connection,
298 tp_chat_got_sender_cb,
299 message, NULL, G_OBJECT (chat));
304 tp_chat_received_cb (TpChannel *channel,
310 const gchar *message_body,
314 EmpathyTpChat *chat = EMPATHY_TP_CHAT (chat_);
315 EmpathyTpChatPriv *priv = GET_PRIV (chat);
317 if (priv->channel == NULL)
320 if (priv->listing_pending_messages) {
324 DEBUG ("Message received: %s", message_body);
326 if (message_flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT &&
327 !tp_strdiff (message_body, "")) {
330 DEBUG ("Empty message with NonTextContent, ignoring and acking.");
332 ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
333 g_array_append_val (ids, message_id);
334 acknowledge_messages (chat, ids);
335 g_array_free (ids, TRUE);
340 tp_chat_build_message (chat,
351 tp_chat_sent_cb (TpChannel *channel,
354 const gchar *message_body,
358 EmpathyTpChat *chat = EMPATHY_TP_CHAT (chat_);
359 EmpathyTpChatPriv *priv = GET_PRIV (chat);
361 if (priv->channel == NULL)
364 DEBUG ("Message sent: %s", message_body);
366 tp_chat_build_message (chat,
377 tp_chat_send_error_cb (TpChannel *channel,
381 const gchar *message_body,
385 EmpathyTpChatPriv *priv = GET_PRIV (chat);
387 if (priv->channel == NULL)
390 DEBUG ("Error sending '%s' (%d)", message_body, error_code);
392 g_signal_emit (chat, signals[SEND_ERROR], 0, message_body, error_code);
396 tp_chat_send_cb (TpChannel *proxy,
401 EmpathyMessage *message = EMPATHY_MESSAGE (user_data);
404 DEBUG ("Error: %s", error->message);
405 g_signal_emit (chat, signals[SEND_ERROR], 0,
406 empathy_message_get_body (message),
407 TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN);
413 TpChannelChatState state;
417 tp_chat_state_changed_got_contact_cb (TpConnection *connection,
418 EmpathyContact *contact,
423 TpChannelChatState state;
426 DEBUG ("Error: %s", error->message);
430 state = GPOINTER_TO_UINT (user_data);
431 DEBUG ("Chat state changed for %s (%d): %d",
432 empathy_contact_get_name (contact),
433 empathy_contact_get_handle (contact), state);
435 g_signal_emit (chat, signals[CHAT_STATE_CHANGED], 0, contact, state);
439 tp_chat_state_changed_cb (TpChannel *channel,
441 TpChannelChatState state,
445 EmpathyTpChatPriv *priv = GET_PRIV (chat);
447 empathy_tp_contact_factory_get_from_handle (priv->connection, handle,
448 tp_chat_state_changed_got_contact_cb, GUINT_TO_POINTER (state),
453 tp_chat_list_pending_messages_cb (TpChannel *channel,
454 const GPtrArray *messages_list,
459 EmpathyTpChat *chat = EMPATHY_TP_CHAT (chat_);
460 EmpathyTpChatPriv *priv = GET_PRIV (chat);
462 GArray *empty_non_text_content_ids = NULL;
464 priv->listing_pending_messages = FALSE;
466 if (priv->channel == NULL)
470 DEBUG ("Error listing pending messages: %s", error->message);
474 for (i = 0; i < messages_list->len; i++) {
475 GValueArray *message_struct;
476 const gchar *message_body;
483 message_struct = g_ptr_array_index (messages_list, i);
485 message_id = g_value_get_uint (g_value_array_get_nth (message_struct, 0));
486 timestamp = g_value_get_uint (g_value_array_get_nth (message_struct, 1));
487 from_handle = g_value_get_uint (g_value_array_get_nth (message_struct, 2));
488 message_type = g_value_get_uint (g_value_array_get_nth (message_struct, 3));
489 message_flags = g_value_get_uint (g_value_array_get_nth (message_struct, 4));
490 message_body = g_value_get_string (g_value_array_get_nth (message_struct, 5));
492 DEBUG ("Message pending: %s", message_body);
494 if (message_flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT &&
495 !tp_strdiff (message_body, "")) {
496 DEBUG ("Empty message with NonTextContent, ignoring and acking.");
498 if (empty_non_text_content_ids == NULL) {
499 empty_non_text_content_ids = g_array_new (FALSE, FALSE, sizeof (guint));
502 g_array_append_val (empty_non_text_content_ids, message_id);
506 tp_chat_build_message (chat,
516 if (empty_non_text_content_ids != NULL) {
517 acknowledge_messages (chat, empty_non_text_content_ids);
518 g_array_free (empty_non_text_content_ids, TRUE);
525 tp_chat_property_flags_changed_cb (TpProxy *proxy,
526 const GPtrArray *properties,
530 EmpathyTpChatPriv *priv = GET_PRIV (chat);
533 if (priv->channel == NULL)
536 if (!priv->had_properties_list || !properties) {
540 for (i = 0; i < properties->len; i++) {
541 GValueArray *prop_struct;
542 EmpathyTpChatProperty *property;
546 prop_struct = g_ptr_array_index (properties, i);
547 id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
548 flags = g_value_get_uint (g_value_array_get_nth (prop_struct, 1));
550 for (j = 0; j < priv->properties->len; j++) {
551 property = g_ptr_array_index (priv->properties, j);
552 if (property->id == id) {
553 property->flags = flags;
554 DEBUG ("property %s flags changed: %d",
555 property->name, property->flags);
563 tp_chat_properties_changed_cb (TpProxy *proxy,
564 const GPtrArray *properties,
568 EmpathyTpChatPriv *priv = GET_PRIV (chat);
571 if (priv->channel == NULL)
574 if (!priv->had_properties_list || !properties) {
578 for (i = 0; i < properties->len; i++) {
579 GValueArray *prop_struct;
580 EmpathyTpChatProperty *property;
584 prop_struct = g_ptr_array_index (properties, i);
585 id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
586 src_value = g_value_get_boxed (g_value_array_get_nth (prop_struct, 1));
588 for (j = 0; j < priv->properties->len; j++) {
589 property = g_ptr_array_index (priv->properties, j);
590 if (property->id == id) {
591 if (property->value) {
592 g_value_copy (src_value, property->value);
594 property->value = tp_g_value_slice_dup (src_value);
597 DEBUG ("property %s changed", property->name);
598 g_signal_emit (chat, signals[PROPERTY_CHANGED], 0,
599 property->name, property->value);
607 tp_chat_get_properties_cb (TpProxy *proxy,
608 const GPtrArray *properties,
614 DEBUG ("Error getting properties: %s", error->message);
618 tp_chat_properties_changed_cb (proxy, properties, user_data, chat);
622 tp_chat_list_properties_cb (TpProxy *proxy,
623 const GPtrArray *properties,
628 EmpathyTpChatPriv *priv = GET_PRIV (chat);
632 if (priv->channel == NULL)
635 priv->had_properties_list = TRUE;
638 DEBUG ("Error listing properties: %s", error->message);
642 ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), properties->len);
643 priv->properties = g_ptr_array_sized_new (properties->len);
644 for (i = 0; i < properties->len; i++) {
645 GValueArray *prop_struct;
646 EmpathyTpChatProperty *property;
648 prop_struct = g_ptr_array_index (properties, i);
649 property = g_slice_new0 (EmpathyTpChatProperty);
650 property->id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
651 property->name = g_value_dup_string (g_value_array_get_nth (prop_struct, 1));
652 property->flags = g_value_get_uint (g_value_array_get_nth (prop_struct, 3));
654 DEBUG ("Adding property name=%s id=%d flags=%d",
655 property->name, property->id, property->flags);
656 g_ptr_array_add (priv->properties, property);
657 if (property->flags & TP_PROPERTY_FLAG_READ) {
658 g_array_append_val (ids, property->id);
662 tp_cli_properties_interface_call_get_properties (proxy, -1,
664 tp_chat_get_properties_cb,
668 g_array_free (ids, TRUE);
672 empathy_tp_chat_set_property (EmpathyTpChat *chat,
676 EmpathyTpChatPriv *priv = GET_PRIV (chat);
677 EmpathyTpChatProperty *property;
680 if (!priv->had_properties_list) {
684 for (i = 0; i < priv->properties->len; i++) {
685 property = g_ptr_array_index (priv->properties, i);
686 if (!tp_strdiff (property->name, name)) {
687 GPtrArray *properties;
690 GValue dest_value = {0, };
692 if (!(property->flags & TP_PROPERTY_FLAG_WRITE)) {
696 g_value_init (&id, G_TYPE_UINT);
697 g_value_init (&dest_value, G_TYPE_VALUE);
698 g_value_set_uint (&id, property->id);
699 g_value_set_boxed (&dest_value, value);
701 prop = g_value_array_new (2);
702 g_value_array_append (prop, &id);
703 g_value_array_append (prop, &dest_value);
705 properties = g_ptr_array_sized_new (1);
706 g_ptr_array_add (properties, prop);
708 DEBUG ("Set property %s", name);
709 tp_cli_properties_interface_call_set_properties (priv->channel, -1,
711 (tp_cli_properties_interface_callback_for_set_properties)
713 "Seting property", NULL,
716 g_ptr_array_free (properties, TRUE);
717 g_value_array_free (prop);
724 EmpathyTpChatProperty *
725 empathy_tp_chat_get_property (EmpathyTpChat *chat,
728 EmpathyTpChatPriv *priv = GET_PRIV (chat);
729 EmpathyTpChatProperty *property;
732 if (!priv->had_properties_list) {
736 for (i = 0; i < priv->properties->len; i++) {
737 property = g_ptr_array_index (priv->properties, i);
738 if (!tp_strdiff (property->name, name)) {
747 empathy_tp_chat_get_properties (EmpathyTpChat *chat)
749 EmpathyTpChatPriv *priv = GET_PRIV (chat);
751 return priv->properties;
755 tp_chat_dispose (GObject *object)
757 EmpathyTpChat *self = EMPATHY_TP_CHAT (object);
758 EmpathyTpChatPriv *priv = GET_PRIV (self);
760 if (priv->dispose_has_run)
763 priv->dispose_has_run = TRUE;
765 if (priv->connection != NULL)
766 g_object_unref (priv->connection);
767 priv->connection = NULL;
769 if (priv->channel != NULL) {
770 g_signal_handlers_disconnect_by_func (priv->channel,
771 tp_chat_invalidated_cb, self);
772 g_object_unref (priv->channel);
774 priv->channel = NULL;
776 if (priv->remote_contact != NULL)
777 g_object_unref (priv->remote_contact);
778 priv->remote_contact = NULL;
780 if (priv->user != NULL)
781 g_object_unref (priv->user);
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 check_almost_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)
844 tp_cli_channel_type_text_connect_to_received (priv->channel,
847 G_OBJECT (chat), NULL);
848 priv->listing_pending_messages = TRUE;
850 /* TpChat will be ready once ListPendingMessages returned and all the messages
851 * have been added to the pending messages queue. */
852 tp_cli_channel_type_text_call_list_pending_messages (priv->channel, -1,
854 tp_chat_list_pending_messages_cb,
858 tp_cli_channel_type_text_connect_to_sent (priv->channel,
861 G_OBJECT (chat), NULL);
862 tp_cli_channel_type_text_connect_to_send_error (priv->channel,
863 tp_chat_send_error_cb,
865 G_OBJECT (chat), NULL);
866 tp_cli_channel_interface_chat_state_connect_to_chat_state_changed (priv->channel,
867 tp_chat_state_changed_cb,
869 G_OBJECT (chat), NULL);
873 tp_chat_update_remote_contact (EmpathyTpChat *chat)
875 EmpathyTpChatPriv *priv = GET_PRIV (chat);
876 EmpathyContact *contact = NULL;
877 TpHandle self_handle;
878 TpHandleType handle_type;
881 /* If this is a named chatroom, never pretend it is a private chat */
882 tp_channel_get_handle (priv->channel, &handle_type);
883 if (handle_type == TP_HANDLE_TYPE_ROOM) {
887 /* This is an MSN chat, but it's the new style where 1-1 chats don't
888 * have the group interface. If it has the conference interface, then
889 * it is indeed a MUC. */
890 if (tp_proxy_has_interface_by_id (priv->channel,
891 EMP_IFACE_QUARK_CHANNEL_INTERFACE_CONFERENCE)) {
895 /* This is an MSN-like chat where anyone can join the chat at anytime.
896 * If there is only one non-self contact member, we are in a private
897 * chat and we set the "remote-contact" property to that contact. If
898 * there are more, set the "remote-contact" property to NULL and the
899 * UI will display a contact list. */
900 self_handle = tp_channel_group_get_self_handle (priv->channel);
901 for (l = priv->members; l; l = l->next) {
902 /* Skip self contact if member */
903 if (empathy_contact_get_handle (l->data) == self_handle) {
907 /* We have more than one remote contact, break */
908 if (contact != NULL) {
913 /* If we didn't find yet a remote contact, keep this one */
917 if (priv->remote_contact == contact) {
921 DEBUG ("Changing remote contact from %p to %p",
922 priv->remote_contact, contact);
924 if (priv->remote_contact) {
925 g_object_unref (priv->remote_contact);
928 priv->remote_contact = contact ? g_object_ref (contact) : NULL;
929 g_object_notify (G_OBJECT (chat), "remote-contact");
933 tp_chat_got_added_contacts_cb (TpConnection *connection,
935 EmpathyContact * const * contacts,
937 const TpHandle *failed,
942 EmpathyTpChatPriv *priv = GET_PRIV (chat);
944 const TpIntSet *members;
946 EmpathyContact *contact;
949 DEBUG ("Error: %s", error->message);
953 members = tp_channel_group_get_members (priv->channel);
954 for (i = 0; i < n_contacts; i++) {
955 contact = contacts[i];
956 handle = empathy_contact_get_handle (contact);
958 /* Make sure the contact is still member */
959 if (tp_intset_is_member (members, handle)) {
960 priv->members = g_list_prepend (priv->members,
961 g_object_ref (contact));
962 g_signal_emit_by_name (chat, "members-changed",
963 contact, NULL, 0, NULL, TRUE);
967 tp_chat_update_remote_contact (EMPATHY_TP_CHAT (chat));
968 check_almost_ready (EMPATHY_TP_CHAT (chat));
971 static EmpathyContact *
972 chat_lookup_contact (EmpathyTpChat *chat,
976 EmpathyTpChatPriv *priv = GET_PRIV (chat);
979 for (l = priv->members; l; l = l->next) {
980 EmpathyContact *c = l->data;
982 if (empathy_contact_get_handle (c) != handle) {
987 /* Caller takes the reference. */
988 priv->members = g_list_delete_link (priv->members, l);
1001 TpHandle old_handle;
1004 } ContactRenameData;
1006 static ContactRenameData *
1007 contact_rename_data_new (TpHandle handle,
1009 const gchar* message)
1011 ContactRenameData *data = g_new (ContactRenameData, 1);
1012 data->old_handle = handle;
1013 data->reason = reason;
1014 data->message = g_strdup (message);
1020 contact_rename_data_free (ContactRenameData* data)
1022 g_free (data->message);
1027 tp_chat_got_renamed_contacts_cb (TpConnection *connection,
1029 EmpathyContact * const * contacts,
1031 const TpHandle *failed,
1032 const GError *error,
1036 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1037 const TpIntSet *members;
1039 EmpathyContact *old = NULL, *new = NULL;
1040 ContactRenameData *rename_data = (ContactRenameData *) user_data;
1043 DEBUG ("Error: %s", error->message);
1047 /* renamed members can only be delivered one at a time */
1048 g_warn_if_fail (n_contacts == 1);
1052 members = tp_channel_group_get_members (priv->channel);
1053 handle = empathy_contact_get_handle (new);
1055 old = chat_lookup_contact (EMPATHY_TP_CHAT (chat),
1056 rename_data->old_handle, TRUE);
1058 /* Make sure the contact is still member */
1059 if (tp_intset_is_member (members, handle)) {
1060 priv->members = g_list_prepend (priv->members,
1061 g_object_ref (new));
1064 g_signal_emit_by_name (chat, "member-renamed",
1065 old, new, rename_data->reason,
1066 rename_data->message);
1067 g_object_unref (old);
1071 if (priv->user == old) {
1072 /* We change our nick */
1073 g_object_unref (priv->user);
1074 priv->user = g_object_ref (new);
1077 tp_chat_update_remote_contact (EMPATHY_TP_CHAT (chat));
1078 check_almost_ready (EMPATHY_TP_CHAT (chat));
1083 tp_chat_group_members_changed_cb (TpChannel *self,
1087 GArray *local_pending,
1088 GArray *remote_pending,
1091 EmpathyTpChat *chat)
1093 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1094 EmpathyContact *contact;
1095 EmpathyContact *actor_contact = NULL;
1097 ContactRenameData *rename_data;
1098 TpHandle old_handle;
1100 /* Contact renamed */
1101 if (reason == TP_CHANNEL_GROUP_CHANGE_REASON_RENAMED) {
1102 /* there can only be a single 'added' and a single 'removed' handle */
1103 g_warn_if_fail (removed->len == 1);
1104 g_warn_if_fail (added->len == 1);
1106 old_handle = g_array_index (removed, guint, 0);
1108 rename_data = contact_rename_data_new (old_handle, reason, message);
1109 empathy_tp_contact_factory_get_from_handles (priv->connection,
1110 added->len, (TpHandle *) added->data,
1111 tp_chat_got_renamed_contacts_cb,
1112 rename_data, (GDestroyNotify) contact_rename_data_free,
1118 actor_contact = chat_lookup_contact (chat, actor, FALSE);
1119 if (actor_contact == NULL) {
1120 /* FIXME: handle this a tad more gracefully: perhaps
1121 * the actor was a server op. We could use the
1122 * contact-ids detail of MembersChangedDetailed.
1124 DEBUG ("actor %u not a channel member", actor);
1128 /* Remove contacts that are not members anymore */
1129 for (i = 0; i < removed->len; i++) {
1130 contact = chat_lookup_contact (chat,
1131 g_array_index (removed, TpHandle, i), TRUE);
1133 if (contact != NULL) {
1134 g_signal_emit_by_name (chat, "members-changed", contact,
1135 actor_contact, reason, message,
1137 g_object_unref (contact);
1141 /* Request added contacts */
1142 if (added->len > 0) {
1143 empathy_tp_contact_factory_get_from_handles (priv->connection,
1144 added->len, (TpHandle *) added->data,
1145 tp_chat_got_added_contacts_cb, NULL, NULL,
1149 tp_chat_update_remote_contact (chat);
1151 if (actor_contact != NULL) {
1152 g_object_unref (actor_contact);
1157 tp_chat_got_remote_contact_cb (TpConnection *connection,
1158 EmpathyContact *contact,
1159 const GError *error,
1163 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1166 DEBUG ("Error: %s", error->message);
1167 empathy_tp_chat_leave (EMPATHY_TP_CHAT (chat));
1171 priv->remote_contact = g_object_ref (contact);
1172 g_object_notify (chat, "remote-contact");
1174 check_almost_ready (EMPATHY_TP_CHAT (chat));
1178 tp_chat_got_self_contact_cb (TpConnection *connection,
1179 EmpathyContact *contact,
1180 const GError *error,
1184 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1187 DEBUG ("Error: %s", error->message);
1188 empathy_tp_chat_leave (EMPATHY_TP_CHAT (chat));
1192 priv->user = g_object_ref (contact);
1193 empathy_contact_set_is_user (priv->user, TRUE);
1194 check_almost_ready (EMPATHY_TP_CHAT (chat));
1198 password_flags_changed_cb (TpChannel *channel,
1202 GObject *weak_object)
1204 EmpathyTpChat *self = EMPATHY_TP_CHAT (weak_object);
1205 EmpathyTpChatPriv *priv = GET_PRIV (self);
1206 gboolean was_needed, needed;
1208 was_needed = empathy_tp_chat_password_needed (self);
1210 priv->password_flags |= added;
1211 priv->password_flags ^= removed;
1213 needed = empathy_tp_chat_password_needed (self);
1215 if (was_needed != needed)
1216 g_object_notify (G_OBJECT (self), "password-needed");
1220 got_password_flags_cb (TpChannel *proxy,
1221 guint password_flags,
1222 const GError *error,
1224 GObject *weak_object)
1226 EmpathyTpChat *self = EMPATHY_TP_CHAT (weak_object);
1227 EmpathyTpChatPriv *priv = GET_PRIV (self);
1229 priv->got_password_flags = TRUE;
1230 priv->password_flags = password_flags;
1232 check_almost_ready (EMPATHY_TP_CHAT (self));
1236 tp_chat_constructor (GType type,
1238 GObjectConstructParam *props)
1241 EmpathyTpChatPriv *priv;
1244 chat = G_OBJECT_CLASS (empathy_tp_chat_parent_class)->constructor (type, n_props, props);
1246 priv = GET_PRIV (chat);
1248 priv->connection = g_object_ref (tp_channel_borrow_connection (priv->channel));
1249 tp_g_signal_connect_object (priv->channel, "invalidated",
1250 G_CALLBACK (tp_chat_invalidated_cb),
1253 if (tp_proxy_has_interface_by_id (priv->channel,
1254 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
1255 const TpIntSet *members;
1258 /* Get self contact from the group's self handle */
1259 handle = tp_channel_group_get_self_handle (priv->channel);
1260 empathy_tp_contact_factory_get_from_handle (priv->connection,
1261 handle, tp_chat_got_self_contact_cb,
1264 /* Get initial member contacts */
1265 members = tp_channel_group_get_members (priv->channel);
1266 handles = tp_intset_to_array (members);
1267 empathy_tp_contact_factory_get_from_handles (priv->connection,
1268 handles->len, (TpHandle *) handles->data,
1269 tp_chat_got_added_contacts_cb, NULL, NULL, chat);
1271 priv->can_upgrade_to_muc = FALSE;
1273 tp_g_signal_connect_object (priv->channel, "group-members-changed",
1274 G_CALLBACK (tp_chat_group_members_changed_cb), chat, 0);
1276 EmpathyDispatcher *dispatcher = empathy_dispatcher_dup_singleton ();
1279 /* Get the self contact from the connection's self handle */
1280 handle = tp_connection_get_self_handle (priv->connection);
1281 empathy_tp_contact_factory_get_from_handle (priv->connection,
1282 handle, tp_chat_got_self_contact_cb,
1285 /* Get the remote contact */
1286 handle = tp_channel_get_handle (priv->channel, NULL);
1287 empathy_tp_contact_factory_get_from_handle (priv->connection,
1288 handle, tp_chat_got_remote_contact_cb,
1291 list = empathy_dispatcher_find_requestable_channel_classes (
1292 dispatcher, priv->connection,
1293 tp_channel_get_channel_type (priv->channel),
1294 TP_UNKNOWN_HANDLE_TYPE, NULL);
1296 for (ptr = list; ptr; ptr = ptr->next) {
1297 GValueArray *array = ptr->data;
1298 const char **oprops = g_value_get_boxed (
1299 g_value_array_get_nth (array, 1));
1301 if (tp_strv_contains (oprops, EMP_IFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels")) {
1302 priv->can_upgrade_to_muc = TRUE;
1308 g_object_unref (dispatcher);
1311 if (tp_proxy_has_interface_by_id (priv->channel,
1312 TP_IFACE_QUARK_PROPERTIES_INTERFACE)) {
1313 tp_cli_properties_interface_call_list_properties (priv->channel, -1,
1314 tp_chat_list_properties_cb,
1317 tp_cli_properties_interface_connect_to_properties_changed (priv->channel,
1318 tp_chat_properties_changed_cb,
1320 G_OBJECT (chat), NULL);
1321 tp_cli_properties_interface_connect_to_property_flags_changed (priv->channel,
1322 tp_chat_property_flags_changed_cb,
1324 G_OBJECT (chat), NULL);
1327 /* Check if the chat is password protected */
1328 if (tp_proxy_has_interface_by_id (priv->channel,
1329 TP_IFACE_QUARK_CHANNEL_INTERFACE_PASSWORD)) {
1330 priv->got_password_flags = FALSE;
1332 tp_cli_channel_interface_password_connect_to_password_flags_changed
1333 (priv->channel, password_flags_changed_cb, chat, NULL,
1334 G_OBJECT (chat), NULL);
1336 tp_cli_channel_interface_password_call_get_password_flags
1337 (priv->channel, -1, got_password_flags_cb, chat, NULL, chat);
1339 /* No Password interface, so no need to fetch the password flags */
1340 priv->got_password_flags = TRUE;
1347 tp_chat_get_property (GObject *object,
1352 EmpathyTpChat *self = EMPATHY_TP_CHAT (object);
1353 EmpathyTpChatPriv *priv = GET_PRIV (object);
1357 g_value_set_object (value, priv->channel);
1359 case PROP_REMOTE_CONTACT:
1360 g_value_set_object (value, priv->remote_contact);
1363 g_value_set_boolean (value, priv->ready);
1365 case PROP_PASSWORD_NEEDED:
1366 g_value_set_boolean (value, empathy_tp_chat_password_needed (self));
1369 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1375 tp_chat_set_property (GObject *object,
1377 const GValue *value,
1380 EmpathyTpChatPriv *priv = GET_PRIV (object);
1384 priv->channel = g_value_dup_object (value);
1387 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1393 empathy_tp_chat_class_init (EmpathyTpChatClass *klass)
1395 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1397 object_class->dispose = tp_chat_dispose;
1398 object_class->finalize = tp_chat_finalize;
1399 object_class->constructor = tp_chat_constructor;
1400 object_class->get_property = tp_chat_get_property;
1401 object_class->set_property = tp_chat_set_property;
1403 g_object_class_install_property (object_class,
1405 g_param_spec_object ("channel",
1406 "telepathy channel",
1407 "The text channel for the chat",
1410 G_PARAM_CONSTRUCT_ONLY));
1412 g_object_class_install_property (object_class,
1413 PROP_REMOTE_CONTACT,
1414 g_param_spec_object ("remote-contact",
1415 "The remote contact",
1416 "The remote contact if there is no group iface on the channel",
1417 EMPATHY_TYPE_CONTACT,
1420 g_object_class_install_property (object_class,
1422 g_param_spec_boolean ("ready",
1423 "Is the object ready",
1424 "This object can't be used until this becomes true",
1428 g_object_class_install_property (object_class,
1429 PROP_PASSWORD_NEEDED,
1430 g_param_spec_boolean ("password-needed",
1432 "TRUE if a password is needed to join the channel",
1437 signals[MESSAGE_RECEIVED] =
1438 g_signal_new ("message-received",
1439 G_TYPE_FROM_CLASS (klass),
1443 g_cclosure_marshal_VOID__OBJECT,
1445 1, EMPATHY_TYPE_MESSAGE);
1447 signals[SEND_ERROR] =
1448 g_signal_new ("send-error",
1449 G_TYPE_FROM_CLASS (klass),
1453 _empathy_marshal_VOID__STRING_UINT,
1455 2, G_TYPE_STRING, G_TYPE_UINT);
1457 signals[CHAT_STATE_CHANGED] =
1458 g_signal_new ("chat-state-changed",
1459 G_TYPE_FROM_CLASS (klass),
1463 _empathy_marshal_VOID__OBJECT_UINT,
1465 2, EMPATHY_TYPE_CONTACT, G_TYPE_UINT);
1467 signals[PROPERTY_CHANGED] =
1468 g_signal_new ("property-changed",
1469 G_TYPE_FROM_CLASS (klass),
1473 _empathy_marshal_VOID__STRING_BOXED,
1475 2, G_TYPE_STRING, G_TYPE_VALUE);
1478 g_signal_new ("destroy",
1479 G_TYPE_FROM_CLASS (klass),
1483 g_cclosure_marshal_VOID__VOID,
1487 g_type_class_add_private (object_class, sizeof (EmpathyTpChatPriv));
1491 empathy_tp_chat_init (EmpathyTpChat *chat)
1493 EmpathyTpChatPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chat,
1494 EMPATHY_TYPE_TP_CHAT, EmpathyTpChatPriv);
1497 priv->messages_queue = g_queue_new ();
1498 priv->pending_messages_queue = g_queue_new ();
1502 tp_chat_iface_init (EmpathyContactListIface *iface)
1504 iface->add = tp_chat_add;
1505 iface->remove = tp_chat_remove;
1506 iface->get_members = tp_chat_get_members;
1510 empathy_tp_chat_new (TpChannel *channel)
1512 return g_object_new (EMPATHY_TYPE_TP_CHAT,
1518 empathy_tp_chat_close (EmpathyTpChat *chat) {
1519 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1521 /* If there are still messages left, it'll come back..
1522 * We loose the ordering of sent messages though */
1523 tp_cli_channel_call_close (priv->channel, -1, tp_chat_async_cb,
1524 "closing channel", NULL, NULL);
1528 empathy_tp_chat_get_id (EmpathyTpChat *chat)
1530 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1534 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1536 id = tp_channel_get_identifier (priv->channel);
1537 if (!EMP_STR_EMPTY (id))
1539 else if (priv->remote_contact)
1540 return empathy_contact_get_id (priv->remote_contact);
1547 empathy_tp_chat_get_remote_contact (EmpathyTpChat *chat)
1549 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1551 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1552 g_return_val_if_fail (priv->ready, NULL);
1554 return priv->remote_contact;
1558 empathy_tp_chat_get_channel (EmpathyTpChat *chat)
1560 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1562 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1564 return priv->channel;
1568 empathy_tp_chat_get_connection (EmpathyTpChat *chat)
1570 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1572 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1574 return tp_channel_borrow_connection (priv->channel);
1578 empathy_tp_chat_is_ready (EmpathyTpChat *chat)
1580 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1582 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), FALSE);
1588 empathy_tp_chat_send (EmpathyTpChat *chat,
1589 EmpathyMessage *message)
1591 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1592 const gchar *message_body;
1593 TpChannelTextMessageType message_type;
1595 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1596 g_return_if_fail (EMPATHY_IS_MESSAGE (message));
1597 g_return_if_fail (priv->ready);
1599 message_body = empathy_message_get_body (message);
1600 message_type = empathy_message_get_tptype (message);
1602 DEBUG ("Sending message: %s", message_body);
1603 tp_cli_channel_type_text_call_send (priv->channel, -1,
1607 g_object_ref (message),
1608 (GDestroyNotify) g_object_unref,
1613 empathy_tp_chat_set_state (EmpathyTpChat *chat,
1614 TpChannelChatState state)
1616 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1618 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1619 g_return_if_fail (priv->ready);
1621 if (tp_proxy_has_interface_by_id (priv->channel,
1622 TP_IFACE_QUARK_CHANNEL_INTERFACE_CHAT_STATE)) {
1623 DEBUG ("Set state: %d", state);
1624 tp_cli_channel_interface_chat_state_call_set_chat_state (priv->channel, -1,
1627 "setting chat state",
1635 empathy_tp_chat_get_pending_messages (EmpathyTpChat *chat)
1637 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1639 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1640 g_return_val_if_fail (priv->ready, NULL);
1642 return priv->pending_messages_queue->head;
1646 acknowledge_messages (EmpathyTpChat *chat, GArray *ids) {
1647 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1649 tp_cli_channel_type_text_call_acknowledge_pending_messages (
1650 priv->channel, -1, ids, tp_chat_async_cb,
1651 "acknowledging received message", NULL, G_OBJECT (chat));
1655 empathy_tp_chat_acknowledge_message (EmpathyTpChat *chat,
1656 EmpathyMessage *message) {
1657 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1658 GArray *message_ids;
1662 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1663 g_return_if_fail (priv->ready);
1665 if (!empathy_message_is_incoming (message))
1668 message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
1670 id = empathy_message_get_id (message);
1671 g_array_append_val (message_ids, id);
1672 acknowledge_messages (chat, message_ids);
1673 g_array_free (message_ids, TRUE);
1676 m = g_queue_find (priv->pending_messages_queue, message);
1677 g_assert (m != NULL);
1678 g_queue_delete_link (priv->pending_messages_queue, m);
1679 g_object_unref (message);
1683 empathy_tp_chat_acknowledge_messages (EmpathyTpChat *chat,
1684 const GSList *messages) {
1685 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1686 /* Copy messages as the messges list (probably is) our own */
1687 GSList *msgs = g_slist_copy ((GSList *) messages);
1690 GArray *message_ids;
1692 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1693 g_return_if_fail (priv->ready);
1695 length = g_slist_length ((GSList *) messages);
1700 message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), length);
1702 for (l = msgs; l != NULL; l = g_slist_next (l)) {
1705 EmpathyMessage *message = EMPATHY_MESSAGE (l->data);
1707 m = g_queue_find (priv->pending_messages_queue, message);
1708 g_assert (m != NULL);
1709 g_queue_delete_link (priv->pending_messages_queue, m);
1711 if (empathy_message_is_incoming (message)) {
1712 guint id = empathy_message_get_id (message);
1713 g_array_append_val (message_ids, id);
1715 g_object_unref (message);
1718 if (message_ids->len > 0)
1719 acknowledge_messages (chat, message_ids);
1721 g_array_free (message_ids, TRUE);
1722 g_slist_free (msgs);
1726 empathy_tp_chat_acknowledge_all_messages (EmpathyTpChat *chat)
1728 empathy_tp_chat_acknowledge_messages (chat,
1729 (GSList *) empathy_tp_chat_get_pending_messages (chat));
1733 empathy_tp_chat_password_needed (EmpathyTpChat *self)
1735 EmpathyTpChatPriv *priv = GET_PRIV (self);
1737 return priv->password_flags & TP_CHANNEL_PASSWORD_FLAG_PROVIDE;
1741 provide_password_cb (TpChannel *channel,
1743 const GError *error,
1745 GObject *weak_object)
1747 GSimpleAsyncResult *result = user_data;
1749 if (error != NULL) {
1750 g_simple_async_result_set_from_error (result, error);
1752 else if (!correct) {
1753 /* The current D-Bus API is a bit weird so re-use the
1754 * AuthenticationFailed error */
1755 g_simple_async_result_set_error (result, TP_ERRORS,
1756 TP_ERROR_AUTHENTICATION_FAILED, "Wrong password");
1759 g_simple_async_result_complete (result);
1760 g_object_unref (result);
1764 empathy_tp_chat_provide_password_async (EmpathyTpChat *self,
1765 const gchar *password,
1766 GAsyncReadyCallback callback,
1769 EmpathyTpChatPriv *priv = GET_PRIV (self);
1770 GSimpleAsyncResult *result;
1772 result = g_simple_async_result_new (G_OBJECT (self),
1773 callback, user_data,
1774 empathy_tp_chat_provide_password_finish);
1776 tp_cli_channel_interface_password_call_provide_password
1777 (priv->channel, -1, password, provide_password_cb, result,
1778 NULL, G_OBJECT (self));
1782 empathy_tp_chat_provide_password_finish (EmpathyTpChat *self,
1783 GAsyncResult *result,
1786 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1790 g_return_val_if_fail (g_simple_async_result_is_valid (result,
1791 G_OBJECT (self), empathy_tp_chat_provide_password_finish), FALSE);
1797 * empathy_tp_chat_can_add_contact:
1799 * Returns: %TRUE if empathy_contact_list_add() will work for this channel.
1800 * That is if this chat is a 1-to-1 channel that can be upgraded to
1801 * a MUC using the Conference interface or if the channel is a MUC.
1804 empathy_tp_chat_can_add_contact (EmpathyTpChat *self)
1806 EmpathyTpChatPriv *priv;
1808 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (self), FALSE);
1810 priv = GET_PRIV (self);
1812 return priv->can_upgrade_to_muc ||
1813 tp_proxy_has_interface_by_id (priv->channel,
1814 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP);;
1818 leave_remove_members_cb (TpChannel *proxy,
1819 const GError *error,
1821 GObject *weak_object)
1823 EmpathyTpChat *self = user_data;
1828 DEBUG ("RemoveMembers failed (%s); closing the channel", error->message);
1829 empathy_tp_chat_close (self);
1833 empathy_tp_chat_leave (EmpathyTpChat *self)
1835 EmpathyTpChatPriv *priv = GET_PRIV (self);
1836 TpHandle self_handle;
1839 if (!tp_proxy_has_interface_by_id (priv->channel,
1840 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
1841 empathy_tp_chat_close (self);
1845 self_handle = tp_channel_group_get_self_handle (priv->channel);
1846 if (self_handle == 0) {
1847 /* we are not member of the channel */
1848 empathy_tp_chat_close (self);
1852 array = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), 1);
1853 g_array_insert_val (array, 0, self_handle);
1855 tp_cli_channel_interface_group_call_remove_members (priv->channel, -1, array,
1856 "", leave_remove_members_cb, self, NULL, G_OBJECT (self));
1858 g_array_free (array, TRUE);
1862 add_members_cb (TpChannel *proxy,
1863 const GError *error,
1865 GObject *weak_object)
1867 EmpathyTpChatPriv *priv = GET_PRIV (weak_object);
1869 if (error != NULL) {
1870 DEBUG ("Failed to join chat (%s): %s",
1871 tp_channel_get_identifier (priv->channel), error->message);
1876 empathy_tp_chat_join (EmpathyTpChat *self)
1878 EmpathyTpChatPriv *priv = GET_PRIV (self);
1879 TpHandle self_handle;
1882 self_handle = tp_channel_group_get_self_handle (priv->channel);
1884 members = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), 1);
1885 g_array_append_val (members, self_handle);
1887 tp_cli_channel_interface_group_call_add_members (priv->channel, -1, members,
1888 "", add_members_cb, NULL, NULL, G_OBJECT (self));
1890 g_array_free (members, TRUE);
1894 empathy_tp_chat_is_invited (EmpathyTpChat *self,
1897 EmpathyTpChatPriv *priv = GET_PRIV (self);
1898 TpHandle self_handle;
1900 if (!tp_proxy_has_interface (priv->channel, TP_IFACE_CHANNEL_INTERFACE_GROUP))
1903 self_handle = tp_channel_group_get_self_handle (priv->channel);
1904 if (self_handle == 0)
1907 return tp_channel_group_get_local_pending_info (priv->channel, self_handle,
1908 inviter, NULL, NULL);