[Telepathy-commits] [telepathy-gabble/master] Send and receive message-token/delivery-token/sent message tokens, using the XMPP id attribute

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Mar 18 09:43:22 PDT 2009


---
 src/im-channel.c                 |   23 ++++++++++++++++++++
 src/im-channel.h                 |    4 +-
 src/im-factory.c                 |    6 ++--
 src/message-util.c               |   12 ++++++++++-
 src/message-util.h               |    4 +-
 src/muc-channel.c                |   21 +++++++++++++++++++
 src/muc-channel.h                |    5 ++-
 src/muc-factory.c                |    6 ++--
 tests/test-parse-message.c       |   42 +++++++++++++++++++++++++++++++------
 tests/twisted/muc/send-error.py  |    7 ++---
 tests/twisted/muc/test-muc.py    |   15 ++++++++++---
 tests/twisted/text/send-error.py |   11 ++++++++-
 tests/twisted/text/test-text.py  |    7 +++++-
 13 files changed, 132 insertions(+), 31 deletions(-)

diff --git a/src/im-channel.c b/src/im-channel.c
index 5c573d4..fb2b44c 100644
--- a/src/im-channel.c
+++ b/src/im-channel.c
@@ -42,6 +42,7 @@
 #include "presence.h"
 #include "presence-cache.h"
 #include "roster.h"
+#include "util.h"
 
 static void channel_iface_init (gpointer, gpointer);
 static void chat_state_iface_init (gpointer, gpointer);
@@ -508,6 +509,7 @@ _gabble_im_channel_receive (GabbleIMChannel *chan,
                             TpHandle sender,
                             const char *from,
                             time_t timestamp,
+                            const gchar *id,
                             const char *text,
                             TpChannelTextSendError send_error,
                             TpDeliveryStatus delivery_status)
