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 <libtelepathy/tp-chan-type-text-gen.h>
27 #include <libtelepathy/tp-chan-iface-chat-state-gen.h>
28 #include <libtelepathy/tp-conn.h>
29 #include <libtelepathy/tp-helpers.h>
30 #include <libtelepathy/tp-props-iface.h>
31 #include <telepathy-glib/util.h>
33 #include "empathy-tp-chat.h"
34 #include "empathy-contact-factory.h"
35 #include "empathy-marshal.h"
36 #include "empathy-debug.h"
37 #include "empathy-time.h"
38 #include "empathy-utils.h"
40 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
41 EMPATHY_TYPE_TP_CHAT, EmpathyTpChatPriv))
43 #define DEBUG_DOMAIN "TpChat"
45 struct _EmpathyTpChatPriv {
46 EmpathyContactFactory *factory;
52 gboolean had_pending_messages;
53 GSList *message_queue;
55 DBusGProxy *props_iface;
56 DBusGProxy *text_iface;
57 DBusGProxy *chat_state_iface;
60 static void empathy_tp_chat_class_init (EmpathyTpChatClass *klass);
61 static void empathy_tp_chat_init (EmpathyTpChat *chat);
77 PROP_PASSWORD_REQUIRED,
82 PROP_SUBJECT_TIMESTAMP
93 static guint signals[LAST_SIGNAL];
95 G_DEFINE_TYPE (EmpathyTpChat, empathy_tp_chat, G_TYPE_OBJECT);
98 tp_chat_destroy_cb (TpChan *text_chan,
101 EmpathyTpChatPriv *priv;
103 priv = GET_PRIV (chat);
105 empathy_debug (DEBUG_DOMAIN, "Channel Closed or CM crashed");
107 g_object_unref (priv->tp_chan);
108 priv->tp_chan = NULL;
109 priv->text_iface = NULL;
110 priv->chat_state_iface = NULL;
111 priv->props_iface = NULL;
113 g_signal_emit (chat, signals[DESTROY], 0);
117 tp_chat_closed_cb (TpChan *text_chan,
120 EmpathyTpChatPriv *priv;
122 priv = GET_PRIV (chat);
124 /* The channel is closed, do just like if the proxy was destroyed */
125 g_signal_handlers_disconnect_by_func (priv->tp_chan,
128 tp_chat_destroy_cb (text_chan, chat);
131 static EmpathyMessage *
132 tp_chat_build_message (EmpathyTpChat *chat,
136 const gchar *message_body)
138 EmpathyTpChatPriv *priv;
139 EmpathyMessage *message;
140 EmpathyContact *sender;
142 priv = GET_PRIV (chat);
144 if (from_handle == 0) {
145 sender = g_object_ref (priv->user);
147 sender = empathy_contact_factory_get_from_handle (priv->factory,
152 message = empathy_message_new (message_body);
153 empathy_message_set_type (message, type);
154 empathy_message_set_sender (message, sender);
155 empathy_message_set_receiver (message, priv->user);
156 empathy_message_set_timestamp (message, timestamp);
158 g_object_unref (sender);
164 tp_chat_sender_ready_notify_cb (EmpathyContact *contact,
165 GParamSpec *param_spec,
168 EmpathyTpChatPriv *priv = GET_PRIV (chat);
169 EmpathyMessage *message;
170 EmpathyContact *sender;
171 gboolean removed = FALSE;
172 const gchar *name, *id;
174 /* Emit all messages queued until we find a message with not
175 * ready sender. When leaving this loop, sender is the first not ready
176 * contact queued and removed tells if at least one message got removed
178 while (priv->message_queue) {
179 message = priv->message_queue->data;
180 sender = empathy_message_get_sender (message);
181 name = empathy_contact_get_name (sender);
182 id = empathy_contact_get_id (sender);
184 if (!tp_strdiff (name, id)) {
188 empathy_debug (DEBUG_DOMAIN, "Queued message ready");
189 g_signal_emit (chat, signals[MESSAGE_RECEIVED], 0, message);
190 priv->message_queue = g_slist_remove (priv->message_queue,
192 g_object_unref (message);
197 g_signal_handlers_disconnect_by_func (contact,
198 tp_chat_sender_ready_notify_cb,
201 if (priv->message_queue) {
202 g_signal_connect (sender, "notify::name",
203 G_CALLBACK (tp_chat_sender_ready_notify_cb),
210 tp_chat_emit_or_queue_message (EmpathyTpChat *chat,
211 EmpathyMessage *message)
213 EmpathyTpChatPriv *priv = GET_PRIV (chat);
214 EmpathyContact *sender;
215 const gchar *name, *id;
217 if (priv->message_queue != NULL) {
218 empathy_debug (DEBUG_DOMAIN, "Message queue not empty");
219 priv->message_queue = g_slist_append (priv->message_queue,
220 g_object_ref (message));
224 sender = empathy_message_get_sender (message);
225 name = empathy_contact_get_name (sender);
226 id = empathy_contact_get_id (sender);
227 if (tp_strdiff (name, id)) {
228 empathy_debug (DEBUG_DOMAIN, "Message queue empty and sender ready");
229 g_signal_emit (chat, signals[MESSAGE_RECEIVED], 0, message);
233 empathy_debug (DEBUG_DOMAIN, "Sender not ready");
234 priv->message_queue = g_slist_append (priv->message_queue,
235 g_object_ref (message));
236 g_signal_connect (sender, "notify::name",
237 G_CALLBACK (tp_chat_sender_ready_notify_cb),
242 tp_chat_received_cb (DBusGProxy *text_iface,
251 EmpathyTpChatPriv *priv;
252 EmpathyMessage *message;
254 priv = GET_PRIV (chat);
256 if (!priv->had_pending_messages) {
260 empathy_debug (DEBUG_DOMAIN, "Message received: %s", message_body);
262 message = tp_chat_build_message (chat,
268 tp_chat_emit_or_queue_message (EMPATHY_TP_CHAT (chat), message);
269 g_object_unref (message);
271 if (priv->acknowledge) {
274 message_ids = g_array_new (FALSE, FALSE, sizeof (guint));
275 g_array_append_val (message_ids, message_id);
276 tp_chan_type_text_acknowledge_pending_messages (priv->text_iface,
278 g_array_free (message_ids, TRUE);
283 tp_chat_sent_cb (DBusGProxy *text_iface,
289 EmpathyMessage *message;
291 empathy_debug (DEBUG_DOMAIN, "Message sent: %s", message_body);
293 message = tp_chat_build_message (chat,
299 tp_chat_emit_or_queue_message (EMPATHY_TP_CHAT (chat), message);
300 g_object_unref (message);
304 tp_chat_send_error_cb (DBusGProxy *text_iface,
311 EmpathyMessage *message;
313 empathy_debug (DEBUG_DOMAIN, "Message sent error: %s (%d)",
314 message_body, error_code);
316 message = tp_chat_build_message (chat,
322 g_signal_emit (chat, signals[SEND_ERROR], 0, message, error_code);
323 g_object_unref (message);
327 tp_chat_state_changed_cb (DBusGProxy *chat_state_iface,
329 TpChannelChatState state,
332 EmpathyTpChatPriv *priv;
333 EmpathyContact *contact;
335 priv = GET_PRIV (chat);
337 contact = empathy_contact_factory_get_from_handle (priv->factory,
341 empathy_debug (DEBUG_DOMAIN, "Chat state changed for %s (%d): %d",
342 empathy_contact_get_name (contact),
346 g_signal_emit (chat, signals[CHAT_STATE_CHANGED], 0, contact, state);
347 g_object_unref (contact);
351 tp_chat_list_pending_messages_cb (DBusGProxy *proxy,
352 GPtrArray *messages_list,
356 EmpathyTpChatPriv *priv = GET_PRIV (chat);
359 priv->had_pending_messages = TRUE;
361 for (i = 0; i < messages_list->len; i++) {
362 EmpathyMessage *message;
363 GValueArray *message_struct;
364 const gchar *message_body;
371 message_struct = g_ptr_array_index (messages_list, i);
373 message_id = g_value_get_uint (g_value_array_get_nth (message_struct, 0));
374 timestamp = g_value_get_uint (g_value_array_get_nth (message_struct, 1));
375 from_handle = g_value_get_uint (g_value_array_get_nth (message_struct, 2));
376 message_type = g_value_get_uint (g_value_array_get_nth (message_struct, 3));
377 message_flags = g_value_get_uint (g_value_array_get_nth (message_struct, 4));
378 message_body = g_value_get_string (g_value_array_get_nth (message_struct, 5));
380 empathy_debug (DEBUG_DOMAIN, "Message pending: %s", message_body);
382 message = tp_chat_build_message (chat,
388 tp_chat_emit_or_queue_message (chat, message);
389 g_object_unref (message);
391 g_value_array_free (message_struct);
394 g_ptr_array_free (messages_list, TRUE);
398 tp_chat_properties_ready_cb (TpPropsIface *props_iface,
401 g_object_notify (G_OBJECT (chat), "anonymous");
402 g_object_notify (G_OBJECT (chat), "invite-only");
403 g_object_notify (G_OBJECT (chat), "limit");
404 g_object_notify (G_OBJECT (chat), "limited");
405 g_object_notify (G_OBJECT (chat), "moderated");
406 g_object_notify (G_OBJECT (chat), "name");
407 g_object_notify (G_OBJECT (chat), "description");
408 g_object_notify (G_OBJECT (chat), "password");
409 g_object_notify (G_OBJECT (chat), "password-required");
410 g_object_notify (G_OBJECT (chat), "persistent");
411 g_object_notify (G_OBJECT (chat), "private");
412 g_object_notify (G_OBJECT (chat), "subject");
413 g_object_notify (G_OBJECT (chat), "subject-contact");
414 g_object_notify (G_OBJECT (chat), "subject-timestamp");
418 tp_chat_properties_changed_cb (TpPropsIface *props_iface,
425 g_object_notify (G_OBJECT (chat), "anonymous");
427 case PROP_INVITE_ONLY:
428 g_object_notify (G_OBJECT (chat), "invite-only");
431 g_object_notify (G_OBJECT (chat), "limit");
434 g_object_notify (G_OBJECT (chat), "limited");
437 g_object_notify (G_OBJECT (chat), "moderated");
440 g_object_notify (G_OBJECT (chat), "name");
442 case PROP_DESCRIPTION:
443 g_object_notify (G_OBJECT (chat), "description");
446 g_object_notify (G_OBJECT (chat), "password");
448 case PROP_PASSWORD_REQUIRED:
449 g_object_notify (G_OBJECT (chat), "password-required");
451 case PROP_PERSISTENT:
452 g_object_notify (G_OBJECT (chat), "persistent");
455 g_object_notify (G_OBJECT (chat), "private");
458 g_object_notify (G_OBJECT (chat), "subject");
460 case PROP_SUBJECT_CONTACT:
461 g_object_notify (G_OBJECT (chat), "subject-contact");
463 case PROP_SUBJECT_TIMESTAMP:
464 g_object_notify (G_OBJECT (chat), "subject-timestamp");
470 tp_chat_finalize (GObject *object)
472 EmpathyTpChatPriv *priv;
474 GError *error = NULL;
476 chat = EMPATHY_TP_CHAT (object);
477 priv = GET_PRIV (chat);
479 if (priv->text_iface) {
480 dbus_g_proxy_disconnect_signal (priv->text_iface, "Received",
481 G_CALLBACK (tp_chat_received_cb),
483 dbus_g_proxy_disconnect_signal (priv->text_iface, "Sent",
484 G_CALLBACK (tp_chat_sent_cb),
486 dbus_g_proxy_disconnect_signal (priv->text_iface, "SendError",
487 G_CALLBACK (tp_chat_send_error_cb),
491 if (priv->chat_state_iface) {
492 dbus_g_proxy_disconnect_signal (priv->chat_state_iface, "ChatStateChanged",
493 G_CALLBACK (tp_chat_state_changed_cb),
498 g_signal_handlers_disconnect_by_func (priv->tp_chan,
501 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->tp_chan), "Closed",
502 G_CALLBACK (tp_chat_closed_cb),
504 if (priv->acknowledge) {
505 empathy_debug (DEBUG_DOMAIN, "Closing channel...");
506 if (!tp_chan_close (DBUS_G_PROXY (priv->tp_chan), &error)) {
507 empathy_debug (DEBUG_DOMAIN,
508 "Error closing text channel: %s",
509 error ? error->message : "No error given");
510 g_clear_error (&error);
513 g_object_unref (priv->tp_chan);
516 g_object_unref (priv->factory);
517 g_object_unref (priv->user);
518 g_object_unref (priv->account);
519 g_object_unref (priv->mc);
522 G_OBJECT_CLASS (empathy_tp_chat_parent_class)->finalize (object);
526 tp_chat_constructor (GType type,
528 GObjectConstructParam *props)
531 EmpathyTpChatPriv *priv;
533 chat = G_OBJECT_CLASS (empathy_tp_chat_parent_class)->constructor (type, n_props, props);
535 priv = GET_PRIV (chat);
537 priv->factory = empathy_contact_factory_new ();
538 priv->user = empathy_contact_factory_get_user (priv->factory, priv->account);
539 priv->mc = empathy_mission_control_new ();
541 priv->text_iface = tp_chan_get_interface (priv->tp_chan,
542 TP_IFACE_QUARK_CHANNEL_TYPE_TEXT);
543 priv->chat_state_iface = tp_chan_get_interface (priv->tp_chan,
544 TP_IFACE_QUARK_CHANNEL_INTERFACE_CHAT_STATE);
545 priv->props_iface = tp_chan_get_interface (priv->tp_chan,
546 TP_IFACE_QUARK_PROPERTIES_INTERFACE);
548 g_signal_connect (priv->tp_chan, "destroy",
549 G_CALLBACK (tp_chat_destroy_cb),
551 dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->tp_chan), "Closed",
552 G_CALLBACK (tp_chat_closed_cb),
554 dbus_g_proxy_connect_signal (priv->text_iface, "Received",
555 G_CALLBACK (tp_chat_received_cb),
557 dbus_g_proxy_connect_signal (priv->text_iface, "Sent",
558 G_CALLBACK (tp_chat_sent_cb),
560 dbus_g_proxy_connect_signal (priv->text_iface, "SendError",
561 G_CALLBACK (tp_chat_send_error_cb),
564 if (priv->chat_state_iface != NULL) {
565 dbus_g_proxy_connect_signal (priv->chat_state_iface,
567 G_CALLBACK (tp_chat_state_changed_cb),
570 if (priv->props_iface != NULL) {
571 tp_props_iface_set_mapping (TELEPATHY_PROPS_IFACE (priv->props_iface),
572 "anonymous", PROP_ANONYMOUS,
573 "invite-only", PROP_INVITE_ONLY,
575 "limited", PROP_LIMITED,
576 "moderated", PROP_MODERATED,
578 "description", PROP_DESCRIPTION,
579 "password", PROP_PASSWORD,
580 "password-required", PROP_PASSWORD_REQUIRED,
581 "persistent", PROP_PERSISTENT,
582 "private", PROP_PRIVATE,
583 "subject", PROP_SUBJECT,
584 "subject-contact", PROP_SUBJECT_CONTACT,
585 "subject-timestamp", PROP_SUBJECT_TIMESTAMP,
587 g_signal_connect (priv->props_iface, "properties-ready",
588 G_CALLBACK (tp_chat_properties_ready_cb),
590 g_signal_connect (priv->props_iface, "properties-changed",
591 G_CALLBACK (tp_chat_properties_changed_cb),
595 /* FIXME: We do that in a cb to let time to set the acknowledge
596 * property, this property should be required for construct. */
597 g_idle_add ((GSourceFunc) empathy_tp_chat_get_pendings, chat);
603 tp_chat_get_property (GObject *object,
608 EmpathyTpChatPriv *priv;
611 priv = GET_PRIV (object);
612 chat = EMPATHY_TP_CHAT (object);
614 if (param_id >= PROP_ANONYMOUS &&
615 param_id <= PROP_SUBJECT_TIMESTAMP) {
616 if (priv->props_iface) {
617 tp_props_iface_get_value (TELEPATHY_PROPS_IFACE (priv->props_iface),
627 g_value_set_object (value, priv->account);
630 g_value_set_object (value, priv->tp_chan);
632 case PROP_ACKNOWLEDGE:
633 g_value_set_boolean (value, priv->acknowledge);
636 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
642 tp_chat_set_property (GObject *object,
647 EmpathyTpChatPriv *priv;
650 priv = GET_PRIV (object);
651 chat = EMPATHY_TP_CHAT (object);
653 if (param_id >= PROP_ANONYMOUS &&
654 param_id <= PROP_SUBJECT_TIMESTAMP) {
655 if (priv->props_iface) {
656 tp_props_iface_set_value (TELEPATHY_PROPS_IFACE (priv->props_iface),
666 priv->account = g_object_ref (g_value_get_object (value));
669 priv->tp_chan = g_object_ref (g_value_get_object (value));
671 case PROP_ACKNOWLEDGE:
672 empathy_tp_chat_set_acknowledge (EMPATHY_TP_CHAT (object),
673 g_value_get_boolean (value));
676 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
682 empathy_tp_chat_class_init (EmpathyTpChatClass *klass)
684 GObjectClass *object_class = G_OBJECT_CLASS (klass);
686 object_class->finalize = tp_chat_finalize;
687 object_class->constructor = tp_chat_constructor;
688 object_class->get_property = tp_chat_get_property;
689 object_class->set_property = tp_chat_set_property;
691 /* Construct-only properties */
692 g_object_class_install_property (object_class,
694 g_param_spec_object ("account",
696 "The account associated with the channel",
699 G_PARAM_CONSTRUCT_ONLY));
700 g_object_class_install_property (object_class,
702 g_param_spec_object ("tp-chan",
704 "The text channel for the chat",
707 G_PARAM_CONSTRUCT_ONLY));
709 /* Normal properties */
710 g_object_class_install_property (object_class,
712 g_param_spec_boolean ("acknowledge",
718 /* Properties of Text Channel */
719 g_object_class_install_property (object_class,
721 g_param_spec_boolean ("anonymous",
726 g_object_class_install_property (object_class,
728 g_param_spec_boolean ("invite-only",
733 g_object_class_install_property (object_class,
735 g_param_spec_uint ("limit",
742 g_object_class_install_property (object_class,
744 g_param_spec_boolean ("limited",
749 g_object_class_install_property (object_class,
751 g_param_spec_boolean ("moderated",
756 g_object_class_install_property (object_class,
758 g_param_spec_string ("name",
763 g_object_class_install_property (object_class,
765 g_param_spec_string ("description",
770 g_object_class_install_property (object_class,
772 g_param_spec_string ("password",
777 g_object_class_install_property (object_class,
778 PROP_PASSWORD_REQUIRED,
779 g_param_spec_boolean ("password-required",
784 g_object_class_install_property (object_class,
786 g_param_spec_boolean ("persistent",
791 g_object_class_install_property (object_class,
793 g_param_spec_boolean ("private",
799 g_object_class_install_property (object_class,
801 g_param_spec_string ("subject",
806 g_object_class_install_property (object_class,
807 PROP_SUBJECT_CONTACT,
808 g_param_spec_uint ("subject-contact",
815 g_object_class_install_property (object_class,
816 PROP_SUBJECT_TIMESTAMP,
817 g_param_spec_uint ("subject-timestamp",
826 signals[MESSAGE_RECEIVED] =
827 g_signal_new ("message-received",
828 G_TYPE_FROM_CLASS (klass),
832 g_cclosure_marshal_VOID__OBJECT,
834 1, EMPATHY_TYPE_MESSAGE);
836 signals[SEND_ERROR] =
837 g_signal_new ("send-error",
838 G_TYPE_FROM_CLASS (klass),
842 _empathy_marshal_VOID__OBJECT_UINT,
844 2, EMPATHY_TYPE_MESSAGE, G_TYPE_UINT);
846 signals[CHAT_STATE_CHANGED] =
847 g_signal_new ("chat-state-changed",
848 G_TYPE_FROM_CLASS (klass),
852 _empathy_marshal_VOID__OBJECT_UINT,
854 2, EMPATHY_TYPE_CONTACT, G_TYPE_UINT);
857 g_signal_new ("destroy",
858 G_TYPE_FROM_CLASS (klass),
862 g_cclosure_marshal_VOID__VOID,
866 g_type_class_add_private (object_class, sizeof (EmpathyTpChatPriv));
870 empathy_tp_chat_init (EmpathyTpChat *chat)
875 empathy_tp_chat_new (McAccount *account,
878 return g_object_new (EMPATHY_TYPE_TP_CHAT,
885 empathy_tp_chat_new_with_contact (EmpathyContact *contact)
892 const gchar *bus_name;
895 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
897 mc = empathy_mission_control_new ();
898 account = empathy_contact_get_account (contact);
900 if (mission_control_get_connection_status (mc, account, NULL) != 0) {
901 /* The account is not connected. */
905 tp_conn = mission_control_get_connection (mc, account, NULL);
906 g_return_val_if_fail (tp_conn != NULL, NULL);
907 bus_name = dbus_g_proxy_get_bus_name (DBUS_G_PROXY (tp_conn));
908 handle = empathy_contact_get_handle (contact);
910 text_chan = tp_conn_new_channel (tp_get_bus (),
913 TP_IFACE_CHANNEL_TYPE_TEXT,
914 TP_HANDLE_TYPE_CONTACT,
918 chat = empathy_tp_chat_new (account, text_chan);
920 g_object_unref (tp_conn);
921 g_object_unref (text_chan);
928 empathy_tp_chat_get_acknowledge (EmpathyTpChat *chat)
930 EmpathyTpChatPriv *priv;
932 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), FALSE);
934 priv = GET_PRIV (chat);
936 return priv->acknowledge;
940 empathy_tp_chat_set_acknowledge (EmpathyTpChat *chat,
941 gboolean acknowledge)
943 EmpathyTpChatPriv *priv;
945 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
947 priv = GET_PRIV (chat);
949 priv->acknowledge = acknowledge;
950 g_object_notify (G_OBJECT (chat), "acknowledge");
954 empathy_tp_chat_get_channel (EmpathyTpChat *chat)
956 EmpathyTpChatPriv *priv;
958 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
960 priv = GET_PRIV (chat);
962 return priv->tp_chan;
966 empathy_tp_chat_get_account (EmpathyTpChat *chat)
968 EmpathyTpChatPriv *priv;
970 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
972 priv = GET_PRIV (chat);
974 return priv->account;
978 empathy_tp_chat_get_pendings (EmpathyTpChat *chat)
980 EmpathyTpChatPriv *priv;
982 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
984 priv = GET_PRIV (chat);
986 tp_chan_type_text_list_pending_messages_async (priv->text_iface,
988 tp_chat_list_pending_messages_cb,
995 empathy_tp_chat_send (EmpathyTpChat *chat,
996 EmpathyMessage *message)
998 EmpathyTpChatPriv *priv;
999 const gchar *message_body;
1000 EmpathyMessageType message_type;
1001 GError *error = NULL;
1003 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1004 g_return_if_fail (EMPATHY_IS_MESSAGE (message));
1006 priv = GET_PRIV (chat);
1008 message_body = empathy_message_get_body (message);
1009 message_type = empathy_message_get_type (message);
1011 empathy_debug (DEBUG_DOMAIN, "Sending message: %s", message_body);
1012 if (!tp_chan_type_text_send (priv->text_iface,
1016 empathy_debug (DEBUG_DOMAIN,
1018 error ? error->message : "No error given");
1019 g_clear_error (&error);
1024 empathy_tp_chat_set_state (EmpathyTpChat *chat,
1025 TpChannelChatState state)
1027 EmpathyTpChatPriv *priv;
1028 GError *error = NULL;
1030 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1032 priv = GET_PRIV (chat);
1034 if (priv->chat_state_iface) {
1035 empathy_debug (DEBUG_DOMAIN, "Set state: %d", state);
1036 if (!tp_chan_iface_chat_state_set_chat_state (priv->chat_state_iface,
1039 empathy_debug (DEBUG_DOMAIN,
1040 "Set Chat State Error: %s",
1041 error ? error->message : "No error given");
1042 g_clear_error (&error);
1048 empathy_tp_chat_get_id (EmpathyTpChat *chat)
1050 EmpathyTpChatPriv *priv;
1052 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1054 priv = GET_PRIV (chat);
1057 priv->id = empathy_inspect_channel (priv->account, priv->tp_chan);