aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-04-15 22:41:25 +0800
committerDanielle Madeley <danielle.madeley@collabora.co.uk>2011-04-21 10:35:59 +0800
commit78dae7e27ab6fb535a7fe5ada450403b1d91c7bb (patch)
treec4355627d0077100c7a8b193f9e6e37f4a6146b0
parent755d626b3b010d2b2aaecb968c8faf579df92790 (diff)
downloadgsoc2013-empathy-78dae7e27ab6fb535a7fe5ada450403b1d91c7bb.tar
gsoc2013-empathy-78dae7e27ab6fb535a7fe5ada450403b1d91c7bb.tar.gz
gsoc2013-empathy-78dae7e27ab6fb535a7fe5ada450403b1d91c7bb.tar.bz2
gsoc2013-empathy-78dae7e27ab6fb535a7fe5ada450403b1d91c7bb.tar.lz
gsoc2013-empathy-78dae7e27ab6fb535a7fe5ada450403b1d91c7bb.tar.xz
gsoc2013-empathy-78dae7e27ab6fb535a7fe5ada450403b1d91c7bb.tar.zst
gsoc2013-empathy-78dae7e27ab6fb535a7fe5ada450403b1d91c7bb.zip
use tp_text_channel_send_message_async()
-rw-r--r--libempathy-gtk/empathy-chat.c41
-rw-r--r--libempathy/empathy-tp-chat.c65
-rw-r--r--libempathy/empathy-tp-chat.h2
3 files changed, 79 insertions, 29 deletions
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c
index 986f84594..ee18be657 100644
--- a/libempathy-gtk/empathy-chat.c
+++ b/libempathy-gtk/empathy-chat.c
@@ -815,10 +815,35 @@ chat_command_me (EmpathyChat *chat,
GStrv strv)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- EmpathyMessage *message;
+ TpMessage *message;
+ TpChannel *channel;
+
+ channel = empathy_tp_chat_get_channel (priv->tp_chat);
+
+ /* Strictly speaking we don't depend yet on Messages so best to check that
+ * the channel is actually a TpTextChannel before casting it. */
+ if (TP_IS_TEXT_CHANNEL (channel) &&
+ !tp_text_channel_supports_message_type (TP_TEXT_CHANNEL (channel),
+ TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION)) {
+ /* Action message are not supported, 'simulate' the action */
+ EmpathyContact *self_contact;
+ gchar *tmp;
+
+ self_contact = empathy_tp_chat_get_self_contact (priv->tp_chat);
+ /* The TpChat can't be ready if it doesn't have the self contact */
+ g_assert (self_contact != NULL);
+
+ tmp = g_strdup_printf ("%s %s", empathy_contact_get_alias (self_contact),
+ strv[1]);
+ message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+ tmp);
+ g_free (tmp);
+ }
+ else {
+ message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION,
+ strv[1]);
+ }
- message = empathy_message_new (strv[1]);
- empathy_message_set_tptype (message, TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION);
empathy_tp_chat_send (priv->tp_chat, message);
g_object_unref (message);
}
@@ -828,9 +853,10 @@ chat_command_say (EmpathyChat *chat,
GStrv strv)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- EmpathyMessage *message;
+ TpMessage *message;
- message = empathy_message_new (strv[1]);
+ message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+ strv[1]);
empathy_tp_chat_send (priv->tp_chat, message);
g_object_unref (message);
}
@@ -979,7 +1005,7 @@ chat_send (EmpathyChat *chat,
const gchar *msg)
{
EmpathyChatPriv *priv;
- EmpathyMessage *message;
+ TpMessage *message;
guint i;
if (EMP_STR_EMPTY (msg)) {
@@ -1044,7 +1070,8 @@ chat_send (EmpathyChat *chat,
}
}
- message = empathy_message_new (msg);
+ message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+ msg);
empathy_tp_chat_send (priv->tp_chat, message);
g_object_unref (message);
}
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index 1d5b43cb6..efc1afbee 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -374,19 +374,46 @@ tp_chat_send_error_cb (TpChannel *channel,
g_signal_emit (chat, signals[SEND_ERROR], 0, message_body, error_code);
}
+static TpChannelTextSendError
+error_to_text_send_error (GError *error)
+{
+ if (error->domain != TP_ERRORS)
+ return TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN;
+
+ switch (error->code) {
+ case TP_ERROR_OFFLINE:
+ return TP_CHANNEL_TEXT_SEND_ERROR_OFFLINE;
+ case TP_ERROR_INVALID_HANDLE:
+ return TP_CHANNEL_TEXT_SEND_ERROR_INVALID_CONTACT;
+ case TP_ERROR_PERMISSION_DENIED:
+ return TP_CHANNEL_TEXT_SEND_ERROR_PERMISSION_DENIED;
+ case TP_ERROR_NOT_IMPLEMENTED:
+ return TP_CHANNEL_TEXT_SEND_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN;
+}
+
static void
-tp_chat_send_cb (TpChannel *proxy,
- const GError *error,
- gpointer user_data,
- GObject *chat)
+message_send_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
- EmpathyMessage *message = EMPATHY_MESSAGE (user_data);
+ EmpathyTpChat *chat = user_data;
+ TpTextChannel *channel = (TpTextChannel *) source;
+ GError *error = NULL;
- if (error) {
+ if (!tp_text_channel_send_message_finish (channel, result, NULL, &error)) {
DEBUG ("Error: %s", error->message);
+
+ /* FIXME: we should use the body of the message as first argument of the
+ * signal but can't easily get it as we just get a user_data pointer. Once
+ * we'll have rebased EmpathyTpChat on top of TpTextChannel we'll be able
+ * to use the user_data pointer to pass the message and fix this. */
g_signal_emit (chat, signals[SEND_ERROR], 0,
- empathy_message_get_body (message),
- TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN);
+ NULL, error_to_text_send_error (error));
+
+ g_error_free (error);
}
}
@@ -1627,27 +1654,23 @@ empathy_tp_chat_is_ready (EmpathyTpChat *chat)
void
empathy_tp_chat_send (EmpathyTpChat *chat,
- EmpathyMessage *message)
+ TpMessage *message)
{
EmpathyTpChatPriv *priv = GET_PRIV (chat);
- const gchar *message_body;
- TpChannelTextMessageType message_type;
+ gchar *message_body;
g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
- g_return_if_fail (EMPATHY_IS_MESSAGE (message));
+ g_return_if_fail (TP_IS_CLIENT_MESSAGE (message));
g_return_if_fail (priv->ready);
- message_body = empathy_message_get_body (message);
- message_type = empathy_message_get_tptype (message);
+ message_body = tp_message_to_text (message, NULL);
DEBUG ("Sending message: %s", message_body);
- tp_cli_channel_type_text_call_send (priv->channel, -1,
- message_type,
- message_body,
- tp_chat_send_cb,
- g_object_ref (message),
- (GDestroyNotify) g_object_unref,
- G_OBJECT (chat));
+
+ tp_text_channel_send_message_async (TP_TEXT_CHANNEL (priv->channel),
+ message, 0, message_send_cb, chat);
+
+ g_free (message_body);
}
void
diff --git a/libempathy/empathy-tp-chat.h b/libempathy/empathy-tp-chat.h
index 5559bdd4b..d72c30e06 100644
--- a/libempathy/empathy-tp-chat.h
+++ b/libempathy/empathy-tp-chat.h
@@ -70,7 +70,7 @@ TpAccount * empathy_tp_chat_get_account (EmpathyTpChat *chat);
TpConnection * empathy_tp_chat_get_connection (EmpathyTpChat *chat);
gboolean empathy_tp_chat_is_ready (EmpathyTpChat *chat);
void empathy_tp_chat_send (EmpathyTpChat *chat,
- EmpathyMessage *message);
+ TpMessage *message);
void empathy_tp_chat_set_state (EmpathyTpChat *chat,
TpChannelChatState state);
void empathy_tp_chat_set_property (EmpathyTpChat *chat,