diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2012-10-31 23:06:04 +0000 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2012-12-06 18:28:32 +0000 |
commit | 121fa91e6939dca982e631d104405cb2735b1ecb (patch) | |
tree | 37294cf22af4515cd618b58e093328303531218f | |
parent | 4af3fe1066bfd36894fb10f80148269ed94d6c11 (diff) |
im-channel: send delivery reports when requested...
...and the sender is able to see that we are online, is not blocked, and
so on. This is not a presence leak: all this allows the peer to do that
they cannot already do is determine that our internet connection has not
died without our server noticing.
Sending a receipt as soon as the message is signalled to the UI, rather
than after it's acknowledged, is absolutely compliant with XEP-0184 ยง4:
> Finally, this protocol does not enable the sender to know that the intended
> recipient has read the message[, ...] that an end user client has
> presented the message to a human user (if any), etc.
-rw-r--r-- | src/im-channel.c | 39 | ||||
-rw-r--r-- | src/im-channel.h | 2 | ||||
-rw-r--r-- | src/im-factory.c | 3 |
3 files changed, 43 insertions, 1 deletions
diff --git a/src/im-channel.c b/src/im-channel.c index a11f063bb..9cbdbfaab 100644 --- a/src/im-channel.c +++ b/src/im-channel.c @@ -436,9 +436,46 @@ build_message ( return msg; } +static void +maybe_send_delivery_report ( + GabbleIMChannel *self, + WockyStanza *message, + const gchar *jid, + const gchar *id) +{ + TpBaseChannel *base = TP_BASE_CHANNEL (self); + TpHandle target = tp_base_channel_get_target_handle (base); + TpBaseConnection *base_conn = tp_base_channel_get_connection (base); + GabbleConnection *conn = GABBLE_CONNECTION (base_conn); + WockyStanza *report; + + if (id == NULL) + return; + + if (wocky_node_get_child_ns (wocky_stanza_get_top_node (message), + "request", NS_RECEIPTS) == NULL) + return; + + if (conn->self_presence->status == GABBLE_PRESENCE_HIDDEN || + !gabble_roster_handle_gets_presence_from_us (conn->roster, target)) + return; + + report = wocky_stanza_build ( + WOCKY_STANZA_TYPE_MESSAGE, WOCKY_STANZA_SUB_TYPE_NONE, + NULL, jid, + '(', "received", ':', NS_RECEIPTS, + '@', "id", id, + ')', NULL); + + _gabble_connection_send (conn, report, NULL); + g_object_unref (report); +} + /* * _gabble_im_channel_receive: * @chan: a channel + * @message: the <message> stanza, from which all the following arguments were + * extracted. * @type: the message type * @from: the full JID we received the message from * @timestamp: the time at which the message was sent (not the time it was @@ -453,6 +490,7 @@ build_message ( */ void _gabble_im_channel_receive (GabbleIMChannel *chan, + WockyStanza *message, TpChannelTextMessageType type, const char *from, time_t timestamp, @@ -490,6 +528,7 @@ _gabble_im_channel_receive (GabbleIMChannel *chan, tp_message_set_string (msg, 0, "message-token", id); tp_message_mixin_take_received (G_OBJECT (chan), msg); + maybe_send_delivery_report (chan, message, from, id); } void diff --git a/src/im-channel.h b/src/im-channel.h index 4b6fc7bee..c09408484 100644 --- a/src/im-channel.h +++ b/src/im-channel.h @@ -25,6 +25,7 @@ #include <time.h> #include <telepathy-glib/telepathy-glib.h> +#include <wocky/wocky.h> G_BEGIN_DECLS @@ -63,6 +64,7 @@ GType gabble_im_channel_get_type (void); GabbleIMChannelClass)) void _gabble_im_channel_receive (GabbleIMChannel *chan, + WockyStanza *message, TpChannelTextMessageType type, const char *from, time_t timestamp, diff --git a/src/im-factory.c b/src/im-factory.c index e0bff2bdf..4170d1012 100644 --- a/src/im-factory.c +++ b/src/im-factory.c @@ -257,7 +257,8 @@ im_factory_message_cb ( } else if (body != NULL) { - _gabble_im_channel_receive (chan, msgtype, from, stamp, id, body, state); + _gabble_im_channel_receive (chan, message, msgtype, from, stamp, id, + body, state); } else if (state != -1) { |