diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index 223fece350..e1fb516c7c 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -705,7 +705,16 @@ processChatCommand' vr = \case [] -> pure Nothing memStatuses -> pure $ Just $ map (uncurry MemberDeliveryStatus) memStatuses _ -> pure Nothing - pure $ CRChatItemInfo user aci ChatItemInfo {itemVersions, memberDeliveryStatuses} + forwardedFromChatItem <- getForwardedFromItem user ci + pure $ CRChatItemInfo user aci ChatItemInfo {itemVersions, memberDeliveryStatuses, forwardedFromChatItem} + where + getForwardedFromItem :: User -> ChatItem c d -> CM (Maybe AChatItem) + getForwardedFromItem user ChatItem {meta = CIMeta {itemForwarded}} = case itemForwarded of + Just (CIFFContact _ _ (Just ctId) (Just fwdItemId)) -> + Just <$> withStore (\db -> getAChatItem db vr user (ChatRef CTDirect ctId) fwdItemId) + Just (CIFFGroup _ _ (Just gId) (Just fwdItemId)) -> + Just <$> withStore (\db -> getAChatItem db vr user (ChatRef CTGroup gId) fwdItemId) + _ -> pure Nothing APISendMessage (ChatRef cType chatId) live itemTTL cm -> withUser $ \user -> case cType of CTDirect -> withContactLock "sendMessage" chatId $ sendContactContentMessage user chatId live itemTTL cm Nothing diff --git a/src/Simplex/Chat/Messages.hs b/src/Simplex/Chat/Messages.hs index 50ec1dd80e..3da9c2b2ae 100644 --- a/src/Simplex/Chat/Messages.hs +++ b/src/Simplex/Chat/Messages.hs @@ -1031,9 +1031,10 @@ instance TextEncoding CIForwardedFromTag where data ChatItemInfo = ChatItemInfo { itemVersions :: [ChatItemVersion], - memberDeliveryStatuses :: Maybe [MemberDeliveryStatus] + memberDeliveryStatuses :: Maybe [MemberDeliveryStatus], + forwardedFromChatItem :: Maybe AChatItem } - deriving (Eq, Show) + deriving (Show) data ChatItemVersion = ChatItemVersion { chatItemVersionId :: Int64, @@ -1116,8 +1117,6 @@ $(JQ.deriveJSON defaultJSON ''MemberDeliveryStatus) $(JQ.deriveJSON defaultJSON ''ChatItemVersion) -$(JQ.deriveJSON defaultJSON ''ChatItemInfo) - instance (ChatTypeI c, MsgDirectionI d) => FromJSON (CIMeta c d) where parseJSON = $(JQ.mkParseJSON defaultJSON ''CIMeta) @@ -1207,6 +1206,8 @@ instance ChatTypeI c => ToJSON (CChatItem c) where toJSON (CChatItem _ ci) = J.toJSON ci toEncoding (CChatItem _ ci) = J.toEncoding ci +$(JQ.deriveJSON defaultJSON ''ChatItemInfo) + $(JQ.deriveJSON defaultJSON ''ChatStats) instance ChatTypeI c => ToJSON (Chat c) where diff --git a/src/Simplex/Chat/View.hs b/src/Simplex/Chat/View.hs index 635c6a3b10..346037f539 100644 --- a/src/Simplex/Chat/View.hs +++ b/src/Simplex/Chat/View.hs @@ -625,11 +625,12 @@ viewChatItem chat ci@ChatItem {chatDir, meta = meta@CIMeta {itemForwarded, forwa prohibited = styled (colored Red) ("[unexpected chat item created, please report to developers]" :: String) viewChatItemInfo :: AChatItem -> ChatItemInfo -> TimeZone -> [StyledString] -viewChatItemInfo (AChatItem _ msgDir _ ChatItem {meta = CIMeta {itemTs, itemTimed, createdAt}}) ChatItemInfo {itemVersions} tz = +viewChatItemInfo (AChatItem _ msgDir _ ChatItem {meta = CIMeta {itemTs, itemTimed, createdAt}}) ChatItemInfo {itemVersions, forwardedFromChatItem} tz = ["sent at: " <> ts itemTs] <> receivedAt <> toBeDeletedAt <> versions + <> forwardedFromItemId where ts = styleTime . localTs tz receivedAt = case msgDir of @@ -642,7 +643,12 @@ viewChatItemInfo (AChatItem _ msgDir _ ChatItem {meta = CIMeta {itemTs, itemTime if null itemVersions then [] else ["message history:"] <> concatMap version itemVersions - version ChatItemVersion {msgContent, itemVersionTs} = prependFirst (ts itemVersionTs <> styleTime ": ") $ ttyMsgContent msgContent + where + version ChatItemVersion {msgContent, itemVersionTs} = prependFirst (ts itemVersionTs <> styleTime ": ") $ ttyMsgContent msgContent + forwardedFromItemId = + case forwardedFromChatItem of + Just aci -> ["forwarded from chat item id: " <> (plain . show) (aChatItemId aci)] + _ -> [] localTs :: TimeZone -> UTCTime -> String localTs tz ts = do diff --git a/tests/ChatTests/Forward.hs b/tests/ChatTests/Forward.hs index 57b38354df..e7eabd7a64 100644 --- a/tests/ChatTests/Forward.hs +++ b/tests/ChatTests/Forward.hs @@ -54,6 +54,7 @@ testForwardContactToContact = cath <# "alice> -> forwarded" cath <## " hey" + -- read chat alice ##> "/tail @cath 2" alice <# "@cath -> from you" alice <## " hi" @@ -66,6 +67,13 @@ testForwardContactToContact = cath <# "alice> -> forwarded" cath <## " hey" + -- item info + alice ##> "/item info @cath hey" + alice <##. "sent at: " + alice <## "message history:" + alice .<## ": hey" + alice <##. "forwarded from chat item id:" + testForwardContactToGroup :: HasCallStack => FilePath -> IO () testForwardContactToGroup = testChat3 aliceProfile bobProfile cathProfile $