From 83b90bf1effdb5c4830f1e71903a7d807d1959b2 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Thu, 4 Sep 2025 18:15:51 +0400 Subject: [PATCH] core: mark support chat read --- src/Simplex/Chat/Library/Commands.hs | 2 +- src/Simplex/Chat/Store/Messages.hs | 60 +++++++++++++++++++--------- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/Simplex/Chat/Library/Commands.hs b/src/Simplex/Chat/Library/Commands.hs index 25577841b6..a18056362f 100644 --- a/src/Simplex/Chat/Library/Commands.hs +++ b/src/Simplex/Chat/Library/Commands.hs @@ -1043,7 +1043,7 @@ processChatCommand vr nm = \case pure (user, gInfo) ts <- liftIO getCurrentTime timedItems <- withFastStore' $ \db -> do - timedItems <- getGroupUnreadTimedItems db user chatId + timedItems <- getGroupUnreadTimedItems db user chatId scope updateGroupChatItemsRead db user gInfo scope setGroupChatItemsDeleteAt db user chatId timedItems ts forM_ timedItems $ \(itemId, deleteAt) -> startProximateTimedItemThread user (chatRef, itemId) deleteAt diff --git a/src/Simplex/Chat/Store/Messages.hs b/src/Simplex/Chat/Store/Messages.hs index a06f2c3a12..b645a57988 100644 --- a/src/Simplex/Chat/Store/Messages.hs +++ b/src/Simplex/Chat/Store/Messages.hs @@ -2021,16 +2021,26 @@ setDirectChatItemsDeleteAt db User {userId} contactId itemIds currentTs = forM i updateGroupChatItemsRead :: DB.Connection -> User -> GroupInfo -> Maybe GroupChatScope -> IO () updateGroupChatItemsRead db User {userId} GroupInfo {groupId, membership} scope = do currentTs <- getCurrentTime - DB.execute - db - [sql| - UPDATE chat_items SET item_status = ?, updated_at = ? - WHERE user_id = ? AND group_id = ? AND item_status = ? - |] - (CISRcvRead, currentTs, userId, groupId, CISRcvNew) case scope of - Nothing -> pure () + Nothing -> + DB.execute + db + [sql| + UPDATE chat_items SET item_status = ?, updated_at = ? + WHERE user_id = ? AND group_id = ? + AND item_status = ? + |] + (CISRcvRead, currentTs, userId, groupId, CISRcvNew) Just GCSMemberSupport {groupMemberId_} -> do + DB.execute + db + [sql| + UPDATE chat_items SET item_status = ?, updated_at = ? + WHERE user_id = ? AND group_id = ? + AND group_scope_tag = ? AND group_scope_group_member_id IS NOT DISTINCT FROM ? + AND item_status = ? + |] + (CISRcvRead, currentTs, userId, groupId, GCSTMemberSupport_, groupMemberId_, CISRcvNew) let gmId = fromMaybe (groupMemberId' membership) groupMemberId_ DB.execute db @@ -2043,16 +2053,30 @@ updateGroupChatItemsRead db User {userId} GroupInfo {groupId, membership} scope |] (Only gmId) -getGroupUnreadTimedItems :: DB.Connection -> User -> GroupId -> IO [(ChatItemId, Int)] -getGroupUnreadTimedItems db User {userId} groupId = - DB.query - db - [sql| - SELECT chat_item_id, timed_ttl - FROM chat_items - WHERE user_id = ? AND group_id = ? AND item_status = ? AND timed_ttl IS NOT NULL AND timed_delete_at IS NULL - |] - (userId, groupId, CISRcvNew) +getGroupUnreadTimedItems :: DB.Connection -> User -> GroupId -> Maybe GroupChatScope -> IO [(ChatItemId, Int)] +getGroupUnreadTimedItems db User {userId} groupId scope = + case scope of + Nothing -> + DB.query + db + [sql| + SELECT chat_item_id, timed_ttl + FROM chat_items + WHERE user_id = ? AND group_id = ? + AND item_status = ? AND timed_ttl IS NOT NULL AND timed_delete_at IS NULL + |] + (userId, groupId, CISRcvNew) + Just GCSMemberSupport {groupMemberId_} -> + DB.query + db + [sql| + SELECT chat_item_id, timed_ttl + FROM chat_items + WHERE user_id = ? AND group_id = ? + AND group_scope_tag = ? AND group_scope_group_member_id IS NOT DISTINCT FROM ? + AND item_status = ? AND timed_ttl IS NOT NULL AND timed_delete_at IS NULL + |] + (userId, groupId, GCSTMemberSupport_, groupMemberId_, CISRcvNew) updateGroupChatItemsReadList :: DB.Connection -> VersionRangeChat -> User -> GroupInfo -> Maybe GroupChatScopeInfo -> NonEmpty ChatItemId -> ExceptT StoreError IO ([(ChatItemId, Int)], GroupInfo) updateGroupChatItemsReadList db vr user@User {userId} g@GroupInfo {groupId} scopeInfo_ itemIds = do