aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libempathy-gtk/empathy-chat.c19
-rw-r--r--libempathy/empathy-tp-chat.c65
-rw-r--r--libempathy/empathy-tp-chat.h2
3 files changed, 56 insertions, 30 deletions
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c
index 2d906b0f4..53c4677fc 100644
--- a/libempathy-gtk/empathy-chat.c
+++ b/libempathy-gtk/empathy-chat.c
@@ -868,7 +868,7 @@ 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);
@@ -888,12 +888,13 @@ chat_command_me (EmpathyChat *chat,
tmp = g_strdup_printf ("%s %s", empathy_contact_get_alias (self_contact),
strv[1]);
- message = empathy_message_new (tmp);
+ message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+ tmp);
g_free (tmp);
}
else {
- message = empathy_message_new (strv[1]);
- empathy_message_set_tptype (message, TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION);
+ message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION,
+ strv[1]);
}
empathy_tp_chat_send (priv->tp_chat, message);
@@ -905,9 +906,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);
}
@@ -1074,7 +1076,7 @@ chat_send (EmpathyChat *chat,
const gchar *msg)
{
EmpathyChatPriv *priv;
- EmpathyMessage *message;
+ TpMessage *message;
guint i;
if (EMP_STR_EMPTY (msg)) {
@@ -1144,7 +1146,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 eed87d90f..44c4eab26 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -371,19 +371,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);
}
}
@@ -1550,27 +1577,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 f7998e06f..7c998a3fa 100644
--- a/libempathy/empathy-tp-chat.h
+++ b/libempathy/empathy-tp-chat.h
@@ -69,7 +69,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,