diff options
author | fiaxh <git@lightrise.org> | 2019-12-19 15:27:08 +0100 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2019-12-19 15:27:08 +0100 |
commit | 2938c685a2ad5c20eeeb6a27fee47581df2a4a2a (patch) | |
tree | 031a06ab609a938c79845ce31b5c29a07ab7ae07 /libdino/src | |
parent | 013786a120fb5f0845eae6426184d1c506d8107b (diff) | |
download | dino-2938c685a2ad5c20eeeb6a27fee47581df2a4a2a.tar.gz dino-2938c685a2ad5c20eeeb6a27fee47581df2a4a2a.zip |
Trim ms from local_time when creating messages
Mss are striped when storing in db. Comparing messages with and without ms might lead to wrong orderings. Related: Message duplication in UI when scrolling up.
Diffstat (limited to 'libdino/src')
-rw-r--r-- | libdino/src/service/message_processor.vala | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala index 98239eb8..fd575bf5 100644 --- a/libdino/src/service/message_processor.vala +++ b/libdino/src/service/message_processor.vala @@ -338,7 +338,8 @@ public class MessageProcessor : StreamInteractionModule, Object { } if (mam_message_flag != null) new_message.local_time = mam_message_flag.server_time; - if (new_message.local_time == null || new_message.local_time.compare(new DateTime.now_utc()) > 0) new_message.local_time = new DateTime.now_utc(); + DateTime now = new DateTime.from_unix_utc(new DateTime.now_utc().to_unix()); // Remove milliseconds. They are not stored in the db and might lead to ordering issues when compared with times from the db. + if (new_message.local_time == null || new_message.local_time.compare(now) > 0) new_message.local_time = now; Xep.DelayedDelivery.MessageFlag? delayed_message_flag = Xep.DelayedDelivery.MessageFlag.get_flag(message); if (delayed_message_flag != null) new_message.time = delayed_message_flag.datetime; @@ -525,8 +526,9 @@ public class MessageProcessor : StreamInteractionModule, Object { message.stanza_id = random_uuid(); message.account = conversation.account; message.body = text; - message.time = new DateTime.now_utc(); - message.local_time = new DateTime.now_utc(); + DateTime now = new DateTime.from_unix_utc(new DateTime.now_utc().to_unix()); // Remove milliseconds. They are not stored in the db and might lead to ordering issues when compared with times from the db. + message.time = now; + message.local_time = now; message.direction = Entities.Message.DIRECTION_SENT; message.counterpart = conversation.counterpart; if (conversation.type_ in new Conversation.Type[]{Conversation.Type.GROUPCHAT, Conversation.Type.GROUPCHAT_PM}) { |