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-marshal.h"
34 #include "empathy-request-util.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;
45 TpConnection *connection;
47 EmpathyContact *remote_contact;
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);
84 static guint signals[LAST_SIGNAL];
86 G_DEFINE_TYPE_WITH_CODE (EmpathyTpChat, empathy_tp_chat, G_TYPE_OBJECT,
87 G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CONTACT_LIST,
90 static void acknowledge_messages (EmpathyTpChat *chat, GArray *ids);
93 tp_chat_invalidated_cb (TpProxy *proxy,
99 DEBUG ("Channel invalidated: %s", message);
100 g_signal_emit (chat, signals[DESTROY], 0);
104 tp_chat_async_cb (TpChannel *proxy,
107 GObject *weak_object)
110 DEBUG ("Error %s: %s", (gchar *) user_data, error->message);
115 create_conference_cb (GObject *source,
116 GAsyncResult *result,
119 GError *error = NULL;
121 if (!tp_account_channel_request_create_channel_finish (
122 TP_ACCOUNT_CHANNEL_REQUEST (source), result, &error)) {
123 DEBUG ("Failed to create conference channel: %s", error->message);
124 g_error_free (error);
129 tp_chat_add (EmpathyContactList *list,
130 EmpathyContact *contact,
131 const gchar *message)
133 EmpathyTpChatPriv *priv = GET_PRIV (list);
135 if (tp_proxy_has_interface_by_id (priv->channel,
136 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
138 GArray handles = {(gchar *) &handle, 1};
140 g_return_if_fail (EMPATHY_IS_TP_CHAT (list));
141 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
143 handle = empathy_contact_get_handle (contact);
144 tp_cli_channel_interface_group_call_add_members (priv->channel,
145 -1, &handles, NULL, NULL, NULL, NULL, NULL);
146 } else if (priv->can_upgrade_to_muc) {
147 TpAccountChannelRequest *req;
149 const char *object_path;
150 GPtrArray channels = { (gpointer *) &object_path, 1 };
151 const char *invitees[2] = { NULL, };
153 invitees[0] = empathy_contact_get_id (contact);
154 object_path = tp_proxy_get_object_path (priv->channel);
157 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
158 TP_IFACE_CHANNEL_TYPE_TEXT,
159 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
161 TP_PROP_CHANNEL_INTERFACE_CONFERENCE_INITIAL_CHANNELS,
162 TP_ARRAY_TYPE_OBJECT_PATH_LIST, &channels,
163 TP_PROP_CHANNEL_INTERFACE_CONFERENCE_INITIAL_INVITEE_IDS,
164 G_TYPE_STRV, invitees,
165 /* FIXME: InvitationMessage ? */
168 req = tp_account_channel_request_new (priv->account, props,
169 TP_USER_ACTION_TIME_NOT_USER_ACTION);
171 /* Although this is a MUC, it's anonymous, so CreateChannel is
173 tp_account_channel_request_create_channel_async (req, EMPATHY_CHAT_BUS_NAME,
174 NULL, create_conference_cb, NULL);
176 g_object_unref (req);
177 g_hash_table_unref (props);
179 g_warning ("Cannot add to this channel");
184 tp_chat_remove (EmpathyContactList *list,
185 EmpathyContact *contact,
186 const gchar *message)
188 EmpathyTpChatPriv *priv = GET_PRIV (list);
190 GArray handles = {(gchar *) &handle, 1};
192 g_return_if_fail (EMPATHY_IS_TP_CHAT (list));
193 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
195 handle = empathy_contact_get_handle (contact);
196 tp_cli_channel_interface_group_call_remove_members (priv->channel, -1,
203 tp_chat_get_members (EmpathyContactList *list)
205 EmpathyTpChatPriv *priv = GET_PRIV (list);
206 GList *members = NULL;
208 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (list), NULL);
211 members = g_list_copy (priv->members);
212 g_list_foreach (members, (GFunc) g_object_ref, NULL);
214 members = g_list_prepend (members, g_object_ref (priv->user));
215 if (priv->remote_contact != NULL)
216 members = g_list_prepend (members, g_object_ref (priv->remote_contact));
223 check_ready (EmpathyTpChat *chat)
225 EmpathyTpChatPriv *priv = GET_PRIV (chat);
230 if (g_queue_get_length (priv->messages_queue) > 0)
236 g_object_notify (G_OBJECT (chat), "ready");
240 tp_chat_emit_queued_messages (EmpathyTpChat *chat)
242 EmpathyTpChatPriv *priv = GET_PRIV (chat);
243 EmpathyMessage *message;
245 /* Check if we can now emit some queued messages */
246 while ((message = g_queue_peek_head (priv->messages_queue)) != NULL) {
247 if (empathy_message_get_sender (message) == NULL) {
251 DEBUG ("Queued message ready");
252 g_queue_pop_head (priv->messages_queue);
253 g_queue_push_tail (priv->pending_messages_queue, message);
254 g_signal_emit (chat, signals[MESSAGE_RECEIVED], 0, message);
261 tp_chat_got_sender_cb (TpConnection *connection,
262 EmpathyContact *contact,
267 EmpathyTpChatPriv *priv = GET_PRIV (chat);
270 DEBUG ("Error: %s", error->message);
271 /* Do not block the message queue, just drop this message */
272 g_queue_remove (priv->messages_queue, message);
274 empathy_message_set_sender (message, contact);
277 tp_chat_emit_queued_messages (EMPATHY_TP_CHAT (chat));
281 tp_chat_build_message (EmpathyTpChat *chat,
285 EmpathyTpChatPriv *priv;
286 EmpathyMessage *message;
289 priv = GET_PRIV (chat);
291 message = empathy_message_new_from_tp_message (msg, incoming);
292 /* FIXME: this is actually a lie for incoming messages. */
293 empathy_message_set_receiver (message, priv->user);
295 g_queue_push_tail (priv->messages_queue, message);
297 sender = tp_signalled_message_get_sender (msg);
298 g_assert (sender != NULL);
300 if (tp_contact_get_handle (sender) == 0) {
301 empathy_message_set_sender (message, priv->user);
302 tp_chat_emit_queued_messages (chat);
304 empathy_tp_contact_factory_get_from_handle (priv->connection,
305 tp_contact_get_handle (sender),
306 tp_chat_got_sender_cb,
307 message, NULL, G_OBJECT (chat));
312 message_received_cb (TpTextChannel *channel,
316 EmpathyTpChatPriv *priv = GET_PRIV (chat);
319 message_body = tp_message_to_text (message, NULL);
321 DEBUG ("Message received from channel %s: %s",
322 tp_proxy_get_object_path (channel), message_body);
324 if (message_body == NULL) {
325 DEBUG ("Empty message with NonTextContent, ignoring and acking.");
327 tp_text_channel_ack_message_async (TP_TEXT_CHANNEL (priv->channel),
328 message, NULL, NULL);
332 tp_chat_build_message (chat, message, TRUE);
334 g_free (message_body);
338 message_sent_cb (TpTextChannel *channel,
340 TpMessageSendingFlags flags,
346 message_body = tp_message_to_text (message, NULL);
348 DEBUG ("Message sent: %s", message_body);
350 tp_chat_build_message (chat, message, FALSE);
352 g_free (message_body);
356 tp_chat_send_error_cb (TpChannel *channel,
360 const gchar *message_body,
364 EmpathyTpChatPriv *priv = GET_PRIV (chat);
366 if (priv->channel == NULL)
369 DEBUG ("Error sending '%s' (%d)", message_body, error_code);
371 g_signal_emit (chat, signals[SEND_ERROR], 0, message_body, error_code);
375 tp_chat_send_cb (TpChannel *proxy,
380 EmpathyMessage *message = EMPATHY_MESSAGE (user_data);
383 DEBUG ("Error: %s", error->message);
384 g_signal_emit (chat, signals[SEND_ERROR], 0,
385 empathy_message_get_body (message),
386 TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN);
392 TpChannelChatState state;
396 tp_chat_state_changed_got_contact_cb (TpConnection *connection,
397 EmpathyContact *contact,
402 TpChannelChatState state;
405 DEBUG ("Error: %s", error->message);
409 state = GPOINTER_TO_UINT (user_data);
410 DEBUG ("Chat state changed for %s (%d): %d",
411 empathy_contact_get_alias (contact),
412 empathy_contact_get_handle (contact), state);
414 g_signal_emit (chat, signals[CHAT_STATE_CHANGED], 0, contact, state);
418 tp_chat_state_changed_cb (TpChannel *channel,
420 TpChannelChatState state,
424 EmpathyTpChatPriv *priv = GET_PRIV (chat);
426 empathy_tp_contact_factory_get_from_handle (priv->connection, handle,
427 tp_chat_state_changed_got_contact_cb, GUINT_TO_POINTER (state),
432 list_pending_messages (EmpathyTpChat *self)
434 EmpathyTpChatPriv *priv = GET_PRIV (self);
437 g_assert (priv->channel != NULL);
439 messages = tp_text_channel_get_pending_messages (
440 TP_TEXT_CHANNEL (priv->channel));
442 for (l = messages; l != NULL; l = g_list_next (l)) {
443 TpMessage *message = l->data;
446 message_body = tp_message_to_text (message, NULL);
448 DEBUG ("Message pending: %s", message_body);
450 if (message_body == NULL) {
451 DEBUG ("Empty message with NonTextContent, ignoring and acking.");
453 tp_text_channel_ack_message_async (TP_TEXT_CHANNEL (priv->channel),
454 message, NULL, NULL);
458 tp_chat_build_message (self, message, TRUE);
460 g_free (message_body);
463 g_list_free (messages);
467 tp_chat_property_flags_changed_cb (TpProxy *proxy,
468 const GPtrArray *properties,
472 EmpathyTpChatPriv *priv = GET_PRIV (chat);
475 if (priv->channel == NULL)
478 if (!priv->had_properties_list || !properties) {
482 for (i = 0; i < properties->len; i++) {
483 GValueArray *prop_struct;
484 EmpathyTpChatProperty *property;
488 prop_struct = g_ptr_array_index (properties, i);
489 id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
490 flags = g_value_get_uint (g_value_array_get_nth (prop_struct, 1));
492 for (j = 0; j < priv->properties->len; j++) {
493 property = g_ptr_array_index (priv->properties, j);
494 if (property->id == id) {
495 property->flags = flags;
496 DEBUG ("property %s flags changed: %d",
497 property->name, property->flags);
505 tp_chat_properties_changed_cb (TpProxy *proxy,
506 const GPtrArray *properties,
510 EmpathyTpChatPriv *priv = GET_PRIV (chat);
513 if (priv->channel == NULL)
516 if (!priv->had_properties_list || !properties) {
520 for (i = 0; i < properties->len; i++) {
521 GValueArray *prop_struct;
522 EmpathyTpChatProperty *property;
526 prop_struct = g_ptr_array_index (properties, i);
527 id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
528 src_value = g_value_get_boxed (g_value_array_get_nth (prop_struct, 1));
530 for (j = 0; j < priv->properties->len; j++) {
531 property = g_ptr_array_index (priv->properties, j);
532 if (property->id == id) {
533 if (property->value) {
534 g_value_copy (src_value, property->value);
536 property->value = tp_g_value_slice_dup (src_value);
539 DEBUG ("property %s changed", property->name);
540 g_signal_emit (chat, signals[PROPERTY_CHANGED], 0,
541 property->name, property->value);
549 tp_chat_get_properties_cb (TpProxy *proxy,
550 const GPtrArray *properties,
556 DEBUG ("Error getting properties: %s", error->message);
560 tp_chat_properties_changed_cb (proxy, properties, user_data, chat);
564 tp_chat_list_properties_cb (TpProxy *proxy,
565 const GPtrArray *properties,
570 EmpathyTpChatPriv *priv = GET_PRIV (chat);
574 if (priv->channel == NULL)
577 priv->had_properties_list = TRUE;
580 DEBUG ("Error listing properties: %s", error->message);
584 ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), properties->len);
585 priv->properties = g_ptr_array_sized_new (properties->len);
586 for (i = 0; i < properties->len; i++) {
587 GValueArray *prop_struct;
588 EmpathyTpChatProperty *property;
590 prop_struct = g_ptr_array_index (properties, i);
591 property = g_slice_new0 (EmpathyTpChatProperty);
592 property->id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
593 property->name = g_value_dup_string (g_value_array_get_nth (prop_struct, 1));
594 property->flags = g_value_get_uint (g_value_array_get_nth (prop_struct, 3));
596 DEBUG ("Adding property name=%s id=%d flags=%d",
597 property->name, property->id, property->flags);
598 g_ptr_array_add (priv->properties, property);
599 if (property->flags & TP_PROPERTY_FLAG_READ) {
600 g_array_append_val (ids, property->id);
604 tp_cli_properties_interface_call_get_properties (proxy, -1,
606 tp_chat_get_properties_cb,
610 g_array_free (ids, TRUE);
614 empathy_tp_chat_set_property (EmpathyTpChat *chat,
618 EmpathyTpChatPriv *priv = GET_PRIV (chat);
619 EmpathyTpChatProperty *property;
622 if (!priv->had_properties_list) {
626 for (i = 0; i < priv->properties->len; i++) {
627 property = g_ptr_array_index (priv->properties, i);
628 if (!tp_strdiff (property->name, name)) {
629 GPtrArray *properties;
632 GValue dest_value = {0, };
634 if (!(property->flags & TP_PROPERTY_FLAG_WRITE)) {
638 g_value_init (&id, G_TYPE_UINT);
639 g_value_init (&dest_value, G_TYPE_VALUE);
640 g_value_set_uint (&id, property->id);
641 g_value_set_boxed (&dest_value, value);
643 prop = g_value_array_new (2);
644 g_value_array_append (prop, &id);
645 g_value_array_append (prop, &dest_value);
647 properties = g_ptr_array_sized_new (1);
648 g_ptr_array_add (properties, prop);
650 DEBUG ("Set property %s", name);
651 tp_cli_properties_interface_call_set_properties (priv->channel, -1,
653 (tp_cli_properties_interface_callback_for_set_properties)
655 "Seting property", NULL,
658 g_ptr_array_free (properties, TRUE);
659 g_value_array_free (prop);
666 EmpathyTpChatProperty *
667 empathy_tp_chat_get_property (EmpathyTpChat *chat,
670 EmpathyTpChatPriv *priv = GET_PRIV (chat);
671 EmpathyTpChatProperty *property;
674 if (!priv->had_properties_list) {
678 for (i = 0; i < priv->properties->len; i++) {
679 property = g_ptr_array_index (priv->properties, i);
680 if (!tp_strdiff (property->name, name)) {
689 empathy_tp_chat_get_properties (EmpathyTpChat *chat)
691 EmpathyTpChatPriv *priv = GET_PRIV (chat);
693 return priv->properties;
697 tp_chat_dispose (GObject *object)
699 EmpathyTpChat *self = EMPATHY_TP_CHAT (object);
700 EmpathyTpChatPriv *priv = GET_PRIV (self);
702 if (priv->dispose_has_run)
705 priv->dispose_has_run = TRUE;
707 tp_clear_object (&priv->account);
709 if (priv->connection != NULL)
710 g_object_unref (priv->connection);
711 priv->connection = NULL;
713 if (priv->channel != NULL) {
714 g_signal_handlers_disconnect_by_func (priv->channel,
715 tp_chat_invalidated_cb, self);
716 g_object_unref (priv->channel);
718 priv->channel = NULL;
720 if (priv->remote_contact != NULL)
721 g_object_unref (priv->remote_contact);
722 priv->remote_contact = NULL;
724 if (priv->user != NULL)
725 g_object_unref (priv->user);
728 g_queue_foreach (priv->messages_queue, (GFunc) g_object_unref, NULL);
729 g_queue_clear (priv->messages_queue);
731 g_queue_foreach (priv->pending_messages_queue,
732 (GFunc) g_object_unref, NULL);
733 g_queue_clear (priv->pending_messages_queue);
735 if (G_OBJECT_CLASS (empathy_tp_chat_parent_class)->dispose)
736 G_OBJECT_CLASS (empathy_tp_chat_parent_class)->dispose (object);
740 tp_chat_finalize (GObject *object)
742 EmpathyTpChatPriv *priv = GET_PRIV (object);
745 DEBUG ("Finalize: %p", object);
747 if (priv->properties) {
748 for (i = 0; i < priv->properties->len; i++) {
749 EmpathyTpChatProperty *property;
751 property = g_ptr_array_index (priv->properties, i);
752 g_free (property->name);
753 if (property->value) {
754 tp_g_value_slice_free (property->value);
756 g_slice_free (EmpathyTpChatProperty, property);
758 g_ptr_array_free (priv->properties, TRUE);
761 g_queue_free (priv->messages_queue);
762 g_queue_free (priv->pending_messages_queue);
764 G_OBJECT_CLASS (empathy_tp_chat_parent_class)->finalize (object);
768 check_almost_ready (EmpathyTpChat *chat)
770 EmpathyTpChatPriv *priv = GET_PRIV (chat);
775 if (priv->user == NULL)
778 if (!priv->got_password_flags)
781 /* We need either the members (room) or the remote contact (private chat).
782 * If the chat is protected by a password we can't get these information so
783 * consider the chat as ready so it can be presented to the user. */
784 if (!empathy_tp_chat_password_needed (chat) && priv->members == NULL &&
785 priv->remote_contact == NULL)
788 /* We use the default factory so this feature should have been prepared */
789 g_assert (tp_proxy_is_prepared (priv->channel,
790 TP_TEXT_CHANNEL_FEATURE_INCOMING_MESSAGES));
792 tp_g_signal_connect_object (priv->channel, "message-received",
793 G_CALLBACK (message_received_cb), chat, 0);
795 list_pending_messages (chat);
797 tp_g_signal_connect_object (priv->channel, "message-sent",
798 G_CALLBACK (message_sent_cb), chat, 0);
800 tp_cli_channel_type_text_connect_to_send_error (priv->channel,
801 tp_chat_send_error_cb,
803 G_OBJECT (chat), NULL);
804 tp_cli_channel_interface_chat_state_connect_to_chat_state_changed (priv->channel,
805 tp_chat_state_changed_cb,
807 G_OBJECT (chat), NULL);
813 tp_chat_update_remote_contact (EmpathyTpChat *chat)
815 EmpathyTpChatPriv *priv = GET_PRIV (chat);
816 EmpathyContact *contact = NULL;
817 TpHandle self_handle;
818 TpHandleType handle_type;
821 /* If this is a named chatroom, never pretend it is a private chat */
822 tp_channel_get_handle (priv->channel, &handle_type);
823 if (handle_type == TP_HANDLE_TYPE_ROOM) {
827 /* This is an MSN chat, but it's the new style where 1-1 chats don't
828 * have the group interface. If it has the conference interface, then
829 * it is indeed a MUC. */
830 if (tp_proxy_has_interface_by_id (priv->channel,
831 TP_IFACE_QUARK_CHANNEL_INTERFACE_CONFERENCE)) {
835 /* This is an MSN-like chat where anyone can join the chat at anytime.
836 * If there is only one non-self contact member, we are in a private
837 * chat and we set the "remote-contact" property to that contact. If
838 * there are more, set the "remote-contact" property to NULL and the
839 * UI will display a contact list. */
840 self_handle = tp_channel_group_get_self_handle (priv->channel);
841 for (l = priv->members; l; l = l->next) {
842 /* Skip self contact if member */
843 if (empathy_contact_get_handle (l->data) == self_handle) {
847 /* We have more than one remote contact, break */
848 if (contact != NULL) {
853 /* If we didn't find yet a remote contact, keep this one */
857 if (priv->remote_contact == contact) {
861 DEBUG ("Changing remote contact from %p to %p",
862 priv->remote_contact, contact);
864 if (priv->remote_contact) {
865 g_object_unref (priv->remote_contact);
868 priv->remote_contact = contact ? g_object_ref (contact) : NULL;
869 g_object_notify (G_OBJECT (chat), "remote-contact");
873 tp_chat_got_added_contacts_cb (TpConnection *connection,
875 EmpathyContact * const * contacts,
877 const TpHandle *failed,
882 EmpathyTpChatPriv *priv = GET_PRIV (chat);
884 const TpIntSet *members;
886 EmpathyContact *contact;
889 DEBUG ("Error: %s", error->message);
893 members = tp_channel_group_get_members (priv->channel);
894 for (i = 0; i < n_contacts; i++) {
895 contact = contacts[i];
896 handle = empathy_contact_get_handle (contact);
898 /* Make sure the contact is still member */
899 if (tp_intset_is_member (members, handle)) {
900 priv->members = g_list_prepend (priv->members,
901 g_object_ref (contact));
902 g_signal_emit_by_name (chat, "members-changed",
903 contact, NULL, 0, NULL, TRUE);
907 tp_chat_update_remote_contact (EMPATHY_TP_CHAT (chat));
908 check_almost_ready (EMPATHY_TP_CHAT (chat));
911 static EmpathyContact *
912 chat_lookup_contact (EmpathyTpChat *chat,
916 EmpathyTpChatPriv *priv = GET_PRIV (chat);
919 for (l = priv->members; l; l = l->next) {
920 EmpathyContact *c = l->data;
922 if (empathy_contact_get_handle (c) != handle) {
927 /* Caller takes the reference. */
928 priv->members = g_list_delete_link (priv->members, l);
946 static ContactRenameData *
947 contact_rename_data_new (TpHandle handle,
949 const gchar* message)
951 ContactRenameData *data = g_new (ContactRenameData, 1);
952 data->old_handle = handle;
953 data->reason = reason;
954 data->message = g_strdup (message);
960 contact_rename_data_free (ContactRenameData* data)
962 g_free (data->message);
967 tp_chat_got_renamed_contacts_cb (TpConnection *connection,
969 EmpathyContact * const * contacts,
971 const TpHandle *failed,
976 EmpathyTpChatPriv *priv = GET_PRIV (chat);
977 const TpIntSet *members;
979 EmpathyContact *old = NULL, *new = NULL;
980 ContactRenameData *rename_data = (ContactRenameData *) user_data;
983 DEBUG ("Error: %s", error->message);
987 /* renamed members can only be delivered one at a time */
988 g_warn_if_fail (n_contacts == 1);
992 members = tp_channel_group_get_members (priv->channel);
993 handle = empathy_contact_get_handle (new);
995 old = chat_lookup_contact (EMPATHY_TP_CHAT (chat),
996 rename_data->old_handle, TRUE);
998 /* Make sure the contact is still member */
999 if (tp_intset_is_member (members, handle)) {
1000 priv->members = g_list_prepend (priv->members,
1001 g_object_ref (new));
1004 g_signal_emit_by_name (chat, "member-renamed",
1005 old, new, rename_data->reason,
1006 rename_data->message);
1007 g_object_unref (old);
1011 if (priv->user == old) {
1012 /* We change our nick */
1013 tp_clear_object (&priv->user);
1014 priv->user = g_object_ref (new);
1017 tp_chat_update_remote_contact (EMPATHY_TP_CHAT (chat));
1018 check_almost_ready (EMPATHY_TP_CHAT (chat));
1023 tp_chat_group_members_changed_cb (TpChannel *self,
1027 GArray *local_pending,
1028 GArray *remote_pending,
1031 EmpathyTpChat *chat)
1033 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1034 EmpathyContact *contact;
1035 EmpathyContact *actor_contact = NULL;
1037 ContactRenameData *rename_data;
1038 TpHandle old_handle;
1040 /* Contact renamed */
1041 if (reason == TP_CHANNEL_GROUP_CHANGE_REASON_RENAMED) {
1042 /* there can only be a single 'added' and a single 'removed' handle */
1043 if (removed->len != 1 || added->len != 1) {
1044 g_warning ("RENAMED with %u added, %u removed (expected 1, 1)",
1045 added->len, removed->len);
1049 old_handle = g_array_index (removed, guint, 0);
1051 rename_data = contact_rename_data_new (old_handle, reason, message);
1052 empathy_tp_contact_factory_get_from_handles (priv->connection,
1053 added->len, (TpHandle *) added->data,
1054 tp_chat_got_renamed_contacts_cb,
1055 rename_data, (GDestroyNotify) contact_rename_data_free,
1061 actor_contact = chat_lookup_contact (chat, actor, FALSE);
1062 if (actor_contact == NULL) {
1063 /* FIXME: handle this a tad more gracefully: perhaps
1064 * the actor was a server op. We could use the
1065 * contact-ids detail of MembersChangedDetailed.
1067 DEBUG ("actor %u not a channel member", actor);
1071 /* Remove contacts that are not members anymore */
1072 for (i = 0; i < removed->len; i++) {
1073 contact = chat_lookup_contact (chat,
1074 g_array_index (removed, TpHandle, i), TRUE);
1076 if (contact != NULL) {
1077 g_signal_emit_by_name (chat, "members-changed", contact,
1078 actor_contact, reason, message,
1080 g_object_unref (contact);
1084 /* Request added contacts */
1085 if (added->len > 0) {
1086 empathy_tp_contact_factory_get_from_handles (priv->connection,
1087 added->len, (TpHandle *) added->data,
1088 tp_chat_got_added_contacts_cb, NULL, NULL,
1092 tp_chat_update_remote_contact (chat);
1094 if (actor_contact != NULL) {
1095 g_object_unref (actor_contact);
1100 tp_chat_got_remote_contact_cb (TpConnection *connection,
1101 EmpathyContact *contact,
1102 const GError *error,
1106 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1109 DEBUG ("Error: %s", error->message);
1110 empathy_tp_chat_leave (EMPATHY_TP_CHAT (chat), "");
1114 priv->remote_contact = g_object_ref (contact);
1115 g_object_notify (chat, "remote-contact");
1117 check_almost_ready (EMPATHY_TP_CHAT (chat));
1121 tp_chat_got_self_contact_cb (TpConnection *connection,
1122 EmpathyContact *contact,
1123 const GError *error,
1127 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1130 DEBUG ("Error: %s", error->message);
1131 empathy_tp_chat_leave (EMPATHY_TP_CHAT (chat), "");
1135 priv->user = g_object_ref (contact);
1136 empathy_contact_set_is_user (priv->user, TRUE);
1137 check_almost_ready (EMPATHY_TP_CHAT (chat));
1141 password_flags_changed_cb (TpChannel *channel,
1145 GObject *weak_object)
1147 EmpathyTpChat *self = EMPATHY_TP_CHAT (weak_object);
1148 EmpathyTpChatPriv *priv = GET_PRIV (self);
1149 gboolean was_needed, needed;
1151 was_needed = empathy_tp_chat_password_needed (self);
1153 priv->password_flags |= added;
1154 priv->password_flags ^= removed;
1156 needed = empathy_tp_chat_password_needed (self);
1158 if (was_needed != needed)
1159 g_object_notify (G_OBJECT (self), "password-needed");
1163 got_password_flags_cb (TpChannel *proxy,
1164 guint password_flags,
1165 const GError *error,
1167 GObject *weak_object)
1169 EmpathyTpChat *self = EMPATHY_TP_CHAT (weak_object);
1170 EmpathyTpChatPriv *priv = GET_PRIV (self);
1172 priv->got_password_flags = TRUE;
1173 priv->password_flags = password_flags;
1175 check_almost_ready (EMPATHY_TP_CHAT (self));
1179 tp_chat_constructor (GType type,
1181 GObjectConstructParam *props)
1184 EmpathyTpChatPriv *priv;
1187 chat = G_OBJECT_CLASS (empathy_tp_chat_parent_class)->constructor (type, n_props, props);
1189 priv = GET_PRIV (chat);
1191 priv->connection = g_object_ref (tp_account_get_connection (priv->account));
1192 tp_g_signal_connect_object (priv->channel, "invalidated",
1193 G_CALLBACK (tp_chat_invalidated_cb),
1196 g_assert (tp_proxy_is_prepared (priv->connection,
1197 TP_CONNECTION_FEATURE_CAPABILITIES));
1199 if (tp_proxy_has_interface_by_id (priv->channel,
1200 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
1201 const TpIntSet *members;
1204 /* Get self contact from the group's self handle */
1205 handle = tp_channel_group_get_self_handle (priv->channel);
1206 empathy_tp_contact_factory_get_from_handle (priv->connection,
1207 handle, tp_chat_got_self_contact_cb,
1210 /* Get initial member contacts */
1211 members = tp_channel_group_get_members (priv->channel);
1212 handles = tp_intset_to_array (members);
1213 empathy_tp_contact_factory_get_from_handles (priv->connection,
1214 handles->len, (TpHandle *) handles->data,
1215 tp_chat_got_added_contacts_cb, NULL, NULL, chat);
1217 priv->can_upgrade_to_muc = FALSE;
1219 tp_g_signal_connect_object (priv->channel, "group-members-changed",
1220 G_CALLBACK (tp_chat_group_members_changed_cb), chat, 0);
1222 TpCapabilities *caps;
1226 /* Get the self contact from the connection's self handle */
1227 handle = tp_connection_get_self_handle (priv->connection);
1228 empathy_tp_contact_factory_get_from_handle (priv->connection,
1229 handle, tp_chat_got_self_contact_cb,
1232 /* Get the remote contact */
1233 handle = tp_channel_get_handle (priv->channel, NULL);
1234 empathy_tp_contact_factory_get_from_handle (priv->connection,
1235 handle, tp_chat_got_remote_contact_cb,
1238 caps = tp_connection_get_capabilities (priv->connection);
1239 g_assert (caps != NULL);
1241 classes = tp_capabilities_get_channel_classes (caps);
1243 for (i = 0; i < classes->len; i++) {
1244 GValueArray *array = g_ptr_array_index (classes, i);
1245 const char **oprops = g_value_get_boxed (
1246 g_value_array_get_nth (array, 1));
1248 if (tp_strv_contains (oprops, TP_PROP_CHANNEL_INTERFACE_CONFERENCE_INITIAL_CHANNELS)) {
1249 priv->can_upgrade_to_muc = TRUE;
1255 if (tp_proxy_has_interface_by_id (priv->channel,
1256 TP_IFACE_QUARK_PROPERTIES_INTERFACE)) {
1257 tp_cli_properties_interface_call_list_properties (priv->channel, -1,
1258 tp_chat_list_properties_cb,
1261 tp_cli_properties_interface_connect_to_properties_changed (priv->channel,
1262 tp_chat_properties_changed_cb,
1264 G_OBJECT (chat), NULL);
1265 tp_cli_properties_interface_connect_to_property_flags_changed (priv->channel,
1266 tp_chat_property_flags_changed_cb,
1268 G_OBJECT (chat), NULL);
1271 /* Check if the chat is password protected */
1272 if (tp_proxy_has_interface_by_id (priv->channel,
1273 TP_IFACE_QUARK_CHANNEL_INTERFACE_PASSWORD)) {
1274 priv->got_password_flags = FALSE;
1276 tp_cli_channel_interface_password_connect_to_password_flags_changed
1277 (priv->channel, password_flags_changed_cb, chat, NULL,
1278 G_OBJECT (chat), NULL);
1280 tp_cli_channel_interface_password_call_get_password_flags
1281 (priv->channel, -1, got_password_flags_cb, chat, NULL, chat);
1283 /* No Password interface, so no need to fetch the password flags */
1284 priv->got_password_flags = TRUE;
1291 tp_chat_get_property (GObject *object,
1296 EmpathyTpChat *self = EMPATHY_TP_CHAT (object);
1297 EmpathyTpChatPriv *priv = GET_PRIV (object);
1301 g_value_set_object (value, priv->account);
1304 g_value_set_object (value, priv->channel);
1306 case PROP_REMOTE_CONTACT:
1307 g_value_set_object (value, priv->remote_contact);
1310 g_value_set_boolean (value, priv->ready);
1312 case PROP_PASSWORD_NEEDED:
1313 g_value_set_boolean (value, empathy_tp_chat_password_needed (self));
1316 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1322 tp_chat_set_property (GObject *object,
1324 const GValue *value,
1327 EmpathyTpChatPriv *priv = GET_PRIV (object);
1331 priv->account = g_value_dup_object (value);
1334 priv->channel = g_value_dup_object (value);
1337 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1343 empathy_tp_chat_class_init (EmpathyTpChatClass *klass)
1345 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1347 object_class->dispose = tp_chat_dispose;
1348 object_class->finalize = tp_chat_finalize;
1349 object_class->constructor = tp_chat_constructor;
1350 object_class->get_property = tp_chat_get_property;
1351 object_class->set_property = tp_chat_set_property;
1353 g_object_class_install_property (object_class,
1355 g_param_spec_object ("account",
1357 "the account associated with the chat",
1360 G_PARAM_CONSTRUCT_ONLY |
1361 G_PARAM_STATIC_STRINGS));
1363 g_object_class_install_property (object_class,
1365 g_param_spec_object ("channel",
1366 "telepathy channel",
1367 "The text channel for the chat",
1370 G_PARAM_CONSTRUCT_ONLY));
1372 g_object_class_install_property (object_class,
1373 PROP_REMOTE_CONTACT,
1374 g_param_spec_object ("remote-contact",
1375 "The remote contact",
1376 "The remote contact if there is no group iface on the channel",
1377 EMPATHY_TYPE_CONTACT,
1380 g_object_class_install_property (object_class,
1382 g_param_spec_boolean ("ready",
1383 "Is the object ready",
1384 "This object can't be used until this becomes true",
1388 g_object_class_install_property (object_class,
1389 PROP_PASSWORD_NEEDED,
1390 g_param_spec_boolean ("password-needed",
1392 "TRUE if a password is needed to join the channel",
1397 signals[MESSAGE_RECEIVED] =
1398 g_signal_new ("message-received",
1399 G_TYPE_FROM_CLASS (klass),
1403 g_cclosure_marshal_VOID__OBJECT,
1405 1, EMPATHY_TYPE_MESSAGE);
1407 signals[SEND_ERROR] =
1408 g_signal_new ("send-error",
1409 G_TYPE_FROM_CLASS (klass),
1413 _empathy_marshal_VOID__STRING_UINT,
1415 2, G_TYPE_STRING, G_TYPE_UINT);
1417 signals[CHAT_STATE_CHANGED] =
1418 g_signal_new ("chat-state-changed",
1419 G_TYPE_FROM_CLASS (klass),
1423 _empathy_marshal_VOID__OBJECT_UINT,
1425 2, EMPATHY_TYPE_CONTACT, G_TYPE_UINT);
1427 signals[PROPERTY_CHANGED] =
1428 g_signal_new ("property-changed",
1429 G_TYPE_FROM_CLASS (klass),
1433 _empathy_marshal_VOID__STRING_BOXED,
1435 2, G_TYPE_STRING, G_TYPE_VALUE);
1438 g_signal_new ("destroy",
1439 G_TYPE_FROM_CLASS (klass),
1443 g_cclosure_marshal_VOID__VOID,
1447 g_type_class_add_private (object_class, sizeof (EmpathyTpChatPriv));
1451 empathy_tp_chat_init (EmpathyTpChat *chat)
1453 EmpathyTpChatPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chat,
1454 EMPATHY_TYPE_TP_CHAT, EmpathyTpChatPriv);
1457 priv->messages_queue = g_queue_new ();
1458 priv->pending_messages_queue = g_queue_new ();
1462 tp_chat_iface_init (EmpathyContactListIface *iface)
1464 iface->add = tp_chat_add;
1465 iface->remove = tp_chat_remove;
1466 iface->get_members = tp_chat_get_members;
1470 empathy_tp_chat_new (TpAccount *account,
1473 g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL);
1474 g_return_val_if_fail (TP_IS_TEXT_CHANNEL (channel), NULL);
1476 return g_object_new (EMPATHY_TYPE_TP_CHAT,
1483 empathy_tp_chat_get_id (EmpathyTpChat *chat)
1485 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1489 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1491 id = tp_channel_get_identifier (priv->channel);
1492 if (!EMP_STR_EMPTY (id))
1494 else if (priv->remote_contact)
1495 return empathy_contact_get_id (priv->remote_contact);
1502 empathy_tp_chat_get_remote_contact (EmpathyTpChat *chat)
1504 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1506 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1507 g_return_val_if_fail (priv->ready, NULL);
1509 return priv->remote_contact;
1513 empathy_tp_chat_get_channel (EmpathyTpChat *chat)
1515 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1517 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1519 return priv->channel;
1523 empathy_tp_chat_get_account (EmpathyTpChat *chat)
1525 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1527 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1529 return priv->account;
1533 empathy_tp_chat_get_connection (EmpathyTpChat *chat)
1535 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1537 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1539 return tp_channel_borrow_connection (priv->channel);
1542 empathy_tp_chat_is_ready (EmpathyTpChat *chat)
1544 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1546 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), FALSE);
1552 empathy_tp_chat_send (EmpathyTpChat *chat,
1553 EmpathyMessage *message)
1555 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1556 const gchar *message_body;
1557 TpChannelTextMessageType message_type;
1559 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1560 g_return_if_fail (EMPATHY_IS_MESSAGE (message));
1561 g_return_if_fail (priv->ready);
1563 message_body = empathy_message_get_body (message);
1564 message_type = empathy_message_get_tptype (message);
1566 DEBUG ("Sending message: %s", message_body);
1567 tp_cli_channel_type_text_call_send (priv->channel, -1,
1571 g_object_ref (message),
1572 (GDestroyNotify) g_object_unref,
1577 empathy_tp_chat_set_state (EmpathyTpChat *chat,
1578 TpChannelChatState state)
1580 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1582 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1583 g_return_if_fail (priv->ready);
1585 if (tp_proxy_has_interface_by_id (priv->channel,
1586 TP_IFACE_QUARK_CHANNEL_INTERFACE_CHAT_STATE)) {
1587 DEBUG ("Set state: %d", state);
1588 tp_cli_channel_interface_chat_state_call_set_chat_state (priv->channel, -1,
1591 "setting chat state",
1599 empathy_tp_chat_get_pending_messages (EmpathyTpChat *chat)
1601 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1603 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1604 g_return_val_if_fail (priv->ready, NULL);
1606 return priv->pending_messages_queue->head;
1610 acknowledge_messages (EmpathyTpChat *chat, GArray *ids) {
1611 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1613 tp_cli_channel_type_text_call_acknowledge_pending_messages (
1614 priv->channel, -1, ids, tp_chat_async_cb,
1615 "acknowledging received message", NULL, G_OBJECT (chat));
1619 empathy_tp_chat_acknowledge_message (EmpathyTpChat *chat,
1620 EmpathyMessage *message) {
1621 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1622 GArray *message_ids;
1626 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1627 g_return_if_fail (priv->ready);
1629 if (!empathy_message_is_incoming (message))
1632 message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
1634 id = empathy_message_get_id (message);
1635 g_array_append_val (message_ids, id);
1636 acknowledge_messages (chat, message_ids);
1637 g_array_free (message_ids, TRUE);
1640 m = g_queue_find (priv->pending_messages_queue, message);
1641 g_assert (m != NULL);
1642 g_queue_delete_link (priv->pending_messages_queue, m);
1643 g_object_unref (message);
1647 empathy_tp_chat_acknowledge_messages (EmpathyTpChat *chat,
1648 const GSList *messages) {
1649 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1650 /* Copy messages as the messges list (probably is) our own */
1651 GSList *msgs = g_slist_copy ((GSList *) messages);
1654 GArray *message_ids;
1656 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1657 g_return_if_fail (priv->ready);
1659 length = g_slist_length ((GSList *) messages);
1664 message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), length);
1666 for (l = msgs; l != NULL; l = g_slist_next (l)) {
1669 EmpathyMessage *message = EMPATHY_MESSAGE (l->data);
1671 m = g_queue_find (priv->pending_messages_queue, message);
1672 g_assert (m != NULL);
1673 g_queue_delete_link (priv->pending_messages_queue, m);
1675 if (empathy_message_is_incoming (message)) {
1676 guint id = empathy_message_get_id (message);
1677 g_array_append_val (message_ids, id);
1679 g_object_unref (message);
1682 if (message_ids->len > 0)
1683 acknowledge_messages (chat, message_ids);
1685 g_array_free (message_ids, TRUE);
1686 g_slist_free (msgs);
1690 empathy_tp_chat_acknowledge_all_messages (EmpathyTpChat *chat)
1692 empathy_tp_chat_acknowledge_messages (chat,
1693 (GSList *) empathy_tp_chat_get_pending_messages (chat));
1697 empathy_tp_chat_password_needed (EmpathyTpChat *self)
1699 EmpathyTpChatPriv *priv = GET_PRIV (self);
1701 return priv->password_flags & TP_CHANNEL_PASSWORD_FLAG_PROVIDE;
1705 provide_password_cb (TpChannel *channel,
1707 const GError *error,
1709 GObject *weak_object)
1711 GSimpleAsyncResult *result = user_data;
1713 if (error != NULL) {
1714 g_simple_async_result_set_from_error (result, error);
1716 else if (!correct) {
1717 /* The current D-Bus API is a bit weird so re-use the
1718 * AuthenticationFailed error */
1719 g_simple_async_result_set_error (result, TP_ERRORS,
1720 TP_ERROR_AUTHENTICATION_FAILED, "Wrong password");
1723 g_simple_async_result_complete (result);
1724 g_object_unref (result);
1728 empathy_tp_chat_provide_password_async (EmpathyTpChat *self,
1729 const gchar *password,
1730 GAsyncReadyCallback callback,
1733 EmpathyTpChatPriv *priv = GET_PRIV (self);
1734 GSimpleAsyncResult *result;
1736 result = g_simple_async_result_new (G_OBJECT (self),
1737 callback, user_data,
1738 empathy_tp_chat_provide_password_finish);
1740 tp_cli_channel_interface_password_call_provide_password
1741 (priv->channel, -1, password, provide_password_cb, result,
1742 NULL, G_OBJECT (self));
1746 empathy_tp_chat_provide_password_finish (EmpathyTpChat *self,
1747 GAsyncResult *result,
1750 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1754 g_return_val_if_fail (g_simple_async_result_is_valid (result,
1755 G_OBJECT (self), empathy_tp_chat_provide_password_finish), FALSE);
1761 * empathy_tp_chat_can_add_contact:
1763 * Returns: %TRUE if empathy_contact_list_add() will work for this channel.
1764 * That is if this chat is a 1-to-1 channel that can be upgraded to
1765 * a MUC using the Conference interface or if the channel is a MUC.
1768 empathy_tp_chat_can_add_contact (EmpathyTpChat *self)
1770 EmpathyTpChatPriv *priv;
1772 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (self), FALSE);
1774 priv = GET_PRIV (self);
1776 return priv->can_upgrade_to_muc ||
1777 tp_proxy_has_interface_by_id (priv->channel,
1778 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP);;
1782 tp_channel_leave_async_cb (GObject *source_object,
1786 GError *error = NULL;
1788 if (!tp_channel_leave_finish (TP_CHANNEL (source_object), res, &error)) {
1789 DEBUG ("Could not leave channel properly: (%s); closing the channel",
1791 g_error_free (error);
1796 empathy_tp_chat_leave (EmpathyTpChat *self,
1797 const gchar *message)
1799 EmpathyTpChatPriv *priv = GET_PRIV (self);
1801 tp_channel_leave_async (priv->channel, TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
1802 message, tp_channel_leave_async_cb, self);
1806 add_members_cb (TpChannel *proxy,
1807 const GError *error,
1809 GObject *weak_object)
1811 EmpathyTpChatPriv *priv = GET_PRIV (weak_object);
1813 if (error != NULL) {
1814 DEBUG ("Failed to join chat (%s): %s",
1815 tp_channel_get_identifier (priv->channel), error->message);
1820 empathy_tp_chat_join (EmpathyTpChat *self)
1822 EmpathyTpChatPriv *priv = GET_PRIV (self);
1823 TpHandle self_handle;
1826 self_handle = tp_channel_group_get_self_handle (priv->channel);
1828 members = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), 1);
1829 g_array_append_val (members, self_handle);
1831 tp_cli_channel_interface_group_call_add_members (priv->channel, -1, members,
1832 "", add_members_cb, NULL, NULL, G_OBJECT (self));
1834 g_array_free (members, TRUE);
1838 empathy_tp_chat_is_invited (EmpathyTpChat *self,
1841 EmpathyTpChatPriv *priv = GET_PRIV (self);
1842 TpHandle self_handle;
1844 if (!tp_proxy_has_interface (priv->channel, TP_IFACE_CHANNEL_INTERFACE_GROUP))
1847 self_handle = tp_channel_group_get_self_handle (priv->channel);
1848 if (self_handle == 0)
1851 return tp_channel_group_get_local_pending_info (priv->channel, self_handle,
1852 inviter, NULL, NULL);
1856 empathy_tp_chat_get_chat_state (EmpathyTpChat *chat,
1857 EmpathyContact *contact)
1859 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1860 return tp_channel_get_chat_state (priv->channel,
1861 empathy_contact_get_handle (contact));
1865 empathy_tp_chat_get_self_contact (EmpathyTpChat *self)
1867 EmpathyTpChatPriv *priv = GET_PRIV (self);
1869 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (self), NULL);