mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
core: use filename in quote when there is no message text (#602)
This commit is contained in:
committed by
GitHub
parent
cf04a9fed3
commit
dbf6b1f673
+10
-6
@@ -225,11 +225,11 @@ processChatCommand = \case
|
||||
prepareMsg fileInvitation_ = case quotedItemId_ of
|
||||
Nothing -> pure (MCSimple (ExtMsgContent mc fileInvitation_), Nothing)
|
||||
Just quotedItemId -> do
|
||||
CChatItem _ ChatItem {meta = CIMeta {itemTs, itemSharedMsgId}, content = ciContent, formattedText} <-
|
||||
CChatItem _ ChatItem {meta = CIMeta {itemTs, itemSharedMsgId}, content = ciContent, formattedText, file} <-
|
||||
withStore $ \st -> getDirectChatItem st userId chatId quotedItemId
|
||||
(origQmc, qd, sent) <- quoteData ciContent
|
||||
let msgRef = MsgRef {msgId = itemSharedMsgId, sentAt = itemTs, sent, memberId = Nothing}
|
||||
qmc = quoteContent origQmc mc
|
||||
qmc = quoteContent origQmc file mc
|
||||
quotedItem = CIQuote {chatDir = qd, itemId = Just quotedItemId, sharedMsgId = itemSharedMsgId, sentAt = itemTs, content = qmc, formattedText}
|
||||
pure (MCQuote QuotedMsg {msgRef, content = qmc} (ExtMsgContent mc fileInvitation_), Just quotedItem)
|
||||
where
|
||||
@@ -261,11 +261,11 @@ processChatCommand = \case
|
||||
prepareMsg fileInvitation_ membership = case quotedItemId_ of
|
||||
Nothing -> pure (MCSimple (ExtMsgContent mc fileInvitation_), Nothing)
|
||||
Just quotedItemId -> do
|
||||
CChatItem _ ChatItem {chatDir, meta = CIMeta {itemTs, itemSharedMsgId}, content = ciContent, formattedText} <-
|
||||
CChatItem _ ChatItem {chatDir, meta = CIMeta {itemTs, itemSharedMsgId}, content = ciContent, formattedText, file} <-
|
||||
withStore $ \st -> getGroupChatItem st user chatId quotedItemId
|
||||
(origQmc, qd, sent, GroupMember {memberId}) <- quoteData ciContent chatDir membership
|
||||
let msgRef = MsgRef {msgId = itemSharedMsgId, sentAt = itemTs, sent, memberId = Just memberId}
|
||||
qmc = quoteContent origQmc mc
|
||||
qmc = quoteContent origQmc file mc
|
||||
quotedItem = CIQuote {chatDir = qd, itemId = Just quotedItemId, sharedMsgId = itemSharedMsgId, sentAt = itemTs, content = qmc, formattedText}
|
||||
pure (MCQuote QuotedMsg {msgRef, content = qmc} (ExtMsgContent mc fileInvitation_), Just quotedItem)
|
||||
where
|
||||
@@ -276,9 +276,13 @@ processChatCommand = \case
|
||||
CTContactRequest -> pure $ chatCmdError "not supported"
|
||||
CTContactConnection -> pure $ chatCmdError "not supported"
|
||||
where
|
||||
quoteContent qmc = \case
|
||||
quoteContent :: forall d. MsgContent -> Maybe (CIFile d) -> MsgContent -> MsgContent
|
||||
quoteContent qmc ciFile_ = \case
|
||||
MCText _ -> qmc
|
||||
_ -> MCText $ msgContentText qmc
|
||||
_ ->
|
||||
let t = msgContentText qmc
|
||||
fileName' = T.pack . (fileName :: CIFile d -> String)
|
||||
in MCText $ if T.null t then maybe t fileName' ciFile_ else t
|
||||
unzipMaybe :: Maybe (a, b) -> (Maybe a, Maybe b)
|
||||
unzipMaybe t = (fst <$> t, snd <$> t)
|
||||
-- TODO discontinue
|
||||
|
||||
@@ -223,9 +223,9 @@ viewChatItem chat ChatItem {chatDir, meta, content, quotedItem, file} = case cha
|
||||
withFile view dir l = maybe l (\f -> l <> view dir f meta) file
|
||||
sndMsg = msg viewSentMessage
|
||||
rcvMsg = msg viewReceivedMessage
|
||||
msg view dir quote mc = case (msgContentText mc, file) of
|
||||
("", Just _) -> []
|
||||
-- (_, Just _) -> prependFirst " " $ ttyMsgContent mc
|
||||
msg view dir quote mc = case (msgContentText mc, file, quote) of
|
||||
("", Just _, []) -> []
|
||||
("", Just CIFile {fileName}, _) -> view dir quote (MCText $ T.pack fileName) meta
|
||||
_ -> view dir quote mc meta
|
||||
|
||||
viewItemUpdate :: MsgDirectionI d => ChatInfo c -> ChatItem c d -> [StyledString]
|
||||
|
||||
+40
-2
@@ -1278,12 +1278,50 @@ testSendImageWithTextAndQuote =
|
||||
(bob <## "completed receiving file 1 (test.jpg) from alice")
|
||||
(alice <## "completed sending file 1 (test.jpg) to bob")
|
||||
src <- B.readFile "./tests/fixtures/test.jpg"
|
||||
dest <- B.readFile "./tests/tmp/test.jpg"
|
||||
dest `shouldBe` src
|
||||
B.readFile "./tests/tmp/test.jpg" `shouldReturn` src
|
||||
alice #$> ("/_get chat @2 count=100", chat'', [((0, "hi alice"), Nothing, Nothing), ((1, "hey bob"), Just (0, "hi alice"), Just "./tests/fixtures/test.jpg")])
|
||||
alice @@@ [("@bob", "hey bob")]
|
||||
bob #$> ("/_get chat @2 count=100", chat'', [((1, "hi alice"), Nothing, Nothing), ((0, "hey bob"), Just (1, "hi alice"), Just "./tests/tmp/test.jpg")])
|
||||
bob @@@ [("@alice", "hey bob")]
|
||||
-- quoting (file + text) with file uses quoted text
|
||||
bob ##> "/_send @2 file ./tests/fixtures/test.txt quoted 2 json {\"text\":\"\",\"type\":\"file\"}"
|
||||
bob <# "@alice > hey bob"
|
||||
bob <## " test.txt"
|
||||
bob <# "/f @alice ./tests/fixtures/test.txt"
|
||||
bob <## "use /fc 2 to cancel sending"
|
||||
alice <# "bob> > hey bob"
|
||||
alice <## " test.txt"
|
||||
alice <# "bob> sends file test.txt (11 bytes / 11 bytes)"
|
||||
alice <## "use /fr 2 [<dir>/ | <path>] to receive it"
|
||||
alice ##> "/fr 2 ./tests/tmp"
|
||||
alice <## "saving file 2 from bob to ./tests/tmp/test.txt"
|
||||
concurrently_
|
||||
(alice <## "started receiving file 2 (test.txt) from bob")
|
||||
(bob <## "started sending file 2 (test.txt) to alice")
|
||||
concurrently_
|
||||
(alice <## "completed receiving file 2 (test.txt) from bob")
|
||||
(bob <## "completed sending file 2 (test.txt) to alice")
|
||||
txtSrc <- B.readFile "./tests/fixtures/test.txt"
|
||||
B.readFile "./tests/tmp/test.txt" `shouldReturn` txtSrc
|
||||
-- quoting (file without text) with file uses file name
|
||||
alice ##> "/_send @2 file ./tests/fixtures/test.jpg quoted 3 json {\"text\":\"\",\"type\":\"image\",\"image\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAQMAAAD+wSzIAAAABlBMVEX///+/v7+jQ3Y5AAAADklEQVQI12P4AIX8EAgALgAD/aNpbtEAAAAASUVORK5CYII=\"}"
|
||||
alice <# "@bob > test.txt"
|
||||
alice <## " test.jpg"
|
||||
alice <# "/f @bob ./tests/fixtures/test.jpg"
|
||||
alice <## "use /fc 3 to cancel sending"
|
||||
bob <# "alice> > test.txt"
|
||||
bob <## " test.jpg"
|
||||
bob <# "alice> sends file test.jpg (136.5 KiB / 139737 bytes)"
|
||||
bob <## "use /fr 3 [<dir>/ | <path>] to receive it"
|
||||
bob ##> "/fr 3 ./tests/tmp"
|
||||
bob <## "saving file 3 from alice to ./tests/tmp/test_1.jpg"
|
||||
concurrently_
|
||||
(bob <## "started receiving file 3 (test.jpg) from alice")
|
||||
(alice <## "started sending file 3 (test.jpg) to bob")
|
||||
concurrently_
|
||||
(bob <## "completed receiving file 3 (test.jpg) from alice")
|
||||
(alice <## "completed sending file 3 (test.jpg) to bob")
|
||||
B.readFile "./tests/tmp/test_1.jpg" `shouldReturn` src
|
||||
|
||||
testGroupSendImage :: IO ()
|
||||
testGroupSendImage =
|
||||
|
||||
Reference in New Issue
Block a user