[empathy: 12/19] use delivery report instead of Text.SendError



commit d12280ac153d2b16b2a6a7181ebc5fa4c9300408
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Mon Apr 18 14:31:42 2011 +0200

    use delivery report instead of Text.SendError

 libempathy/empathy-tp-chat.c |   75 ++++++++++++++++++++++++++++--------------
 1 files changed, 50 insertions(+), 25 deletions(-)
---
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index 114ad47..5801125 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -309,13 +309,61 @@ tp_chat_build_message (EmpathyTpChat *chat,
 }
 
 static void
+handle_delivery_report (EmpathyTpChat *self,
+		TpMessage *message)
+{
+	EmpathyTpChatPriv *priv = GET_PRIV (self);
+	TpDeliveryStatus delivery_status;
+	const GHashTable *header;
+	TpChannelTextSendError delivery_error;
+	gboolean valid;
+	GPtrArray *echo;
+	const gchar *message_body = NULL;
+
+	header = tp_message_peek (message, 0);
+	if (header == NULL)
+		goto out;
+
+	delivery_status = tp_asv_get_uint32 (header, "delivery-status", &valid);
+	if (!valid || delivery_status != TP_DELIVERY_STATUS_PERMANENTLY_FAILED)
+		goto out;
+
+	delivery_error = tp_asv_get_uint32 (header, "delivery-error", &valid);
+	if (!valid)
+		delivery_error = TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN;
+
+	/* TODO: ideally we should use tp-glib API giving us the echoed message as a
+	 * TpMessage. (fdo #35884) */
+	echo = tp_asv_get_boxed (header, "delivery-echo",
+		TP_ARRAY_TYPE_MESSAGE_PART_LIST);
+	if (echo != NULL && echo->len >= 1) {
+		const GHashTable *echo_body;
+
+		echo_body = g_ptr_array_index (echo, 1);
+		if (echo_body != NULL)
+			message_body = tp_asv_get_string (echo_body, "content");
+	}
+
+	g_signal_emit (self, signals[SEND_ERROR], 0, message_body, delivery_error);
+
+out:
+	tp_text_channel_ack_message_async (TP_TEXT_CHANNEL (priv->channel),
+		message, NULL, NULL);
+}
+
+static void
 handle_incoming_message (EmpathyTpChat *self,
-	TpMessage *message,
-	gboolean pending)
+			 TpMessage *message,
+			 gboolean pending)
 {
 	EmpathyTpChatPriv *priv = GET_PRIV (self);
 	gchar *message_body;
 
+	if (tp_message_is_delivery_report (message)) {
+		handle_delivery_report (self, message);
+		return;
+	}
+
 	message_body = tp_message_to_text (message, NULL);
 
 	DEBUG ("Message %s (channel %s): %s",
@@ -361,25 +409,6 @@ message_sent_cb (TpTextChannel   *channel,
 	g_free (message_body);
 }
 
-static void
-tp_chat_send_error_cb (TpChannel   *channel,
-		       guint        error_code,
-		       guint        timestamp,
-		       guint        message_type,
-		       const gchar *message_body,
-		       gpointer     user_data,
-		       GObject     *chat)
-{
-	EmpathyTpChatPriv *priv = GET_PRIV (chat);
-
-	if (priv->channel == NULL)
-		return;
-
-	DEBUG ("Error sending '%s' (%d)", message_body, error_code);
-
-	g_signal_emit (chat, signals[SEND_ERROR], 0, message_body, error_code);
-}
-
 static TpChannelTextSendError
 error_to_text_send_error (GError *error)
 {
@@ -818,10 +847,6 @@ check_almost_ready (EmpathyTpChat *chat)
 	tp_g_signal_connect_object (priv->channel, "message-sent",
 		G_CALLBACK (message_sent_cb), chat, 0);
 
-	tp_cli_channel_type_text_connect_to_send_error (priv->channel,
-							tp_chat_send_error_cb,
-							NULL, NULL,
-							G_OBJECT (chat), NULL);
 	tp_cli_channel_interface_chat_state_connect_to_chat_state_changed (priv->channel,
 									   tp_chat_state_changed_cb,
 									   NULL, NULL,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]