core: sort group messages by timestamp (#400)

This commit is contained in:
Efim Poberezkin
2022-03-05 20:32:29 +04:00
committed by GitHub
parent 33f731e247
commit 722f836714
2 changed files with 6 additions and 3 deletions

View File

@@ -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)

View File

@@ -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")