From 7ff4b05c9078cd91e6068df429583e71b6c86e4b Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Mon, 15 Apr 2024 17:19:37 +0400 Subject: [PATCH] core: remember new origin for received forwarded messages (#4032) --- src/Simplex/Chat.hs | 8 +++++--- tests/ChatTests/Forward.hs | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index 92dc294d4b..41c744850a 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -930,10 +930,12 @@ processChatCommand' vr = \case forwardMC ChatItem {content = CIRcvMsgContent fmc} = pure (fmc, MDRcv) forwardMC _ = throwChatError CEInvalidForward forwardCIFF :: ChatItem c d -> Maybe CIForwardedFrom -> Maybe CIForwardedFrom - forwardCIFF ChatItem {meta = CIMeta {itemForwarded = Just ciff}} _ = Just ciff - forwardCIFF _ ciff = ciff + forwardCIFF ChatItem {meta = CIMeta {itemForwarded}} ciff = case itemForwarded of + Nothing -> ciff + Just CIFFUnknown -> ciff + Just prevCIFF -> Just prevCIFF forwardCryptoFile :: ChatItem c d -> CM (Maybe CryptoFile) - forwardCryptoFile ChatItem {file = Just CIFile {fileName, fileStatus, fileSource = Just fromCF@CryptoFile {filePath, cryptoArgs = fromArgs}}} + forwardCryptoFile ChatItem {file = Just CIFile {fileName, fileStatus, fileSource = Just fromCF@CryptoFile {filePath}}} | ciFileLoaded fileStatus = chatReadVar filesFolder >>= \case Nothing -> diff --git a/tests/ChatTests/Forward.hs b/tests/ChatTests/Forward.hs index 8638076ab2..d49c6df955 100644 --- a/tests/ChatTests/Forward.hs +++ b/tests/ChatTests/Forward.hs @@ -24,6 +24,7 @@ chatForwardTests = do it "from notes to notes" testForwardNotesToNotes -- TODO forward between different folders when supported describe "interactions with forwarded messages" $ do it "preserve original forward info" testForwardPreserveInfo + it "received forwarded message is saved with new forward info" testForwardRcvMsgNewInfo it "quoted message is not included" testForwardQuotedMsg it "editing is prohibited" testForwardEditProhibited it "delete for other" testForwardDeleteForOther @@ -276,6 +277,34 @@ testForwardPreserveInfo = dan <# "#team alice> -> forwarded" dan <## " hey" +testForwardRcvMsgNewInfo :: HasCallStack => FilePath -> IO () +testForwardRcvMsgNewInfo = + testChat4 aliceProfile bobProfile cathProfile danProfile $ + \alice bob cath dan -> do + connectUsers bob dan + createCCNoteFolder alice + connectUsers alice bob + connectUsers alice cath + + dan #> "@bob hey" + bob <# "dan> hey" + + bob `send` "@alice <- @dan hey" + bob <# "@alice <- @dan" + bob <## " hey" + alice <# "bob> -> forwarded" + alice <## " hey" + + alice `send` "* <- @bob hey" + alice <# "* <- @bob" + alice <## " hey" + + alice `send` "@cath <- * hey" + alice <# "@cath <- @bob" + alice <## " hey" + cath <# "alice> -> forwarded" + cath <## " hey" + testForwardQuotedMsg :: HasCallStack => FilePath -> IO () testForwardQuotedMsg = testChat3 aliceProfile bobProfile cathProfile $