mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-26 01:02:24 +00:00
tests
This commit is contained in:
@@ -1585,6 +1585,11 @@ processChatCommand' vr = \case
|
||||
forwardedItemId <- withStore $ \db -> getDirectChatItemIdByText db userId contactId msgDir forwardedMsg
|
||||
toChatRef <- getChatRef user toChatName
|
||||
processChatCommand $ APIForwardChatItem (ChatRef CTDirect contactId) toChatRef forwardedItemId
|
||||
ForwardLocalMessage toChatName forwardedMsg -> withUser $ \user -> do
|
||||
folderId <- withStore (`getUserNoteFolderId` user)
|
||||
forwardedItemId <- withStore $ \db -> getLocalChatItemIdByText' db user folderId forwardedMsg
|
||||
toChatRef <- getChatRef user toChatName
|
||||
processChatCommand $ APIForwardChatItem (ChatRef CTLocal folderId) toChatRef forwardedItemId
|
||||
DeleteMessage chatName deletedMsg -> withUser $ \user -> do
|
||||
chatRef <- getChatRef user chatName
|
||||
deletedItemId <- getSentChatItemIdByText user chatRef deletedMsg
|
||||
@@ -7058,6 +7063,7 @@ chatCommandP =
|
||||
"/live " *> (SendLiveMessage <$> chatNameP <*> (A.space *> msgTextP <|> pure "")),
|
||||
(">@" <|> "> @") *> forwardMsgP (AMsgDirection SMDRcv),
|
||||
(">>@" <|> ">> @") *> forwardMsgP (AMsgDirection SMDSnd),
|
||||
(">* -> " <|> "> * -> ") *> (ForwardLocalMessage <$> chatNameP <* A.space <*> msgTextP),
|
||||
(">@" <|> "> @") *> sendMsgQuote (AMsgDirection SMDRcv),
|
||||
(">>@" <|> ">> @") *> sendMsgQuote (AMsgDirection SMDSnd),
|
||||
("\\ " <|> "\\") *> (DeleteMessage <$> chatNameP <* A.space <*> textP),
|
||||
|
||||
@@ -412,6 +412,7 @@ data ChatCommand
|
||||
| SendLiveMessage ChatName Text
|
||||
| SendMessageQuote {contactName :: ContactName, msgDir :: AMsgDirection, quotedMsg :: Text, message :: Text}
|
||||
| ForwardMessage {contactName :: ContactName, msgDir :: AMsgDirection, toChatName :: ChatName, forwardedMsg :: Text}
|
||||
| ForwardLocalMessage {toChatName :: ChatName, forwardedMsg :: Text}
|
||||
| SendMessageBroadcast Text -- UserId (not used in UI)
|
||||
| DeleteMessage ChatName Text
|
||||
| DeleteMemberMessage GroupName ContactName Text
|
||||
|
||||
@@ -87,6 +87,7 @@ runInputLoop ct@ChatTerminal {termState, liveMessageState} cc = forever $ do
|
||||
Right SendFile {} -> True
|
||||
Right SendMessageQuote {} -> True
|
||||
Right ForwardMessage {} -> True
|
||||
Right ForwardLocalMessage {} -> True
|
||||
Right SendGroupMessageQuote {} -> True
|
||||
Right ForwardGroupMessage {} -> True
|
||||
Right SendMessageBroadcast {} -> True
|
||||
|
||||
@@ -10,10 +10,18 @@ import Test.Hspec hiding (it)
|
||||
chatForwardTests :: SpecWith FilePath
|
||||
chatForwardTests = do
|
||||
describe "forward messages" $ do
|
||||
it "from contact to contact" testForwardContactContact
|
||||
it "from contact to contact" testForwardContactToContact
|
||||
it "from contact to group" testForwardContactToGroup
|
||||
it "from contact to notes" testForwardContactToNotes
|
||||
it "from group to contact" testForwardGroupToContact
|
||||
it "from group to group" testForwardGroupToGroup
|
||||
it "from group to notes" testForwardGroupToNotes
|
||||
it "from notes to contact" testForwardNotesToContact
|
||||
it "from notes to group" testForwardNotesToGroup
|
||||
it "from notes to notes" testForwardNotesToNotes
|
||||
|
||||
testForwardContactContact :: HasCallStack => FilePath -> IO ()
|
||||
testForwardContactContact =
|
||||
testForwardContactToContact :: HasCallStack => FilePath -> IO ()
|
||||
testForwardContactToContact =
|
||||
testChat3 aliceProfile bobProfile cathProfile $
|
||||
\alice bob cath -> do
|
||||
connectUsers alice bob
|
||||
@@ -23,9 +31,8 @@ testForwardContactContact =
|
||||
alice #> "@bob hi"
|
||||
bob <# "alice> hi"
|
||||
msgId <- lastItemId alice
|
||||
|
||||
alice #> "@bob hey"
|
||||
bob <# "alice> hey"
|
||||
bob #> "@alice hey"
|
||||
alice <# "bob> hey"
|
||||
|
||||
alice ##> ("/_forward @2 @3 " <> msgId)
|
||||
alice <# "@cath -> forwarded"
|
||||
@@ -33,8 +40,178 @@ testForwardContactContact =
|
||||
cath <# "alice> -> forwarded"
|
||||
cath <## " hi"
|
||||
|
||||
bob `send` "> @alice -> @cath hey"
|
||||
bob <# "@cath -> forwarded"
|
||||
bob <## " hey"
|
||||
cath <# "bob> -> forwarded"
|
||||
alice `send` "> @bob -> @cath hey"
|
||||
alice <# "@cath -> forwarded"
|
||||
alice <## " hey"
|
||||
cath <# "alice> -> forwarded"
|
||||
cath <## " hey"
|
||||
|
||||
alice ##> "/tail @cath 2"
|
||||
alice <# "@cath -> forwarded"
|
||||
alice <## " hi"
|
||||
alice <# "@cath -> forwarded"
|
||||
alice <## " hey"
|
||||
|
||||
cath ##> "/tail @alice 2"
|
||||
cath <# "alice> -> forwarded"
|
||||
cath <## " hi"
|
||||
cath <# "alice> -> forwarded"
|
||||
cath <## " hey"
|
||||
|
||||
testForwardContactToGroup :: HasCallStack => FilePath -> IO ()
|
||||
testForwardContactToGroup =
|
||||
testChat3 aliceProfile bobProfile cathProfile $
|
||||
\alice bob cath -> do
|
||||
connectUsers alice bob
|
||||
createGroup2 "team" alice cath
|
||||
|
||||
alice #> "@bob hi"
|
||||
bob <# "alice> hi"
|
||||
bob #> "@alice hey"
|
||||
alice <# "bob> hey"
|
||||
|
||||
alice `send` ">> @bob -> #team hi"
|
||||
alice <# "#team -> forwarded"
|
||||
alice <## " hi"
|
||||
cath <# "#team alice> -> forwarded"
|
||||
cath <## " hi"
|
||||
|
||||
alice `send` "> @bob -> #team hey"
|
||||
alice <# "#team -> forwarded"
|
||||
alice <## " hey"
|
||||
cath <# "#team alice> -> forwarded"
|
||||
cath <## " hey"
|
||||
|
||||
testForwardContactToNotes :: HasCallStack => FilePath -> IO ()
|
||||
testForwardContactToNotes =
|
||||
testChat2 aliceProfile bobProfile $
|
||||
\alice bob -> do
|
||||
createCCNoteFolder alice
|
||||
connectUsers alice bob
|
||||
|
||||
alice #> "@bob hi"
|
||||
bob <# "alice> hi"
|
||||
bob #> "@alice hey"
|
||||
alice <# "bob> hey"
|
||||
|
||||
alice `send` ">> @bob -> * hi"
|
||||
alice <# "* -> forwarded"
|
||||
alice <## " hi"
|
||||
|
||||
alice `send` "> @bob -> * hey"
|
||||
alice <# "* -> forwarded"
|
||||
alice <## " hey"
|
||||
|
||||
testForwardGroupToContact :: HasCallStack => FilePath -> IO ()
|
||||
testForwardGroupToContact =
|
||||
testChat3 aliceProfile bobProfile cathProfile $
|
||||
\alice bob cath -> do
|
||||
createGroup2 "team" alice bob
|
||||
connectUsers alice cath
|
||||
|
||||
alice #> "#team hi"
|
||||
bob <# "#team alice> hi"
|
||||
bob #> "#team hey"
|
||||
alice <# "#team bob> hey"
|
||||
|
||||
alice `send` "> #team -> @cath hi"
|
||||
alice <# "@cath -> forwarded"
|
||||
alice <## " hi"
|
||||
cath <# "alice> -> forwarded"
|
||||
cath <## " hi"
|
||||
|
||||
alice `send` "> #team -> @cath hey"
|
||||
alice <# "@cath -> forwarded"
|
||||
alice <## " hey"
|
||||
cath <# "alice> -> forwarded"
|
||||
cath <## " hey"
|
||||
|
||||
testForwardGroupToGroup :: HasCallStack => FilePath -> IO ()
|
||||
testForwardGroupToGroup =
|
||||
testChat3 aliceProfile bobProfile cathProfile $
|
||||
\alice bob cath -> do
|
||||
createGroup2 "team" alice bob
|
||||
createGroup2 "club" alice cath
|
||||
|
||||
alice #> "#team hi"
|
||||
bob <# "#team alice> hi"
|
||||
bob #> "#team hey"
|
||||
alice <# "#team bob> hey"
|
||||
|
||||
alice `send` "> #team -> #club hi"
|
||||
alice <# "#club -> forwarded"
|
||||
alice <## " hi"
|
||||
cath <# "#club alice> -> forwarded"
|
||||
cath <## " hi"
|
||||
|
||||
alice `send` "> #team -> #club hey"
|
||||
alice <# "#club -> forwarded"
|
||||
alice <## " hey"
|
||||
cath <# "#club alice> -> forwarded"
|
||||
cath <## " hey"
|
||||
|
||||
testForwardGroupToNotes :: HasCallStack => FilePath -> IO ()
|
||||
testForwardGroupToNotes =
|
||||
testChat2 aliceProfile bobProfile $
|
||||
\alice bob -> do
|
||||
createCCNoteFolder alice
|
||||
createGroup2 "team" alice bob
|
||||
|
||||
alice #> "#team hi"
|
||||
bob <# "#team alice> hi"
|
||||
bob #> "#team hey"
|
||||
alice <# "#team bob> hey"
|
||||
|
||||
alice `send` "> #team -> * hi"
|
||||
alice <# "* -> forwarded"
|
||||
alice <## " hi"
|
||||
|
||||
alice `send` "> #team -> * hey"
|
||||
alice <# "* -> forwarded"
|
||||
alice <## " hey"
|
||||
|
||||
testForwardNotesToContact :: HasCallStack => FilePath -> IO ()
|
||||
testForwardNotesToContact =
|
||||
testChat2 aliceProfile cathProfile $
|
||||
\alice cath -> do
|
||||
createCCNoteFolder alice
|
||||
connectUsers alice cath
|
||||
|
||||
alice /* "hi"
|
||||
|
||||
alice `send` "> * -> @cath hi"
|
||||
alice <# "@cath -> forwarded"
|
||||
alice <## " hi"
|
||||
cath <# "alice> -> forwarded"
|
||||
cath <## " hi"
|
||||
|
||||
testForwardNotesToGroup :: HasCallStack => FilePath -> IO ()
|
||||
testForwardNotesToGroup =
|
||||
testChat2 aliceProfile cathProfile $
|
||||
\alice cath -> do
|
||||
createCCNoteFolder alice
|
||||
createGroup2 "team" alice cath
|
||||
|
||||
alice /* "hi"
|
||||
|
||||
alice `send` "> * -> #team hi"
|
||||
alice <# "#team -> forwarded"
|
||||
alice <## " hi"
|
||||
cath <# "#team alice> -> forwarded"
|
||||
cath <## " hi"
|
||||
|
||||
testForwardNotesToNotes :: HasCallStack => FilePath -> IO ()
|
||||
testForwardNotesToNotes tmp =
|
||||
withNewTestChat tmp "alice" aliceProfile $ \alice -> do
|
||||
createCCNoteFolder alice
|
||||
|
||||
alice /* "hi"
|
||||
|
||||
alice `send` "> * -> * hi"
|
||||
alice <# "* -> forwarded"
|
||||
alice <## " hi"
|
||||
|
||||
alice ##> "/tail * 2"
|
||||
alice <# "* hi"
|
||||
alice <# "* -> forwarded"
|
||||
alice <## " hi"
|
||||
|
||||
Reference in New Issue
Block a user