aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
authorDanielle Madeley <danielle.madeley@collabora.co.uk>2011-05-05 16:22:31 +0800
committerDanielle Madeley <danielle.madeley@collabora.co.uk>2011-05-05 16:22:31 +0800
commitc698741b1825e306de447fa09624f4a93f067374 (patch)
treeab44edd2ab39a6a5923653aaeae1f9d6b3d7e574 /libempathy
parent981d17576bb3451bd4ac79cbd2de079fb64d260b (diff)
parent0d44943efc4f3f727861387ba89f57238aa92577 (diff)
downloadgsoc2013-empathy-c698741b1825e306de447fa09624f4a93f067374.tar
gsoc2013-empathy-c698741b1825e306de447fa09624f4a93f067374.tar.gz
gsoc2013-empathy-c698741b1825e306de447fa09624f4a93f067374.tar.bz2
gsoc2013-empathy-c698741b1825e306de447fa09624f4a93f067374.tar.lz
gsoc2013-empathy-c698741b1825e306de447fa09624f4a93f067374.tar.xz
gsoc2013-empathy-c698741b1825e306de447fa09624f4a93f067374.tar.zst
gsoc2013-empathy-c698741b1825e306de447fa09624f4a93f067374.zip
Merge branch 'delivery-reports-rebase'
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/empathy-tp-chat.c94
-rw-r--r--libempathy/empathy-tp-chat.h6
2 files changed, 93 insertions, 7 deletions
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index b8e4cdf0c..72c6bebf0 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -61,6 +61,8 @@ typedef struct {
gboolean can_upgrade_to_muc;
gboolean got_sms_channel;
gboolean sms_channel;
+
+ GHashTable *messages_being_sent;
} EmpathyTpChatPriv;
static void tp_chat_iface_init (EmpathyContactListIface *iface);
@@ -73,6 +75,7 @@ enum {
PROP_PASSWORD_NEEDED,
PROP_READY,
PROP_SMS_CHANNEL,
+ PROP_N_MESSAGES_SENDING,
};
enum {
@@ -93,6 +96,40 @@ G_DEFINE_TYPE_WITH_CODE (EmpathyTpChat, empathy_tp_chat, G_TYPE_OBJECT,
static void acknowledge_messages (EmpathyTpChat *chat, GArray *ids);
static void
+tp_chat_set_delivery_status (EmpathyTpChat *self,
+ const gchar *token,
+ EmpathyDeliveryStatus delivery_status)
+{
+ EmpathyTpChatPriv *priv = GET_PRIV (self);
+ TpDeliveryReportingSupportFlags flags =
+ tp_text_channel_get_delivery_reporting_support (
+ TP_TEXT_CHANNEL (priv->channel));
+
+ /* channel must support receiving failures and successes */
+ if (!tp_str_empty (token) &&
+ flags & TP_DELIVERY_REPORTING_SUPPORT_FLAG_RECEIVE_FAILURES &&
+ flags & TP_DELIVERY_REPORTING_SUPPORT_FLAG_RECEIVE_SUCCESSES) {
+
+ DEBUG ("Delivery status (%s) = %u", token, delivery_status);
+
+ switch (delivery_status) {
+ case EMPATHY_DELIVERY_STATUS_NONE:
+ g_hash_table_remove (priv->messages_being_sent,
+ token);
+ break;
+
+ default:
+ g_hash_table_insert (priv->messages_being_sent,
+ g_strdup (token),
+ GUINT_TO_POINTER (delivery_status));
+ break;
+ }
+
+ g_object_notify (G_OBJECT (self), "n-messages-sending");
+ }
+}
+
+static void
tp_chat_invalidated_cb (TpProxy *proxy,
guint domain,
gint code,
@@ -322,19 +359,38 @@ handle_delivery_report (EmpathyTpChat *self,
gboolean valid;
GPtrArray *echo;
const gchar *message_body = NULL;
+ const gchar *delivery_dbus_error;
+ const gchar *delivery_token = NULL;
header = tp_message_peek (message, 0);
if (header == NULL)
goto out;
+ delivery_token = tp_asv_get_string (header, "delivery-token");
delivery_status = tp_asv_get_uint32 (header, "delivery-status", &valid);
- if (!valid || delivery_status != TP_DELIVERY_STATUS_PERMANENTLY_FAILED)
+
+ if (!valid) {
+ goto out;
+ } else if (delivery_status == TP_DELIVERY_STATUS_ACCEPTED) {
+ DEBUG ("Accepted %s", delivery_token);
+ tp_chat_set_delivery_status (self, delivery_token,
+ EMPATHY_DELIVERY_STATUS_ACCEPTED);
+ goto out;
+ } else if (delivery_status == TP_DELIVERY_STATUS_DELIVERED) {
+ DEBUG ("Delivered %s", delivery_token);
+ tp_chat_set_delivery_status (self, delivery_token,
+ EMPATHY_DELIVERY_STATUS_NONE);
+ goto out;
+ } else if (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;
+ delivery_dbus_error = tp_asv_get_string (header, "delivery-dbus-error");
+
/* 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",
@@ -347,7 +403,10 @@ handle_delivery_report (EmpathyTpChat *self,
message_body = tp_asv_get_string (echo_body, "content");
}
- g_signal_emit (self, signals[SEND_ERROR], 0, message_body, delivery_error);
+ tp_chat_set_delivery_status (self, delivery_token,
+ EMPATHY_DELIVERY_STATUS_NONE);
+ g_signal_emit (self, signals[SEND_ERROR], 0, message_body,
+ delivery_error, delivery_dbus_error);
out:
tp_text_channel_ack_message_async (TP_TEXT_CHANNEL (priv->channel),
@@ -439,9 +498,10 @@ message_send_cb (GObject *source,
{
EmpathyTpChat *chat = user_data;
TpTextChannel *channel = (TpTextChannel *) source;
+ gchar *token = NULL;
GError *error = NULL;
- if (!tp_text_channel_send_message_finish (channel, result, NULL, &error)) {
+ if (!tp_text_channel_send_message_finish (channel, result, &token, &error)) {
DEBUG ("Error: %s", error->message);
/* FIXME: we should use the body of the message as first argument of the
@@ -449,10 +509,14 @@ message_send_cb (GObject *source,
* 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,
- NULL, error_to_text_send_error (error));
+ NULL, error_to_text_send_error (error), NULL);
g_error_free (error);
}
+
+ tp_chat_set_delivery_status (chat, token,
+ EMPATHY_DELIVERY_STATUS_SENDING);
+ g_free (token);
}
typedef struct {
@@ -812,6 +876,7 @@ tp_chat_finalize (GObject *object)
g_queue_free (priv->messages_queue);
g_queue_free (priv->pending_messages_queue);
+ g_hash_table_destroy (priv->messages_being_sent);
G_OBJECT_CLASS (empathy_tp_chat_parent_class)->finalize (object);
}
@@ -1415,6 +1480,10 @@ tp_chat_get_property (GObject *object,
case PROP_SMS_CHANNEL:
g_value_set_boolean (value, priv->sms_channel);
break;
+ case PROP_N_MESSAGES_SENDING:
+ g_value_set_uint (value,
+ g_hash_table_size (priv->messages_being_sent));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -1504,6 +1573,14 @@ empathy_tp_chat_class_init (EmpathyTpChatClass *klass)
FALSE,
G_PARAM_READABLE));
+ g_object_class_install_property (object_class,
+ PROP_N_MESSAGES_SENDING,
+ g_param_spec_uint ("n-messages-sending",
+ "Num Messages Sending",
+ "The number of messages being sent",
+ 0, G_MAXUINT, 0,
+ G_PARAM_READABLE));
+
/* Signals */
signals[MESSAGE_RECEIVED] =
g_signal_new ("message-received",
@@ -1521,9 +1598,9 @@ empathy_tp_chat_class_init (EmpathyTpChatClass *klass)
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
- _empathy_marshal_VOID__STRING_UINT,
+ _empathy_marshal_VOID__STRING_UINT_STRING,
G_TYPE_NONE,
- 2, G_TYPE_STRING, G_TYPE_UINT);
+ 3, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING);
signals[CHAT_STATE_CHANGED] =
g_signal_new ("chat-state-changed",
@@ -1567,6 +1644,8 @@ empathy_tp_chat_init (EmpathyTpChat *chat)
chat->priv = priv;
priv->messages_queue = g_queue_new ();
priv->pending_messages_queue = g_queue_new ();
+ priv->messages_being_sent = g_hash_table_new_full (
+ g_str_hash, g_str_equal, g_free, NULL);
}
static void
@@ -1675,7 +1754,8 @@ empathy_tp_chat_send (EmpathyTpChat *chat,
DEBUG ("Sending message: %s", message_body);
tp_text_channel_send_message_async (TP_TEXT_CHANNEL (priv->channel),
- message, 0, message_send_cb, chat);
+ message, TP_MESSAGE_SENDING_FLAG_REPORT_DELIVERY,
+ message_send_cb, chat);
g_free (message_body);
}
diff --git a/libempathy/empathy-tp-chat.h b/libempathy/empathy-tp-chat.h
index 7ac1296e0..83c7fe7d1 100644
--- a/libempathy/empathy-tp-chat.h
+++ b/libempathy/empathy-tp-chat.h
@@ -59,6 +59,12 @@ typedef struct {
GValue *value;
} EmpathyTpChatProperty;
+typedef enum {
+ EMPATHY_DELIVERY_STATUS_NONE,
+ EMPATHY_DELIVERY_STATUS_SENDING,
+ EMPATHY_DELIVERY_STATUS_ACCEPTED
+} EmpathyDeliveryStatus;
+
GType empathy_tp_chat_get_type (void) G_GNUC_CONST;
EmpathyTpChat *empathy_tp_chat_new (TpAccount *account,
TpChannel *channel);