@@ -537,6 +539,9 @@ _gabble_im_channel_receive (GabbleIMChannel *chan,
   if (timestamp != 0)
     tp_message_set_uint64 (msg, 0, "message-sent", timestamp);
 
+  if (id != NULL)
+    tp_message_set_string (msg, 0, "message-token", id);
+
   /* Body */
   tp_message_set_string (msg, 1, "content-type", "text/plain");
   tp_message_set_string (msg, 1, "content", text);
@@ -547,11 +552,22 @@ _gabble_im_channel_receive (GabbleIMChannel *chan,
           sender);
       tp_message_set_uint64 (msg, 0, "message-received", time (NULL));
 
+      /* Ensure that all incoming messages have an ID, either from the
+       * protocol or just a locally generated UUID */
+      if (id == NULL)
+        {
+          gchar *tmp = gabble_generate_id ();
+
+          tp_message_set_string (msg, 0, "message-token", tmp);
+          g_free (tmp);
+        }
+
       tp_message_mixin_take_received (G_OBJECT (chan), msg);
     }
   else
     {
       TpMessage *delivery_report = tp_message_new (base_conn, 1, 1);
+      gchar *tmp;
 
       tp_message_set_uint32 (delivery_report, 0, "message-type",
           TP_CHANNEL_TEXT_MESSAGE_TYPE_DELIVERY_REPORT);
@@ -560,10 +576,17 @@ _gabble_im_channel_receive (GabbleIMChannel *chan,
       tp_message_set_uint64 (delivery_report, 0, "message-received",
           time (NULL));
 
+      tmp = gabble_generate_id ();
+      tp_message_set_string (delivery_report, 0, "message-token", tmp);
+      g_free (tmp);
+
       tp_message_set_uint32 (delivery_report, 0, "delivery-status",
           delivery_status);
       tp_message_set_uint32 (delivery_report, 0, "delivery-error", send_error);
 
+      if (id != NULL)
+        tp_message_set_string (delivery_report, 0, "delivery-token", id);
+
       /* We're getting a send error, so the original sender of the echoed
        * message must be us! */
       tp_message_set_handle (msg, 0, "message-sender", TP_HANDLE_TYPE_CONTACT,
diff --git a/src/im-channel.h b/src/im-channel.h
index 80fc67a..7d7d96a 100644
--- a/src/im-channel.h
+++ b/src/im-channel.h
@@ -67,8 +67,8 @@ GType gabble_im_channel_get_type (void);
 
 void _gabble_im_channel_receive (GabbleIMChannel *chan,
     TpChannelTextMessageType type, TpHandle sender, const char *from,
-    time_t timestamp, const char *text, TpChannelTextSendError send_error,
-    TpDeliveryStatus delivery_status);
+    time_t timestamp, const char *id, const char *text,
+    TpChannelTextSendError send_error, TpDeliveryStatus delivery_status);
 void _gabble_im_channel_state_receive (GabbleIMChannel *chan, guint state);
 
 G_END_DECLS
diff --git a/src/im-factory.c b/src/im-factory.c
index b5fdcc0..0f09a88 100644
--- a/src/im-factory.c
+++ b/src/im-factory.c
@@ -215,7 +215,7 @@ im_factory_message_cb (LmMessageHandler *handler,
   TpBaseConnection *conn = (TpBaseConnection *) priv->conn;
   TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (conn,
       TP_HANDLE_TYPE_CONTACT);
-  const gchar *from, *body;
+  const gchar *from, *body, *id;
   time_t stamp;
   TpChannelTextMessageType msgtype;
   TpHandle handle;
@@ -225,7 +225,7 @@ im_factory_message_cb (LmMessageHandler *handler,
   TpDeliveryStatus delivery_status;
 
   if (!gabble_message_util_parse_incoming_message (message, &from, &stamp,
-        &msgtype, &body, &state, &send_error, &delivery_status))
+        &msgtype, &id, &body, &state, &send_error, &delivery_status))
     return LM_HANDLER_RESULT_REMOVE_MESSAGE;
 
   if (body == NULL && state == -1)
@@ -287,7 +287,7 @@ im_factory_message_cb (LmMessageHandler *handler,
     _gabble_im_channel_state_receive (chan, state);
 
   if (body != NULL)
-    _gabble_im_channel_receive (chan, msgtype, handle, from, stamp, body,
+    _gabble_im_channel_receive (chan, msgtype, handle, from, stamp, id, body,
         send_error, delivery_status);
 
   return LM_HANDLER_RESULT_REMOVE_MESSAGE;
diff --git a/src/message-util.c b/src/message-util.c
index 60cbe47..94ce48b 100644
--- a/src/message-util.c
+++ b/src/message-util.c
@@ -97,6 +97,7 @@ gabble_message_util_send_message (GObject *obj,
   guint type = TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL;
   gboolean result = TRUE;
   const gchar *content_type, *text;
+  gchar *id = NULL;
   guint n_parts;
 
 #define INVALID_ARGUMENT(msg, args...) \
@@ -152,6 +153,10 @@ gabble_message_util_send_message (GObject *obj,
 
   msg = lm_message_new_with_sub_type (recipient, LM_MESSAGE_TYPE_MESSAGE,
       subtype);
+  /* Generate a UUID for the message */
+  id = gabble_generate_id ();
+  lm_message_node_set_attribute (msg->node, "id", id);
+  tp_message_set_string (message, 0, "message-token", id);
 
   if (send_nick)
     lm_message_node_add_own_nick (msg->node, conn);
@@ -176,7 +181,8 @@ gabble_message_util_send_message (GObject *obj,
   if (!result)
     goto despair_island;
 
-  tp_message_mixin_sent (obj, message, flags, "", NULL);
+  tp_message_mixin_sent (obj, message, flags, id, NULL);
+  g_free (id);
 
   return;
 
@@ -184,6 +190,7 @@ despair_island:
   g_assert (error != NULL);
   tp_message_mixin_sent (obj, message, 0, NULL, error);
   g_error_free (error);
+  g_free (id);
 }
 
 
@@ -320,6 +327,7 @@ gabble_message_util_parse_incoming_message (LmMessage *message,
                                             const gchar **from,
                                             time_t *stamp,
                                             TpChannelTextMessageType *msgtype,
+                                            const gchar **id,
                                             const gchar **body_ret,
                                             gint *state,
                                             TpChannelTextSendError *send_error,
@@ -340,6 +348,8 @@ gabble_message_util_parse_incoming_message (LmMessage *message,
       *send_error = _tp_send_error_from_error_node (error_node, delivery_status);
     }
 
+  *id = lm_message_node_get_attribute (message->node, "id");
+
   *from = lm_message_node_get_attribute (message->node, "from");
   if (*from == NULL)
     {
diff --git a/src/message-util.h b/src/message-util.h
index 2421742..3da8406 100644
--- a/src/message-util.h
+++ b/src/message-util.h
@@ -43,8 +43,8 @@ gboolean gabble_message_util_send_chat_state (GObject *obj,
 
 gboolean gabble_message_util_parse_incoming_message (LmMessage *message,
     const gchar **from, time_t *stamp, TpChannelTextMessageType *msgtype,
-    const gchar **body_ret, gint *state, TpChannelTextSendError *send_error,
-    TpDeliveryStatus *delivery_status);
+    const gchar **id, const gchar **body_ret, gint *state,
+    TpChannelTextSendError *send_error, TpDeliveryStatus *delivery_status);
 
 G_END_DECLS
 
diff --git a/src/muc-channel.c b/src/muc-channel.c
index 9ba8177..bb70ca8 100644
--- a/src/muc-channel.c
+++ b/src/muc-channel.c
@@ -2338,6 +2338,7 @@ _gabble_muc_channel_receive (GabbleMucChannel *chan,
                              TpHandleType sender_handle_type,
                              TpHandle sender,
                              time_t timestamp,
+                             const gchar *id,
                              const gchar *text,
                              LmMessage *msg,
                              TpChannelTextSendError send_error,
@@ -2398,12 +2399,17 @@ _gabble_muc_channel_receive (GabbleMucChannel *chan,
   if (timestamp != 0)
     tp_message_set_uint64 (message, 0, "message-sent", timestamp);
 
+  if (id != NULL)
+    tp_message_set_string (message, 0, "message-token", id);
+
   /* Body */
   tp_message_set_string (message, 1, "content-type", "text/plain");
   tp_message_set_string (message, 1, "content", text);
 
   if (is_error || is_echo)
     {
+      gchar *tmp;
+
       /* Error reports and echos of our own messages are represented as
        * delivery reports.
        */
@@ -2412,10 +2418,17 @@ _gabble_muc_channel_receive (GabbleMucChannel *chan,
       TpDeliveryStatus status =
           is_error ? error_status : TP_DELIVERY_STATUS_DELIVERED;
 
+      tmp = gabble_generate_id ();
+      tp_message_set_string (delivery_report, 0, "message-token", tmp);
+      g_free (tmp);
+
       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", status);
 
+      if (id != NULL)
+        tp_message_set_string (delivery_report, 0, "delivery-token", id);
+
       if (is_error)
         tp_message_set_uint32 (delivery_report, 0, "delivery-error",
             send_error);
@@ -2445,6 +2458,14 @@ _gabble_muc_channel_receive (GabbleMucChannel *chan,
       if (timestamp != 0)
         tp_message_set_boolean (message, 0, "scrollback", TRUE);
 
+      if (id == NULL)
+        {
+          gchar *tmp = gabble_generate_id ();
+
+          tp_message_set_string (message, 0, "message-token", tmp);
+          g_free (tmp);
+        }
+
       tp_message_mixin_take_received (G_OBJECT (chan), message);
     }
 }
diff --git a/src/muc-channel.h b/src/muc-channel.h
index ef4c2fd..a8481ec 100644
--- a/src/muc-channel.h
+++ b/src/muc-channel.h
@@ -93,8 +93,9 @@ void _gabble_muc_channel_handle_subject (GabbleMucChannel *chan,
     TpHandle sender, time_t timestamp, const gchar *subject, LmMessage *msg);
 void _gabble_muc_channel_receive (GabbleMucChannel *chan,
     TpChannelTextMessageType msg_type, TpHandleType handle_type,
-    TpHandle sender, time_t timestamp, const gchar *text, LmMessage *msg,
-    TpChannelTextSendError send_error, TpDeliveryStatus delivery_status);
+    TpHandle sender, time_t timestamp, const gchar *id, const gchar *text,
+    LmMessage *msg, TpChannelTextSendError send_error,
+    TpDeliveryStatus delivery_status);
 
 void _gabble_muc_channel_state_receive (GabbleMucChannel *chan,
     guint state, guint from_handle);
diff --git a/src/muc-factory.c b/src/muc-factory.c
index 0caf1ac..47f1144 100644
--- a/src/muc-factory.c
+++ b/src/muc-factory.c
@@ -790,7 +790,7 @@ muc_factory_message_cb (LmMessageHandler *handler,
   TpHandleRepoIface *room_repo = tp_base_connection_get_handles (conn,
       TP_HANDLE_TYPE_ROOM);
 
-  const gchar *from, *body, *subject;
+  const gchar *from, *body, *subject, *id;
   time_t stamp;
   TpChannelTextMessageType msgtype;
   TpHandleRepoIface *handle_source;
@@ -804,7 +804,7 @@ muc_factory_message_cb (LmMessageHandler *handler,
   LmMessageNode *subj_node;
 
   if (!gabble_message_util_parse_incoming_message (message, &from, &stamp,
-        &msgtype, &body, &state, &send_error, &delivery_status))
+        &msgtype, &id, &body, &state, &send_error, &delivery_status))
     return LM_HANDLER_RESULT_REMOVE_MESSAGE;
 
   if (conn_olpc_process_activity_properties_message (priv->conn, message,
@@ -878,7 +878,7 @@ muc_factory_message_cb (LmMessageHandler *handler,
 
   if (body != NULL)
     _gabble_muc_channel_receive (chan, msgtype, handle_type, handle, stamp,
-        body, message, send_error, delivery_status);
+        id, body, message, send_error, delivery_status);
 
   if (send_error == GABBLE_TEXT_CHANNEL_SEND_NO_ERROR)
     {
diff --git a/tests/test-parse-message.c b/tests/test-parse-message.c
index 2ab2943..008babd 100644
--- a/tests/test-parse-message.c
+++ b/tests/test-parse-message.c
@@ -17,15 +17,19 @@ test1 (void)
   TpChannelTextMessageType type;
   TpChannelTextSendError send_error;
   TpDeliveryStatus delivery_status;
+  const gchar *id;
   const gchar *body;
   gint state;
 
   msg = lm_message_build (NULL, LM_MESSAGE_TYPE_MESSAGE,
+        '@', "id", "a867c060-bd3f-4ecc-a38f-3e306af48e4c",
         '@', "from", "foo at bar.com",
         NULL);
   ret = gabble_message_util_parse_incoming_message (
-      msg, &from, &stamp, &type, &body, &state, &send_error, &delivery_status);
+      msg, &from, &stamp, &type, &id, &body, &state, &send_error,
+      &delivery_status);
   g_assert (ret == TRUE);
+  g_assert (0 == strcmp (id, "a867c060-bd3f-4ecc-a38f-3e306af48e4c"));
   g_assert (0 == strcmp (from, "foo at bar.com"));
   g_assert (stamp == 0);
   g_assert (type == TP_CHANNEL_TEXT_MESSAGE_TYPE_NOTICE);
@@ -49,16 +53,20 @@ test2 (void)
   TpChannelTextMessageType type;
   TpChannelTextSendError send_error;
   TpDeliveryStatus delivery_status;
+  const gchar *id;
   const gchar *body;
   gint state;
 
   msg = lm_message_build (NULL, LM_MESSAGE_TYPE_MESSAGE,
         '@', "from", "foo at bar.com",
+        '@', "id", "a867c060-bd3f-4ecc-a38f-3e306af48e4c",
         '(', "body", "hello", ')',
         NULL);
   ret = gabble_message_util_parse_incoming_message (
-      msg, &from, &stamp, &type, &body, &state, &send_error, &delivery_status);
+      msg, &from, &stamp, &type, &id, &body, &state, &send_error,
+      &delivery_status);
   g_assert (ret == TRUE);
+  g_assert (0 == strcmp (id, "a867c060-bd3f-4ecc-a38f-3e306af48e4c"));
   g_assert (0 == strcmp (from, "foo at bar.com"));
   g_assert (stamp == 0);
   g_assert (type == TP_CHANNEL_TEXT_MESSAGE_TYPE_NOTICE);
@@ -80,17 +88,21 @@ test3 (void)
   TpChannelTextMessageType type;
   TpChannelTextSendError send_error;
   TpDeliveryStatus delivery_status;
+  const gchar *id;
   const gchar *body;
   gint state;
 
   msg = lm_message_build (NULL, LM_MESSAGE_TYPE_MESSAGE,
         '@', "from", "foo at bar.com",
+        '@', "id", "a867c060-bd3f-4ecc-a38f-3e306af48e4c",
         '@', "type", "chat",
         '(', "body", "hello", ')',
         NULL);
   ret = gabble_message_util_parse_incoming_message (
-      msg, &from, &stamp, &type, &body, &state, &send_error, &delivery_status);
+      msg, &from, &stamp, &type, &id, &body, &state, &send_error,
+      &delivery_status);
   g_assert (ret == TRUE);
+  g_assert (0 == strcmp (id, "a867c060-bd3f-4ecc-a38f-3e306af48e4c"));
   g_assert (0 == strcmp (from, "foo at bar.com"));
   g_assert (stamp == 0);
   g_assert (type == TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL);
@@ -112,18 +124,22 @@ test_error (void)
   TpChannelTextMessageType type;
   TpChannelTextSendError send_error;
   TpDeliveryStatus delivery_status;
+  const gchar *id;
   const gchar *body;
   gint state;
 
   msg = lm_message_build_with_sub_type (NULL, LM_MESSAGE_TYPE_MESSAGE,
       LM_MESSAGE_SUB_TYPE_ERROR,
       '@', "from", "foo at bar.com",
+      '@', "id", "a867c060-bd3f-4ecc-a38f-3e306af48e4c",
       '@', "type", "error",
       '(', "error", "oops", ')',
       NULL);
   ret = gabble_message_util_parse_incoming_message (
-      msg, &from, &stamp, &type, &body, &state, &send_error, &delivery_status);
+      msg, &from, &stamp, &type, &id, &body, &state, &send_error,
+      &delivery_status);
   g_assert (ret == TRUE);
+  g_assert (0 == strcmp (id, "a867c060-bd3f-4ecc-a38f-3e306af48e4c"));
   g_assert (0 == strcmp (from, "foo at bar.com"));
   g_assert (stamp == 0);
   g_assert (type == TP_CHANNEL_TEXT_MESSAGE_TYPE_NOTICE);
@@ -147,6 +163,7 @@ test_another_error (void)
   TpChannelTextMessageType type;
   TpChannelTextSendError send_error;
   TpDeliveryStatus delivery_status;
+  const gchar *id;
   const gchar *body;
   gint state;
   const gchar *message = "Wherefore art thou, Romeo?";
@@ -154,6 +171,7 @@ test_another_error (void)
   msg = lm_message_build_with_sub_type (NULL, LM_MESSAGE_TYPE_MESSAGE,
       LM_MESSAGE_SUB_TYPE_ERROR,
       '@', "to", "juliet at capulet.com/balcony",
+      '@', "id", "a867c060-bd3f-4ecc-a38f-3e306af48e4c",
       '@', "from", "romeo at montague.net/garden",
       '@', "type", "error",
       '(', "body", message, ')',
@@ -166,8 +184,10 @@ test_another_error (void)
       ')',
       NULL);
   ret = gabble_message_util_parse_incoming_message (
-      msg, &from, &stamp, &type, &body, &state, &send_error, &delivery_status);
+      msg, &from, &stamp, &type, &id, &body, &state, &send_error,
+      &delivery_status);
   g_assert (ret == TRUE);
+  g_assert (0 == strcmp (id, "a867c060-bd3f-4ecc-a38f-3e306af48e4c"));
   g_assert (0 == strcmp (from, "romeo at montague.net/garden"));
   g_assert (stamp == 0);
   g_assert (type == TP_CHANNEL_TEXT_MESSAGE_TYPE_NOTICE);
@@ -192,6 +212,7 @@ test_yet_another_error (void)
   TpChannelTextMessageType type;
   TpChannelTextSendError send_error;
   TpDeliveryStatus delivery_status;
+  const gchar *id;
   const gchar *body;
   gint state;
   const gchar *message = "Its trilling seems to have a tranquilizing effect on "
@@ -200,6 +221,7 @@ test_yet_another_error (void)
   msg = lm_message_build_with_sub_type (NULL, LM_MESSAGE_TYPE_MESSAGE,
       LM_MESSAGE_SUB_TYPE_ERROR,
       '@', "to", "spock at starfleet.us/Enterprise",
+      '@', "id", "a867c060-bd3f-4ecc-a38f-3e306af48e4c",
       '@', "from", "other at starfleet.us/Enterprise",
       '@', "type", "error",
       '(', "body", message, ')',
@@ -212,8 +234,10 @@ test_yet_another_error (void)
       ')',
       NULL);
   ret = gabble_message_util_parse_incoming_message (
-      msg, &from, &stamp, &type, &body, &state, &send_error, &delivery_status);
+      msg, &from, &stamp, &type, &id, &body, &state, &send_error,
+      &delivery_status);
   g_assert (ret == TRUE);
+  g_assert (0 == strcmp (id, "a867c060-bd3f-4ecc-a38f-3e306af48e4c"));
   g_assert (0 == strcmp (from, "other at starfleet.us/Enterprise"));
   g_assert (stamp == 0);
   g_assert (type == TP_CHANNEL_TEXT_MESSAGE_TYPE_NOTICE);
@@ -235,10 +259,12 @@ test_google_offline (void)
   TpChannelTextMessageType type;
   TpChannelTextSendError send_error;
   TpDeliveryStatus delivery_status;
+  const gchar *id;
   const gchar *body;
   gint state;
 
   msg = lm_message_build (NULL, LM_MESSAGE_TYPE_MESSAGE,
+      '@', "id", "a867c060-bd3f-4ecc-a38f-3e306af48e4c",
       '@', "from", "foo at bar.com",
       '(', "body", "hello", ')',
       '(', "x", "",
@@ -251,8 +277,10 @@ test_google_offline (void)
       ')',
       NULL);
   ret = gabble_message_util_parse_incoming_message (
-      msg, &from, &stamp, &type, &body, &state, &send_error, &delivery_status);
+      msg, &from, &stamp, &type, &id, &body, &state, &send_error,
+      &delivery_status);
   g_assert (ret == TRUE);
+  g_assert (0 == strcmp (id, "a867c060-bd3f-4ecc-a38f-3e306af48e4c"));
   g_assert (0 == strcmp (from, "foo at bar.com"));
   g_assert (stamp == 1190899454);
   g_assert (type == TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL);
diff --git a/tests/twisted/muc/send-error.py b/tests/twisted/muc/send-error.py
index e66290b..e8314ab 100644
--- a/tests/twisted/muc/send-error.py
+++ b/tests/twisted/muc/send-error.py
@@ -30,7 +30,7 @@ def test(q, bus, conn, stream):
         }
     ]
 
-    dbus.Interface(text_chan,
+    sent_token = dbus.Interface(text_chan,
         u'org.freedesktop.Telepathy.Channel.Interface.Messages'
         ).SendMessage(greeting, dbus.UInt32(0))
 
@@ -88,9 +88,7 @@ def test(q, bus, conn, stream):
     assert part['message-type'] == 4, part # Message_Type_Delivery_Report
     assert part['delivery-status'] == 3, part # Delivery_Status_Permanently_Failed
     assert part['delivery-error'] == PERMISSION_DENIED, part
-    # 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 part['delivery-token'] == sent_token, part
 
     # Check that the included echo is from us, and matches all the keys in the
     # message we sent.
@@ -98,6 +96,7 @@ def test(q, bus, conn, stream):
     echo = part['delivery-echo']
     assert len(echo) == len(greeting), (echo, greeting)
     assert echo[0]['message-sender'] == test_handle, echo[0]
+    assert echo[0]['message-token'] == sent_token, echo[0]
     for i in range(0, len(echo)):
         for key in greeting[i]:
             assert key in echo[i], (i, key, echo)
diff --git a/tests/twisted/muc/test-muc.py b/tests/twisted/muc/test-muc.py
index f8ebd5b..196a77e 100644
--- a/tests/twisted/muc/test-muc.py
+++ b/tests/twisted/muc/test-muc.py
@@ -124,10 +124,12 @@ def test(q, bus, conn, stream):
         }
     ]
 
-    dbus.Interface(text_chan,
+    sent_token = dbus.Interface(text_chan,
         u'org.freedesktop.Telepathy.Channel.Interface.Messages'
         ).SendMessage(greeting, dbus.UInt32(0))
 
+    assert sent_token
+
     stream_message, sent, message_sent = q.expect_many(
         EventPattern('stream-message'),
         EventPattern('dbus-signal', signal='Sent'),
@@ -145,9 +147,12 @@ def test(q, bus, conn, stream):
     assert sent.args[1] == 1, sent.args # Action
     assert sent.args[2] == u'peers through a gap in the curtains', sent.args
 
+    assert message_sent.args[2] == sent_token
+
     elem = stream_message.stanza
     assert elem.name == 'message'
     assert elem['type'] == 'groupchat', repr(elem)
+    assert elem['id'] == sent_token, repr(elem)
     assert elem['to'] == 'chat at conf.localhost', repr(elem)
     for sub_elem in stream_message.stanza.elements():
         if sub_elem.name == 'body':
@@ -177,9 +182,7 @@ def test(q, bus, conn, stream):
     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 part['delivery-token'] == sent_token, part
     assert 'delivery-error' not in part, part
     assert 'delivery-echo' in part, part
 
@@ -188,6 +191,7 @@ def test(q, bus, conn, stream):
     echo = part['delivery-echo']
     assert len(echo) == len(greeting), (echo, greeting)
     assert echo[0]['message-sender'] == test_handle, echo[0]
+    assert echo[0]['message-token'] == sent_token, echo[0]
     for i in range(0, len(echo)):
         for key in greeting[i]:
             assert key in echo[i], (i, key, echo)
@@ -223,9 +227,12 @@ def test(q, bus, conn, stream):
     assert sent.args[1] == 0, sent.args # Normal
     assert sent.args[2] == u'goodbye', sent.args
 
+    sent_token = message_sent.args[2]
+
     elem = event.stanza
     assert elem.name == 'message'
     assert elem['type'] == 'groupchat'
+    assert elem['id'] == message_sent.args[2]
     body = list(event.stanza.elements())[0]
     assert body.name == 'body'
     assert body.children[0] == u'goodbye'
diff --git a/tests/twisted/text/send-error.py b/tests/twisted/text/send-error.py
index fad520a..a1fc423 100644
--- a/tests/twisted/text/send-error.py
+++ b/tests/twisted/text/send-error.py
@@ -45,6 +45,7 @@ def test_temporary_error(q, bus, conn, stream):
 
     m = domish.Element((None, 'message'))
     m['from'] = 'foo at bar.com'
+    m['id'] = '1845a1a9-f7bc-4a2e-a885-633aadc81e1b'
     m['type'] = 'error'
     m.addElement('body', content=message_body)
 
@@ -82,14 +83,16 @@ def test_temporary_error(q, bus, conn, stream):
     assert header['message-sender'] == foo_handle, header
     assert header['message-type'] == 4, header # Channel_Text_Message_Type_Delivery_Report
     assert header['delivery-status'] == 2, header # Delivery_Status_Temporarily_Failed
-    assert 'delivery-token' not in header, header
+    assert header['delivery-token'] == '1845a1a9-f7bc-4a2e-a885-633aadc81e1b',\
+            header
     assert header['delivery-error'] == expected_send_error, header
 
     delivery_echo = header['delivery-echo']
     assert len(delivery_echo) == 2, delivery_echo
 
     assert delivery_echo[0]['message-sender'] == self_handle, delivery_echo
-    assert 'message-token' not in delivery_echo[0], delivery_echo
+    assert delivery_echo[0]['message-token'] == \
+            '1845a1a9-f7bc-4a2e-a885-633aadc81e1b', delivery_echo
     # FIXME: see above
     #assert delivery_echo[0]['message-type'] == 0, delivery_echo
 
@@ -167,6 +170,8 @@ def test_permanent_error(q, bus, conn, stream):
     assert header['message-sender'] == ninja_handle, header
     assert header['message-type'] == 4, header # Channel_Text_Message_Type_Delivery_Report
     assert header['delivery-status'] == 3, header # Delivery_Status_Permanently_Failed
+    # the error has no ID, therefore its Telepathy rendition has no
+    # delivery-token
     assert 'delivery-token' not in header, header
     assert header['delivery-error'] == expected_send_error, header
 
@@ -174,6 +179,8 @@ def test_permanent_error(q, bus, conn, stream):
     assert len(delivery_echo) == 2, delivery_echo
 
     assert delivery_echo[0]['message-sender'] == self_handle, delivery_echo
+    # the error has no ID, therefore the echo's Telepathy rendition has no
+    # message-token
     assert 'message-token' not in delivery_echo[0], delivery_echo
     # FIXME: see above
     #assert delivery_echo[0]['message-type'] == 0, delivery_echo
diff --git a/tests/twisted/text/test-text.py b/tests/twisted/text/test-text.py
index 0c25499..de1db65 100644
--- a/tests/twisted/text/test-text.py
+++ b/tests/twisted/text/test-text.py
@@ -17,6 +17,7 @@ def test(q, bus, conn, stream):
     # <message type="chat"><body>hello</body</message>
     m = domish.Element((None, 'message'))
     m['from'] = 'foo at bar.com/Pidgin'
+    m['id'] = '1845a1a9-f7bc-4a2e-a885-633aadc81e1b'
     m['type'] = 'chat'
     m.addElement('body', content='hello')
     stream.send(m)
@@ -81,6 +82,7 @@ def test(q, bus, conn, stream):
     # the spec says that message-type "SHOULD be omitted for normal chat
     # messages."
     assert 'message-type' not in header, header
+    assert header['message-token'] == '1845a1a9-f7bc-4a2e-a885-633aadc81e1b'
 
     assert body['content-type'] == 'text/plain', body
     assert body['content'] == 'hello', body
@@ -108,7 +110,7 @@ def test(q, bus, conn, stream):
         }
     ]
 
-    dbus.Interface(text_chan,
+    sent_token = dbus.Interface(text_chan,
         u'org.freedesktop.Telepathy.Channel.Interface.Messages'
         ).SendMessage(greeting, dbus.UInt32(0))
 
@@ -129,10 +131,13 @@ def test(q, bus, conn, stream):
     assert len(sent_message) == 2, sent_message
     header = sent_message[0]
     assert header['message-type'] == 2, header # Notice
+    assert header['message-token'] == sent_token, header
     body = sent_message[1]
     assert body['content-type'] == 'text/plain', body
     assert body['content'] == u'what up', body
 
+    assert message_sent.args[2] == sent_token
+
     assert sent.args[1] == 2, sent.args # Notice
     assert sent.args[2] == u'what up', sent.args
 
-- 
1.5.6.5



More information about the telepathy-commits mailing list