telepathy-gabble: im-channel: send delivery reports when requested...

Will Thompson wjt at kemper.freedesktop.org
Thu Dec 6 10:37:23 PST 2012


Module: telepathy-gabble
Branch: master
Commit: 121fa91e6939dca982e631d104405cb2735b1ecb
URL:    http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=121fa91e6939dca982e631d104405cb2735b1ecb

Author: Will Thompson <will.thompson at collabora.co.uk>
Date:   Wed Oct 31 23:06:04 2012 +0000

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.

---

 src/im-channel.c |   39 +++++++++++++++++++++++++++++++++++++++
 src/im-channel.h |    2 ++
 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 a11f063..9cbdbfa 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 4b6fc7b..c094084 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 e0bff2b..4170d10 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)
     {



More information about the telepathy-commits mailing list