mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-03-31 09:46:03 +00:00
fix group counter on correction
This commit is contained in:
@@ -532,10 +532,9 @@ processChatCommand vr nm = \case
|
||||
GroupChat gInfo (Just GCSIMemberSupport {groupMember_ = Just scopeMem}) -> do
|
||||
case correctedMemAttention scopeMem chatItems of
|
||||
Just newMemAttention -> do
|
||||
scopeMem' <- withFastStore $ \db -> do
|
||||
liftIO $ setSupportChatMemberAttention db (groupMemberId' scopeMem) newMemAttention
|
||||
getGroupMemberById db vr user (groupMemberId' scopeMem)
|
||||
pure $ groupChat {chatInfo = GroupChat gInfo (Just $ GCSIMemberSupport (Just scopeMem'))}
|
||||
(gInfo', scopeMem') <-
|
||||
withFastStore' $ \db -> setSupportChatMemberAttention db vr user gInfo scopeMem newMemAttention
|
||||
pure $ groupChat {chatInfo = GroupChat gInfo' (Just $ GCSIMemberSupport (Just scopeMem'))}
|
||||
Nothing -> pure groupChat
|
||||
_ -> pure groupChat
|
||||
where
|
||||
|
||||
@@ -501,9 +501,20 @@ setSupportChatTs :: DB.Connection -> GroupMemberId -> UTCTime -> IO ()
|
||||
setSupportChatTs db groupMemberId chatTs =
|
||||
DB.execute db "UPDATE group_members SET support_chat_ts = ? WHERE group_member_id = ?" (chatTs, groupMemberId)
|
||||
|
||||
setSupportChatMemberAttention :: DB.Connection -> GroupMemberId -> Int64 -> IO ()
|
||||
setSupportChatMemberAttention db groupMemberId memberAttention =
|
||||
DB.execute db "UPDATE group_members SET support_chat_items_member_attention = ? WHERE group_member_id = ?" (memberAttention, groupMemberId)
|
||||
setSupportChatMemberAttention :: DB.Connection -> VersionRangeChat -> User -> GroupInfo -> GroupMember -> Int64 -> IO (GroupInfo, GroupMember)
|
||||
setSupportChatMemberAttention db vr user g m memberAttention = do
|
||||
m' <- updateGMAttention m
|
||||
g' <- updateGroupMembersRequireAttention db user g m m'
|
||||
pure (g', m')
|
||||
where
|
||||
updateGMAttention m@GroupMember {groupMemberId} = do
|
||||
currentTs <- getCurrentTime
|
||||
DB.execute
|
||||
db
|
||||
"UPDATE group_members SET support_chat_items_member_attention = ?, updated_at = ? WHERE group_member_id = ?"
|
||||
(memberAttention, currentTs, groupMemberId' m)
|
||||
m_ <- runExceptT $ getGroupMemberById db vr user groupMemberId
|
||||
pure $ either (const m) id m_ -- Left shouldn't happen, but types require it
|
||||
|
||||
createNewSndChatItem :: DB.Connection -> User -> ChatDirection c 'MDSnd -> SndMessage -> CIContent 'MDSnd -> Maybe (CIQuote c) -> Maybe CIForwardedFrom -> Maybe CITimed -> Bool -> UTCTime -> IO ChatItemId
|
||||
createNewSndChatItem db user chatDirection SndMessage {msgId, sharedMsgId} ciContent quotedItem itemForwarded timed live createdAt =
|
||||
|
||||
@@ -8104,6 +8104,7 @@ testScopedSupportUnreadStatsCorrectOnOpen =
|
||||
alice <## "members require attention: 1"
|
||||
alice <## "bob (Bob) (id 2): unread: 3, require attention: 3, mentions: 0"
|
||||
|
||||
-- opening chat should correct group_members.support_chat_items_member_attention value if it got out of sync
|
||||
void $ withCCTransaction alice $ \db ->
|
||||
DB.execute db "UPDATE group_members SET support_chat_items_member_attention=100 WHERE group_member_id=?" (Only (2 :: Int64))
|
||||
|
||||
@@ -8123,6 +8124,21 @@ testScopedSupportUnreadStatsCorrectOnOpen =
|
||||
alice ##> "/member support chats #team"
|
||||
alice <## "members require attention: 0"
|
||||
alice <## "bob (Bob) (id 2): unread: 0, require attention: 0, mentions: 0"
|
||||
|
||||
-- opening chat should also correct groups.members_require_attention value if corrected member no longer requires attention
|
||||
void $ withCCTransaction alice $ \db -> do
|
||||
DB.execute db "UPDATE group_members SET support_chat_items_member_attention=100 WHERE group_member_id=?" (Only (2 :: Int64))
|
||||
DB.execute db "UPDATE groups SET members_require_attention=1 WHERE group_id=?" (Only (1 :: Int64))
|
||||
|
||||
alice ##> "/member support chats #team"
|
||||
alice <## "members require attention: 1"
|
||||
alice <## "bob (Bob) (id 2): unread: 0, require attention: 100, mentions: 0"
|
||||
|
||||
alice #$> ("/_get chat #1(_support:2) count=100", chat, [(0, "1"), (0, "2"), (0, "3"), (0, "4"), (0, "5")])
|
||||
|
||||
alice ##> "/member support chats #team"
|
||||
alice <## "members require attention: 0"
|
||||
alice <## "bob (Bob) (id 2): unread: 0, require attention: 0, mentions: 0"
|
||||
where
|
||||
opts =
|
||||
testOpts
|
||||
|
||||
Reference in New Issue
Block a user