diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2024-07-16 21:18:59 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2024-07-16 21:29:51 +0200 |
commit | 710e6121a755959dbf423aa828bd3cc7af4214a2 (patch) | |
tree | 9c619066c5c7f2ea61beb69de7a738b16e5bc744 /src/Erebos/Chatroom.hs | |
parent | 35066bdbd2475b632dfb3d824a297cbbaa7b1aa3 (diff) |
Handle parallel thread diff in chatrooms
Diffstat (limited to 'src/Erebos/Chatroom.hs')
-rw-r--r-- | src/Erebos/Chatroom.hs | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/Erebos/Chatroom.hs b/src/Erebos/Chatroom.hs index b2432c5..ae373b6 100644 --- a/src/Erebos/Chatroom.hs +++ b/src/Erebos/Chatroom.hs @@ -161,8 +161,8 @@ instance Storable ChatMessageData where mdLeave <- isJust <$> loadMbEmpty "leave" return ChatMessageData {..} -threadToList :: [Stored (Signed ChatMessageData)] -> [ChatMessage] -threadToList thread = helper S.empty $ thread +threadToListSince :: [ Stored (Signed ChatMessageData) ] -> [ Stored (Signed ChatMessageData) ] -> [ ChatMessage ] +threadToListSince since thread = helper (S.fromList since) thread where helper :: S.Set (Stored (Signed ChatMessageData)) -> [Stored (Signed ChatMessageData)] -> [ChatMessage] helper seen msgs @@ -244,7 +244,7 @@ instance Mergeable ChatroomState where ChatroomStateData {..} | null rsdMessages -> Nothing | otherwise -> Just rsdMessages roomStateSubscribe = fromMaybe False $ findPropertyFirst rsdSubscribe roomStateData - roomStateMessages = threadToList $ concatMap (rsdMessages . fromStored) roomStateData + roomStateMessages = threadToListSince [] $ concatMap (rsdMessages . fromStored) roomStateData in ChatroomState {..} toComponents = roomStateData @@ -342,10 +342,7 @@ chatroomSetSubscribe lookupData subscribe = void $ findAndUpdateChatroomState $ } getMessagesSinceState :: ChatroomState -> ChatroomState -> [ChatMessage] -getMessagesSinceState cur old = takeWhile notOld (roomStateMessages cur) - where - notOld msg = cmsgData msg `notElem` roomStateMessageData old - -- TODO: parallel message threads +getMessagesSinceState cur old = threadToListSince (roomStateMessageData old) (roomStateMessageData cur) data ChatroomSetChange = AddedChatroom ChatroomState |