[Telepathy-commits] [telepathy-gabble/master] Muc: emit delivery reports in response to echos from the MUC

Will Thompson will.thompson at collabora.co.uk
Tue Feb 3 06:34:49 PST 2009


---
 src/muc-channel.c             |   41 ++++++++++++++++++++++++++++-------------
 tests/twisted/muc/test-muc.py |   40 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 67 insertions(+), 14 deletions(-)

diff --git a/src/muc-channel.c b/src/muc-channel.c
index 3f316fa..9f2fa7a 100644
--- a/src/muc-channel.c
+++ b/src/muc-channel.c
@@ -2225,12 +2225,15 @@ _gabble_muc_channel_receive (GabbleMucChannel *chan,
                              const gchar *text,
                              LmMessage *msg)
 {
-  TpMessage *message;
   GabbleMucChannelPrivate *priv;
+  TpBaseConnection *base_conn;
+  TpMessage *message;
+  gboolean is_echo = FALSE;
 
   g_assert (GABBLE_IS_MUC_CHANNEL (chan));
 
   priv = GABBLE_MUC_CHANNEL_GET_PRIVATE (chan);
+  base_conn = (TpBaseConnection *) priv->conn;
 
   if (handle_type == TP_HANDLE_TYPE_ROOM)
     {
@@ -2239,18 +2242,14 @@ _gabble_muc_channel_receive (GabbleMucChannel *chan,
       return;
     }
 
-  if ((sender == chan->group.self_handle) && (timestamp == 0))
-    {
-      /* If we sent the message and it's not delayed, do nothing; we already
-       * emitted the Sent signals.
-       */
-
-      /* TODO: emit a delivery report. */
-      return;
-    }
+  /* If we sent the message and it's not delayed, this is an echo from the MUC;
+   * we'll emit a delivery report.
+   * For messages from other contacts, or our own delayed messages, we'll emit
+   * a received message.
+   */
+  is_echo = ((sender == chan->group.self_handle) && (timestamp == 0));
 
-  /* Receive messages from other contacts and our own if they're delayed */
-  message = tp_message_new ((TpBaseConnection *) priv->conn, 2, 2);
+  message = tp_message_new (base_conn, 2, 2);
 
   /* Header */
   if (msg_type != TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL)
@@ -2267,7 +2266,23 @@ _gabble_muc_channel_receive (GabbleMucChannel *chan,
   tp_message_set_string (message, 1, "type", "text/plain");
   tp_message_set_string (message, 1, "content", text);
 
-  tp_message_mixin_take_received (G_OBJECT (chan), message);
+  if (is_echo)
+    {
+      TpMessage *delivery_report = tp_message_new (base_conn, 1, 1);
+
+      tp_message_set_uint32 (delivery_report, 0, "message-type",
+          TP_CHANNEL_TEXT_MESSAGE_TYPE_DELIVERY_REPORT);
+      tp_message_set_uint32 (delivery_report, 0, "delivery-status",
+          1); /* FIXME: Delivery_Status_Delivered */
+      tp_message_take_message (delivery_report, 0, "delivery-echo",
+          message);
+
+      tp_message_mixin_take_received (G_OBJECT (chan), delivery_report);
+    }
+  else
+    {
+      tp_message_mixin_take_received (G_OBJECT (chan), message);
+    }
 }
 
 /**
diff --git a/tests/twisted/muc/test-muc.py b/tests/twisted/muc/test-muc.py
index 28c3f24..671edbd 100644
--- a/tests/twisted/muc/test-muc.py
+++ b/tests/twisted/muc/test-muc.py
@@ -183,7 +183,45 @@ def test(q, bus, conn, stream):
     elem['from'] = 'chat at conf.localhost/test'
     stream.send(elem)
 
-    # TODO: check for a delivery report
+    # Check that we got the corresponding delivery report
+    report, old_received = q.expect_many(
+        EventPattern('dbus-signal', signal='MessageReceived'),
+        EventPattern('dbus-signal', signal='Received'),
+        )
+
+    assert len(report.args) == 1, report.args
+    parts = report.args[0]
+    # The delivery report should just be a header, no body.
+    assert len(parts) == 1, parts
+    part = parts[0]
+    # The intended recipient was the MUC, so there's no contact handle
+    # suitable for being 'message-sender'.
+    assert 'message-sender' not in part or part['message-sender'] == 0, part
+    assert part['message-type'] == 4, part # Message_Type_Delivery_Report
+    assert part['delivery-status'] == 1, part # Delivery_Status_Delivered
+    # Gabble doesn't issue tokens for messages you send, so no token should be
+    # in the report
+    assert 'delivery-token' not in part, part
+    assert 'delivery-error' not in part, part
+    assert 'delivery-echo' in part, part
+
+    # Check that the included echo is from us, and matches all the keys in the
+    # message we sent.
+    echo = part['delivery-echo']
+    assert len(echo) == len(greeting), (echo, greeting)
+    # Earlier in this test we checked that handle 2 is us.
+    assert echo[0]['message-sender'] == 2, echo[0]
+    for i in range(0, len(echo)):
+        for key in greeting[i]:
+            assert key in echo[i], (i, key, echo)
+            assert echo[i][key] == greeting[i][key], (i, key, echo, greeting)
+
+    # The Text.Received signal should be a "you're not tall enough" stub
+    id, timestamp, sender, type, flags, text = old_received.args
+    assert sender == 0, old_received.args
+    assert type == 4, old_received.args # Message_Type_Delivery_Report
+    assert flags == 2, old_received.args # Non_Text_Content
+    assert text == '', old_received.args
 
 
     # Send a normal message using the Channel.Type.Text API
-- 
1.5.6.5




More information about the telepathy-commits mailing list