fix: do not sort received messages below the last seen one#8031
fix: do not sort received messages below the last seen one#8031
Conversation
61fde0e to
eb93663
Compare
d3e5b60 to
58aafef
Compare
| OutBroadcast#Chat#1001: Channel [0 member(s)] | ||
| -------------------------------------------------------------------------------- | ||
| Msg#1001: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO] | ||
| Msg#1006🔒: Me (Contact#Contact#Self): Member bob@example.net added. [INFO] √ |
There was a problem hiding this comment.
There is some reordering of Alice's own messages in chat::chat_tests::test_sync_broadcast_and_send_message which results in one device showing as if Alice has sent a message to own channel before adding Bob while in fact it was after Alice added Bob. This seems to work as expected, if Alice backdates some message in the channel then it is not possible for the second device to know that it was not actually sent before Bob was added.
Essentially the problem boils down to "smeared timestamps" that cause these problems to golden tests that are not real problems. In practice devices may simply have slightly desynchronized clocks. Maybe we should not add too many golden tests as they are much easier to write than tell whether the breakage is important or not when they break.
|
Two things still needed:
|
It is not clear now what this is testing. Golden test shows messages ordered incorrectly according to the timestamps, they should be ordered the other way round. Comment talks about fetching from mvbox and inbox in paralell which is a rare case that could have happened if one message is left in the inbox and the other message is a chat message moved to mvbox. We never download anything that is not moved to the target folder. The test also resides in "verified chats" tests which are all legacy tests we kept after replacing the concept of verified/protected chats with key contacts in 2.x.
We know which message was added from the return value of receive_imf(). It may be that the first chat in the chatlist is not the one where the message was received if there is a pinned chat or if just received message is old.
…ginning We set timestamp of this info message to 0 to make it always appear in the beginning of the chat. To avoid new chats being sorted to the end of the chatlist, we ignore such 0 and use chat creation timestamp when sorting the chatlist.
f5f626f to
f2f532f
Compare
This is to avoid sorting incoming messages that are slightly in the past above system messages about SecureJoin. SecureJoin messages are timed according to smeared timestamp, so even in the local tests they are in the future by a few seconds.
95a347e to
3671857
Compare
iequidoo
left a comment
There was a problem hiding this comment.
Do other messengers, when a chat is open, insert new delayed messages not at the bottom, but somewhere, maybe even outside the screen?
Have you considered an approach that changes the current behavior less (particularly, for a chat being open): when an MDN for an InFresh message is received, recalculate its sort timestamp as if received was false?
| received: bool, | ||
| incoming: bool, | ||
| ) -> Result<i64> { | ||
| let mut sort_timestamp = cmp::min(message_timestamp, smeared_time(context)); |
There was a problem hiding this comment.
So messages may still be ordered differently on devices if some chat members have clocks in the future and devices e.g. come online at different time.
There was a problem hiding this comment.
Yes, this prevents the message from someone with such clock set into the future from sticking at the end of the chat, even after outgoing messages.
There was a problem hiding this comment.
Yes, this ceiling is good, i just want to say that receiver-side reordering (and different order on user's devices) still may happen if sender's clock is in the future.
Also, sender- or server-side reordering could happen even before multi-relay, e.g. for messages sent while being offline or using a bad network, but this has never been considered as a problem, instead, messages inserted at the bottom always was a "feature".
We could guarantee the same message order on devices, but then we need to know the minimum "received" smeared time on devices...
Hocuri
left a comment
There was a problem hiding this comment.
Thanks for fixing! Let's hope that this improves things 🤞
Fixes #8030
test: remove test_old_message_5: see commit message, the test seems to check for the incorrect behavior
test: do not rely on loading newest chat in load_imf_email(): change helper function to avoid loading the wrong message if there is already a message with a newer timestamp
test: use load_imf_email() more: some test refactoring, since we have
load_imf_email, can as well use it instead of copypastingfix: always sort "Messages are end-to-end encrypted" notice to the beginning: see commit message, this ensures nothing can be added above this message for new chats (existing chats have non-zero timestamp so you can technically backdate something before "Messages are end-to-end encrypted", but this is not really a problem)
fix: never sort the message before chat joining timestamp: avoid adding "Member added" message before securejoin system messages
fix: do not sort received messages below the last seen one: the last change, see the code and comments in the code. I have reviewed "golden tests" breakage, this is where commits above come from, the rest of the breakage looks expected. I also left one comment myself on one of the tests.
There is a problem with "Messages are end-to-end encrypted." message. It has current timestamp, but incoming message from contact requests is from the past, so contact request chats start with the incoming message followed by "Messages are end-to-end encrypted.". Need to set the timestamp for the info message to the timestamp of incoming message or fix it the other way. (
tests::verified_chats::test_outgoing_encrypted_msg)Another problem is with "Member added" message in
sync::tests::test_unpromoted_group_qr_sync, it did not end up at the end: