From 722f8367143468b8c282928704fa64e0a9574732 Mon Sep 17 00:00:00 2001 From: Efim Poberezkin <8711996+efim-poberezkin@users.noreply.github.com> Date: Sat, 5 Mar 2022 20:32:29 +0400 Subject: [PATCH] core: sort group messages by timestamp (#400) --- src/Simplex/Chat/Store.hs | 6 +++--- tests/ChatTests.hs | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Simplex/Chat/Store.hs b/src/Simplex/Chat/Store.hs index 909dbaba97..39d09d544a 100644 --- a/src/Simplex/Chat/Store.hs +++ b/src/Simplex/Chat/Store.hs @@ -2509,7 +2509,7 @@ getGroupChatLast_ db user@User {userId, userContactId} groupId count = do LEFT JOIN group_members m ON m.group_member_id = ci.group_member_id LEFT JOIN contact_profiles p ON p.contact_profile_id = m.contact_profile_id WHERE ci.user_id = ? AND ci.group_id = ? - ORDER BY ci.chat_item_id DESC + ORDER BY ci.item_ts DESC, ci.chat_item_id DESC LIMIT ? |] (userId, groupId, count) @@ -2539,7 +2539,7 @@ getGroupChatAfter_ db user@User {userId, userContactId} groupId afterChatItemId LEFT JOIN group_members m ON m.group_member_id = ci.group_member_id LEFT JOIN contact_profiles p ON p.contact_profile_id = m.contact_profile_id WHERE ci.user_id = ? AND ci.group_id = ? AND ci.chat_item_id > ? - ORDER BY ci.chat_item_id ASC + ORDER BY ci.item_ts ASC, ci.chat_item_id ASC LIMIT ? |] (userId, groupId, afterChatItemId, count) @@ -2569,7 +2569,7 @@ getGroupChatBefore_ db user@User {userId, userContactId} groupId beforeChatItemI LEFT JOIN group_members m ON m.group_member_id = ci.group_member_id LEFT JOIN contact_profiles p ON p.contact_profile_id = m.contact_profile_id WHERE ci.user_id = ? AND ci.group_id = ? AND ci.chat_item_id < ? - ORDER BY ci.chat_item_id DESC + ORDER BY ci.item_ts DESC, ci.chat_item_id DESC LIMIT ? |] (userId, groupId, beforeChatItemId, count) diff --git a/tests/ChatTests.hs b/tests/ChatTests.hs index 9e7ecb1404..a90ea50e3b 100644 --- a/tests/ChatTests.hs +++ b/tests/ChatTests.hs @@ -6,6 +6,7 @@ module ChatTests where import ChatClient +import Control.Concurrent (threadDelay) import Control.Concurrent.Async (concurrently_) import Control.Concurrent.STM import qualified Data.ByteString as B @@ -157,10 +158,12 @@ testGroup = concurrently_ (bob <# "#team alice> hello") (cath <# "#team alice> hello") + threadDelay 1000000 -- server assigns timestamps with one second precision bob #> "#team hi there" concurrently_ (alice <# "#team bob> hi there") (cath <# "#team bob> hi there") + threadDelay 1000000 cath #> "#team hey team" concurrently_ (alice <# "#team cath> hey team")