diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2010-12-13 14:53:43 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2010-12-13 14:53:46 +0000 |
commit | afef93b9cfed8878a96bb7150d60ceafd02d8ddf (patch) | |
tree | a5f4c5f8c589365de71b2a772fd33f15062f6eaa | |
parent | f1d5bc82b1f779733b8ef49375869e36c2500474 (diff) | |
parent | c639794d12ad21ff7d04c69e49f1a64b383df95f (diff) |
Merge branch 'messages'
Reviewed-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r-- | src/im-channel.c | 29 | ||||
-rw-r--r-- | src/muc-channel.c | 22 | ||||
-rw-r--r-- | tests/twisted/muc/test-muc.py | 2 | ||||
-rw-r--r-- | tests/twisted/text/test-text.py | 9 |
4 files changed, 26 insertions, 36 deletions
diff --git a/src/im-channel.c b/src/im-channel.c index d01e5bf4b..891dcca21 100644 --- a/src/im-channel.c +++ b/src/im-channel.c @@ -378,14 +378,14 @@ _gabble_im_channel_receive (GabbleIMChannel *chan, priv->chat_states_supported = CHAT_STATES_UNKNOWN; } - msg = tp_message_new (base_conn, 2, 2); + msg = tp_cm_message_new (base_conn, 2); /* Header */ if (type != TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL) tp_message_set_uint32 (msg, 0, "message-type", type); if (timestamp != 0) - tp_message_set_uint64 (msg, 0, "message-sent", timestamp); + tp_message_set_int64 (msg, 0, "message-sent", timestamp); /* Body */ tp_message_set_string (msg, 1, "content-type", "text/plain"); @@ -393,28 +393,22 @@ _gabble_im_channel_receive (GabbleIMChannel *chan, if (send_error == GABBLE_TEXT_CHANNEL_SEND_NO_ERROR) { - tp_message_set_handle (msg, 0, "message-sender", TP_HANDLE_TYPE_CONTACT, - sender); - tp_message_set_uint64 (msg, 0, "message-received", time (NULL)); + tp_cm_message_set_sender (msg, sender); + tp_message_set_int64 (msg, 0, "message-received", time (NULL)); - /* We can't trust the id='' attribute set by the contact to be unique - * enough to be a message-token, so let's generate one locally. - */ - tmp = gabble_generate_id (); - tp_message_set_string (msg, 0, "message-token", tmp); - g_free (tmp); + if (id != NULL) + tp_message_set_string (msg, 0, "message-token", id); tp_message_mixin_take_received (G_OBJECT (chan), msg); } else { - TpMessage *delivery_report = tp_message_new (base_conn, 1, 1); + TpMessage *delivery_report = tp_cm_message_new (base_conn, 1); tp_message_set_uint32 (delivery_report, 0, "message-type", TP_CHANNEL_TEXT_MESSAGE_TYPE_DELIVERY_REPORT); - tp_message_set_handle (delivery_report, 0, "message-sender", - TP_HANDLE_TYPE_CONTACT, sender); - tp_message_set_uint64 (delivery_report, 0, "message-received", + tp_cm_message_set_sender (delivery_report, sender); + tp_message_set_int64 (delivery_report, 0, "message-received", time (NULL)); tmp = gabble_generate_id (); @@ -430,14 +424,13 @@ _gabble_im_channel_receive (GabbleIMChannel *chan, /* 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, - base_conn->self_handle); + tp_cm_message_set_sender (msg, base_conn->self_handle); /* Since this is a send error, we can trust the id on the message. */ if (id != NULL) tp_message_set_string (msg, 0, "message-token", id); - tp_message_take_message (delivery_report, 0, "delivery-echo", msg); + tp_cm_message_take_message (delivery_report, 0, "delivery-echo", msg); tp_message_mixin_take_received (G_OBJECT (chan), delivery_report); } diff --git a/src/muc-channel.c b/src/muc-channel.c index 7faac539e..85bd67e9b 100644 --- a/src/muc-channel.c +++ b/src/muc-channel.c @@ -2725,14 +2725,14 @@ _gabble_muc_channel_receive (GabbleMucChannel *chan, return; } - message = tp_message_new (base_conn, 2, 2); + message = tp_cm_message_new (base_conn, 2); /* Header common to normal message and delivery-echo */ if (msg_type != TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL) tp_message_set_uint32 (message, 0, "message-type", msg_type); if (timestamp != 0) - tp_message_set_uint64 (message, 0, "message-sent", timestamp); + tp_message_set_int64 (message, 0, "message-sent", timestamp); /* Body */ tp_message_set_string (message, 1, "content-type", "text/plain"); @@ -2744,7 +2744,7 @@ _gabble_muc_channel_receive (GabbleMucChannel *chan, * delivery reports. */ - TpMessage *delivery_report = tp_message_new (base_conn, 1, 1); + TpMessage *delivery_report = tp_cm_message_new (base_conn, 1); TpDeliveryStatus status = is_error ? error_status : TP_DELIVERY_STATUS_DELIVERED; @@ -2770,15 +2770,14 @@ _gabble_muc_channel_receive (GabbleMucChannel *chan, * The sender of the echo, however, is ourself. (Unless we get errors * for messages that we didn't send, which would be odd.) */ - tp_message_set_handle (message, 0, "message-sender", - TP_HANDLE_TYPE_CONTACT, muc_self_handle); + tp_cm_message_set_sender (message, muc_self_handle); /* If we sent the message whose delivery has succeeded or failed, we * trust the id='' attribute. */ if (id != NULL) tp_message_set_string (message, 0, "message-token", id); - tp_message_take_message (delivery_report, 0, "delivery-echo", + tp_cm_message_take_message (delivery_report, 0, "delivery-echo", message); tp_message_mixin_take_received (G_OBJECT (chan), delivery_report); @@ -2787,18 +2786,13 @@ _gabble_muc_channel_receive (GabbleMucChannel *chan, { /* Messages from the MUC itself should have no sender. */ if (sender_handle_type == TP_HANDLE_TYPE_CONTACT) - tp_message_set_handle (message, 0, "message-sender", - TP_HANDLE_TYPE_CONTACT, sender); + tp_cm_message_set_sender (message, sender); if (timestamp != 0) tp_message_set_boolean (message, 0, "scrollback", TRUE); - /* We can't trust the id='' attribute set by the contact to be unique - * enough to be a message-token, so let's generate one locally. - */ - tmp = gabble_generate_id (); - tp_message_set_string (message, 0, "message-token", tmp); - g_free (tmp); + if (id != NULL) + tp_message_set_string (message, 0, "message-token", id); 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 f47d02739..993c726ae 100644 --- a/tests/twisted/muc/test-muc.py +++ b/tests/twisted/muc/test-muc.py @@ -135,6 +135,8 @@ def test(q, bus, conn, stream): assert len(sent_message) == 2, sent_message header = sent_message[0] assert header['message-type'] == 1, header # Action + assertEquals(test_handle, header['message-sender']) + assertEquals('chat@conf.localhost/test', header['message-sender-id']) body = sent_message[1] assert body['content-type'] == 'text/plain', body assert body['content'] == u'peers through a gap in the curtains', body diff --git a/tests/twisted/text/test-text.py b/tests/twisted/text/test-text.py index 30bb2a915..5d255413c 100644 --- a/tests/twisted/text/test-text.py +++ b/tests/twisted/text/test-text.py @@ -88,10 +88,9 @@ def test(q, bus, conn, stream): # messages." assert 'message-type' not in header or header['message-type'] == 0, header - # This looks wrong, but is correct. We don't know if our contacts generate - # message id='' attributes which are unique enough for our requirements, so - # we should not use them as the message-token for incoming messages. - assertNotEquals(id, header['message-token']) + # We don't make any uniqueness guarantees about the tokens on incoming + # messages, so we use the id='' provided at the protocol level. + assertEquals(id, header['message-token']) assert body['content-type'] == 'text/plain', body assert body['content'] == 'hello', body @@ -137,6 +136,8 @@ def test(q, bus, conn, stream): header = sent_message[0] assert header['message-type'] == 2, header # Notice assert header['message-token'] == sent_token, header + assertEquals(conn.GetSelfHandle(), header['message-sender']) + assertEquals('test@localhost', header['message-sender-id']) body = sent_message[1] assert body['content-type'] == 'text/plain', body assert body['content'] == u'what up', body |