From e70cc80e58b9cac96fb31525d5c4664015a621bf Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:37:44 +0400 Subject: [PATCH] fix disappearing messages --- src/Simplex/Chat.hs | 15 ++++++++------- tests/ChatClient.hs | 4 ++-- tests/ChatTests/Groups.hs | 5 +++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index 5ed695a6d1..53928e65fb 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -3730,7 +3730,7 @@ processAgentMessageConn user@User {userId} corrId agentConnId agentMessage = do (m', conn', msg@RcvMessage {chatMsgEvent = ACME _ event}) <- saveGroupRcvMsg user groupId m conn msgMeta cmdId msgBody chatMsg updateChatLock "groupMessage" event case event of - XMsgNew mc -> memberCanSend m' $ newGroupContentMessage gInfo m' mc msg brokerTs + XMsgNew mc -> memberCanSend m' $ newGroupContentMessage gInfo m' mc msg brokerTs False XMsgFileDescr sharedMsgId fileDescr -> memberCanSend m' $ groupMessageFileDescription gInfo m' sharedMsgId fileDescr XMsgUpdate sharedMsgId mContent ttl live -> memberCanSend m' $ groupMessageUpdate gInfo m' sharedMsgId mContent msg brokerTs ttl live XMsgDel sharedMsgId memberId -> groupMessageDelete gInfo m' sharedMsgId memberId msg brokerTs @@ -4371,14 +4371,15 @@ processAgentMessageConn user@User {userId} corrId agentConnId agentMessage = do ChatErrorStore (SEChatItemSharedMsgIdNotFound sharedMsgId) -> handle sharedMsgId e -> throwError e - newGroupContentMessage :: GroupInfo -> GroupMember -> MsgContainer -> RcvMessage -> UTCTime -> m () - newGroupContentMessage gInfo m@GroupMember {memberId, memberRole} mc msg@RcvMessage {sharedMsgId_} brokerTs + newGroupContentMessage :: GroupInfo -> GroupMember -> MsgContainer -> RcvMessage -> UTCTime -> Bool -> m () + newGroupContentMessage gInfo m@GroupMember {memberId, memberRole} mc msg@RcvMessage {sharedMsgId_} brokerTs forwarded | isVoice content && not (groupFeatureAllowed SGFVoice gInfo) = rejected GFVoice | not (isVoice content) && isJust fInv_ && not (groupFeatureAllowed SGFFiles gInfo) = rejected GFFiles | otherwise = do - -- TODO integrity message check - -- check if message moderation event was received ahead of message - let timed_ = rcvGroupCITimed gInfo itemTTL + let timed_ = + if forwarded + then rcvCITimed_ (Just Nothing) itemTTL + else rcvGroupCITimed gInfo itemTTL live = fromMaybe False live_ withStore' (\db -> getCIModeration db user gInfo memberId sharedMsgId_) >>= \case Just ciModeration -> do @@ -5304,7 +5305,7 @@ processAgentMessageConn user@User {userId} corrId agentConnId agentMessage = do let body = LB.toStrict $ J.encode msg rcvMsg@RcvMessage {chatMsgEvent = ACME _ event} <- saveGroupFwdRcvMsg user groupId m author body chatMsg case event of - XMsgNew mc -> memberCanSend author $ newGroupContentMessage gInfo author mc rcvMsg msgTs + XMsgNew mc -> memberCanSend author $ newGroupContentMessage gInfo author mc rcvMsg msgTs True XMsgFileDescr sharedMsgId fileDescr -> memberCanSend author $ groupMessageFileDescription gInfo author sharedMsgId fileDescr XMsgUpdate sharedMsgId mContent ttl live -> memberCanSend author $ groupMessageUpdate gInfo author sharedMsgId mContent rcvMsg msgTs ttl live XMsgDel sharedMsgId memId -> groupMessageDelete gInfo author sharedMsgId memId rcvMsg msgTs diff --git a/tests/ChatClient.hs b/tests/ChatClient.hs index 7721c4db37..c32d8002b9 100644 --- a/tests/ChatClient.hs +++ b/tests/ChatClient.hs @@ -276,8 +276,8 @@ getTermLine cc = 5000000 `timeout` atomically (readTQueue $ termQ cc) >>= \case Just s -> do -- remove condition to always echo virtual terminal - when True $ do - -- when (printOutput cc) $ do + -- when True $ do + when (printOutput cc) $ do name <- userName cc putStrLn $ name <> ": " <> s pure s diff --git a/tests/ChatTests/Groups.hs b/tests/ChatTests/Groups.hs index 67b1dce7b6..73863d68db 100644 --- a/tests/ChatTests/Groups.hs +++ b/tests/ChatTests/Groups.hs @@ -125,7 +125,7 @@ chatGroupTests = do it "cancelled files without text are excluded" testGroupHistoryFileCancelNoText it "quoted messages" testGroupHistoryQuotes it "deleted message is not included" testGroupHistoryDeletedMessage - xit "disappearing message is sent as disappearing" testGroupHistoryDisappearingMessage + it "disappearing message is sent as disappearing" testGroupHistoryDisappearingMessage where _0 = supportedChatVRange -- don't create direct connections _1 = groupCreateDirectVRange @@ -4658,6 +4658,7 @@ testGroupHistoryDisappearingMessage = threadDelay 1000000 + -- 3 seconds so that messages 2 and 3 are not deleted for alice before sending history to cath alice ##> "/set disappear #team on 3" alice <## "updated group preferences:" alice <## "Disappearing messages: on (3 sec)" @@ -4722,5 +4723,5 @@ testGroupHistoryDisappearingMessage = cath ##> "/_get chat #1 count=100" r2 <- chat <$> getTermLine cath r2 `shouldContain` [(0, "1"), (0, "4")] + r2 `shouldNotContain` [(0, "2")] r2 `shouldNotContain` [(0, "3")] - r2 `shouldNotContain` [(0, "4")]