mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-27 22:34:51 +00:00
core, ui: correct member attention stat for support chat on opening it; mark support chat read (#6240)
This commit is contained in:
+106
-3
@@ -18,6 +18,7 @@ import Control.Concurrent.Async (concurrently_)
|
||||
import Control.Monad (forM_, void, when)
|
||||
import Data.Bifunctor (second)
|
||||
import qualified Data.ByteString.Char8 as B
|
||||
import Data.Int (Int64)
|
||||
import Data.List (intercalate, isInfixOf)
|
||||
import qualified Data.Map.Strict as M
|
||||
import qualified Data.Text as T
|
||||
@@ -219,6 +220,7 @@ chatGroupTests = do
|
||||
it "should send messages to admins and members" testSupportCLISendCommand
|
||||
it "should correctly maintain unread stats for support chats on reading chat items" testScopedSupportUnreadStatsOnRead
|
||||
it "should correctly maintain unread stats for support chats on deleting chat items" testScopedSupportUnreadStatsOnDelete
|
||||
it "should correct member attention stat for support chat on opening it" testScopedSupportUnreadStatsCorrectOnOpen
|
||||
|
||||
testGroupCheckMessages :: HasCallStack => TestParams -> IO ()
|
||||
testGroupCheckMessages =
|
||||
@@ -7432,8 +7434,10 @@ testScopedSupportManyModerators =
|
||||
cath #$> ("/_get chat #1(_support:3) count=100", chat, [])
|
||||
|
||||
alice ##> "/member support chats #team"
|
||||
alice <## "members require attention: 0"
|
||||
alice <## "bob (Bob) (id 2): unread: 0, require attention: 0, mentions: 0"
|
||||
dan ##> "/member support chats #team"
|
||||
dan <## "members require attention: 0"
|
||||
dan <## "bob (Bob) (id 3): unread: 0, require attention: 0, mentions: 0"
|
||||
bob ##> "/member support chats #team"
|
||||
bob <## "support: unread: 0, require attention: 0, mentions: 0"
|
||||
@@ -7888,8 +7892,10 @@ testScopedSupportUnreadStatsOnRead =
|
||||
dan <# "#team (support: bob) alice> 3"
|
||||
|
||||
alice ##> "/member support chats #team"
|
||||
alice <## "members require attention: 0"
|
||||
alice <## "bob (Bob) (id 2): unread: 0, require attention: 0, mentions: 0"
|
||||
dan ##> "/member support chats #team"
|
||||
dan <## "members require attention: 0"
|
||||
dan <## "bob (Bob) (id 3): unread: 1, require attention: 0, mentions: 0"
|
||||
bob ##> "/member support chats #team"
|
||||
bob <## "support: unread: 1, require attention: 0, mentions: 0"
|
||||
@@ -7899,8 +7905,10 @@ testScopedSupportUnreadStatsOnRead =
|
||||
[alice, dan] *<# "#team (support: bob) bob> 4"
|
||||
|
||||
alice ##> "/member support chats #team"
|
||||
alice <## "members require attention: 1"
|
||||
alice <## "bob (Bob) (id 2): unread: 1, require attention: 1, mentions: 0"
|
||||
dan ##> "/member support chats #team"
|
||||
dan <## "members require attention: 1"
|
||||
dan <## "bob (Bob) (id 3): unread: 2, require attention: 1, mentions: 0"
|
||||
bob ##> "/member support chats #team"
|
||||
bob <## "support: unread: 1, require attention: 0, mentions: 0"
|
||||
@@ -7913,9 +7921,11 @@ testScopedSupportUnreadStatsOnRead =
|
||||
bob <# "#team (support) dan> 5"
|
||||
|
||||
alice ##> "/member support chats #team"
|
||||
alice <## "members require attention: 0"
|
||||
alice <## "bob (Bob) (id 2): unread: 2, require attention: 0, mentions: 0"
|
||||
-- In test "answering" doesn't reset unanswered, but in UI items would be marked read on opening chat
|
||||
dan ##> "/member support chats #team"
|
||||
dan <## "members require attention: 1"
|
||||
dan <## "bob (Bob) (id 3): unread: 2, require attention: 1, mentions: 0"
|
||||
bob ##> "/member support chats #team"
|
||||
bob <## "support: unread: 2, require attention: 0, mentions: 0"
|
||||
@@ -7928,8 +7938,10 @@ testScopedSupportUnreadStatsOnRead =
|
||||
bob <# "#team (support) dan> @alice 6"
|
||||
|
||||
alice ##> "/member support chats #team"
|
||||
alice <## "members require attention: 1"
|
||||
alice <## "bob (Bob) (id 2): unread: 3, require attention: 0, mentions: 1"
|
||||
dan ##> "/member support chats #team"
|
||||
dan <## "members require attention: 1"
|
||||
dan <## "bob (Bob) (id 3): unread: 2, require attention: 1, mentions: 0"
|
||||
bob ##> "/member support chats #team"
|
||||
bob <## "support: unread: 3, require attention: 0, mentions: 0"
|
||||
@@ -7944,8 +7956,10 @@ testScopedSupportUnreadStatsOnRead =
|
||||
dan <# "#team (support: bob) bob> @alice 7"
|
||||
|
||||
alice ##> "/member support chats #team"
|
||||
alice <## "members require attention: 1"
|
||||
alice <## "bob (Bob) (id 2): unread: 4, require attention: 1, mentions: 2"
|
||||
dan ##> "/member support chats #team"
|
||||
dan <## "members require attention: 1"
|
||||
dan <## "bob (Bob) (id 3): unread: 3, require attention: 2, mentions: 0"
|
||||
bob ##> "/member support chats #team"
|
||||
bob <## "support: unread: 3, require attention: 0, mentions: 0"
|
||||
@@ -7958,8 +7972,10 @@ testScopedSupportUnreadStatsOnRead =
|
||||
dan <# "#team (support: bob) bob!> @dan 8"
|
||||
|
||||
alice ##> "/member support chats #team"
|
||||
alice <## "members require attention: 1"
|
||||
alice <## "bob (Bob) (id 2): unread: 5, require attention: 2, mentions: 2"
|
||||
dan ##> "/member support chats #team"
|
||||
dan <## "members require attention: 1"
|
||||
dan <## "bob (Bob) (id 3): unread: 4, require attention: 3, mentions: 1"
|
||||
bob ##> "/member support chats #team"
|
||||
bob <## "support: unread: 3, require attention: 0, mentions: 0"
|
||||
@@ -7967,11 +7983,13 @@ testScopedSupportUnreadStatsOnRead =
|
||||
alice #$> ("/_read chat items #1(_support:2) " <> aliceMentionedByDanItemId, id, "items read for chat")
|
||||
|
||||
alice ##> "/member support chats #team"
|
||||
alice <## "members require attention: 1"
|
||||
alice <## "bob (Bob) (id 2): unread: 4, require attention: 2, mentions: 1"
|
||||
|
||||
alice #$> ("/_read chat items #1(_support:2) " <> aliceMentionedByBobItemId, id, "items read for chat")
|
||||
|
||||
alice ##> "/member support chats #team"
|
||||
alice <## "members require attention: 1"
|
||||
alice <## "bob (Bob) (id 2): unread: 3, require attention: 1, mentions: 0"
|
||||
|
||||
threadDelay 1000000
|
||||
@@ -7982,23 +8000,30 @@ testScopedSupportUnreadStatsOnRead =
|
||||
bob <# "#team (support) dan!> @bob 9"
|
||||
|
||||
alice ##> "/member support chats #team"
|
||||
alice <## "members require attention: 0"
|
||||
alice <## "bob (Bob) (id 2): unread: 4, require attention: 0, mentions: 0"
|
||||
dan ##> "/member support chats #team"
|
||||
dan <## "members require attention: 1"
|
||||
dan <## "bob (Bob) (id 3): unread: 4, require attention: 3, mentions: 1"
|
||||
bob ##> "/member support chats #team"
|
||||
bob <## "support: unread: 4, require attention: 0, mentions: 1"
|
||||
|
||||
alice #$> ("/_read chat #1(_support:2)", id, "ok")
|
||||
alice ##> "/_read chat #1(_support:2)"
|
||||
alice <## "#team: bob support chat read"
|
||||
|
||||
alice ##> "/member support chats #team"
|
||||
alice <## "members require attention: 0"
|
||||
alice <## "bob (Bob) (id 2): unread: 0, require attention: 0, mentions: 0"
|
||||
|
||||
dan #$> ("/_read chat #1(_support:3)", id, "ok")
|
||||
dan ##> "/_read chat #1(_support:3)"
|
||||
dan <## "#team: bob support chat read"
|
||||
|
||||
dan ##> "/member support chats #team"
|
||||
dan <## "members require attention: 0"
|
||||
dan <## "bob (Bob) (id 3): unread: 0, require attention: 0, mentions: 0"
|
||||
|
||||
bob #$> ("/_read chat #1(_support)", id, "ok")
|
||||
bob ##> "/_read chat #1(_support)"
|
||||
bob <## "#team: support chat read"
|
||||
|
||||
bob ##> "/member support chats #team"
|
||||
bob <## "support: unread: 0, require attention: 0, mentions: 0"
|
||||
@@ -8029,12 +8054,90 @@ testScopedSupportUnreadStatsOnDelete =
|
||||
msgIdBob <- lastItemId bob
|
||||
|
||||
alice ##> "/member support chats #team"
|
||||
alice <## "members require attention: 1"
|
||||
alice <## "bob (Bob) (id 2): unread: 1, require attention: 1, mentions: 0"
|
||||
|
||||
bob #$> ("/_delete item #1(_support) " <> msgIdBob <> " broadcast", id, "message deleted")
|
||||
alice <# "#team (support: bob) bob> [deleted] 1"
|
||||
|
||||
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
|
||||
{ markRead = False
|
||||
}
|
||||
|
||||
testScopedSupportUnreadStatsCorrectOnOpen :: HasCallStack => TestParams -> IO ()
|
||||
testScopedSupportUnreadStatsCorrectOnOpen =
|
||||
testChatOpts2 opts aliceProfile bobProfile $ \alice bob -> do
|
||||
createGroup2 "team" alice bob
|
||||
|
||||
bob #> "#team (support) 1"
|
||||
alice <# "#team (support: bob) bob> 1"
|
||||
|
||||
bob #> "#team (support) 2"
|
||||
alice <# "#team (support: bob) bob> 2"
|
||||
|
||||
alice ##> "/member support chats #team"
|
||||
alice <## "members require attention: 1"
|
||||
alice <## "bob (Bob) (id 2): unread: 2, require attention: 2, mentions: 0"
|
||||
|
||||
alice ##> "/_read chat #1(_support:2)"
|
||||
alice <## "#team: bob support chat read"
|
||||
|
||||
alice ##> "/member support chats #team"
|
||||
alice <## "members require attention: 0"
|
||||
alice <## "bob (Bob) (id 2): unread: 0, require attention: 0, mentions: 0"
|
||||
|
||||
bob #> "#team (support) 3"
|
||||
alice <# "#team (support: bob) bob> 3"
|
||||
|
||||
bob #> "#team (support) 4"
|
||||
alice <# "#team (support: bob) bob> 4"
|
||||
|
||||
bob #> "#team (support) 5"
|
||||
alice <# "#team (support: bob) bob> 5"
|
||||
|
||||
alice ##> "/member support chats #team"
|
||||
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))
|
||||
|
||||
alice ##> "/member support chats #team"
|
||||
alice <## "members require attention: 1"
|
||||
alice <## "bob (Bob) (id 2): unread: 3, 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: 1"
|
||||
alice <## "bob (Bob) (id 2): unread: 3, require attention: 3, mentions: 0"
|
||||
|
||||
alice ##> "/_read chat #1(_support:2)"
|
||||
alice <## "#team: bob support chat read"
|
||||
|
||||
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 =
|
||||
|
||||
Reference in New Issue
Block a user