aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy/empathy-tp-chat.c
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-04-15 22:41:25 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-04-18 20:40:30 +0800
commit6c45c22ef3b659f977221ad691638a073bcfa94e (patch)
treeaf7525c5e69436ea3bde76bb041a65e7129040c1 /libempathy/empathy-tp-chat.c
parent92ff1b9177bd6d8633b8d92357e5081db0e9554f (diff)
downloadgsoc2013-empathy-6c45c22ef3b659f977221ad691638a073bcfa94e.tar
gsoc2013-empathy-6c45c22ef3b659f977221ad691638a073bcfa94e.tar.gz
gsoc2013-empathy-6c45c22ef3b659f977221ad691638a073bcfa94e.tar.bz2
gsoc2013-empathy-6c45c22ef3b659f977221ad691638a073bcfa94e.tar.lz
gsoc2013-empathy-6c45c22ef3b659f977221ad691638a073bcfa94e.tar.xz
gsoc2013-empathy-6c45c22ef3b659f977221ad691638a073bcfa94e.tar.zst
gsoc2013-empathy-6c45c22ef3b659f977221ad691638a073bcfa94e.zip
use tp_text_channel_send_message_async()
Diffstat (limited to 'libempathy/empathy-tp-chat.c')
-rw-r--r--libempathy/empathy-tp-chat.c65
1 files changed, 44 insertions, 21 deletions
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