core: chat item content types for chat initiation (#5998)

* core: chat item content types for chat initiation

* connection mode for ui

* padding

* simplexmq

* initial items

* update content items

* core: feature and e2e items

* refactor

* chat items

* ios types

* fix condition for PQ encryption of link
This commit is contained in:
Evgeny
2025-06-20 11:54:21 +01:00
committed by GitHub
parent 05dba0bda2
commit fc04872c91
19 changed files with 230 additions and 103 deletions
+29 -1
View File
@@ -533,7 +533,16 @@ cmToQuotedMsg = \case
ACME _ (XMsgNew (MCQuote quotedMsg _)) -> Just quotedMsg
_ -> Nothing
data MsgContentTag = MCText_ | MCLink_ | MCImage_ | MCVideo_ | MCVoice_ | MCFile_ | MCReport_ | MCUnknown_ Text
data MsgContentTag
= MCText_
| MCLink_
| MCImage_
| MCVideo_
| MCVoice_
| MCFile_
| MCReport_
| MCChat_
| MCUnknown_ Text
deriving (Eq, Show)
instance StrEncoding MsgContentTag where
@@ -545,6 +554,7 @@ instance StrEncoding MsgContentTag where
MCFile_ -> "file"
MCVoice_ -> "voice"
MCReport_ -> "report"
MCChat_ -> "chat"
MCUnknown_ t -> encodeUtf8 t
strDecode = \case
"text" -> Right MCText_
@@ -554,6 +564,7 @@ instance StrEncoding MsgContentTag where
"voice" -> Right MCVoice_
"file" -> Right MCFile_
"report" -> Right MCReport_
"chat" -> Right MCChat_
t -> Right . MCUnknown_ $ safeDecodeUtf8 t
strP = strDecode <$?> A.takeTill (== ' ')
@@ -593,9 +604,16 @@ data MsgContent
| MCVoice {text :: Text, duration :: Int}
| MCFile {text :: Text}
| MCReport {text :: Text, reason :: ReportReason}
| MCChat {text :: Text, chatLink :: MsgChatLink}
| MCUnknown {tag :: Text, text :: Text, json :: J.Object}
deriving (Eq, Show)
data MsgChatLink
= MCLContact {connLink :: ShortLinkContact, profile :: Profile, business :: Bool}
| MCLInvitation {invLink :: ShortLinkInvitation, profile :: Profile}
| MCLGroup {connLink :: ShortLinkContact, groupProfile :: GroupProfile}
deriving (Eq, Show)
msgContentText :: MsgContent -> Text
msgContentText = \case
MCText t -> t
@@ -611,6 +629,7 @@ msgContentText = \case
if T.null text then msg else msg <> ": " <> text
where
msg = "report " <> safeDecodeUtf8 (strEncode reason)
MCChat {text} -> text
MCUnknown {text} -> text
durationText :: Int -> Text
@@ -646,6 +665,7 @@ msgContentTag = \case
MCVoice {} -> MCVoice_
MCFile {} -> MCFile_
MCReport {} -> MCReport_
MCChat {} -> MCChat_
MCUnknown {tag} -> MCUnknown_ tag
data ExtMsgContent = ExtMsgContent
@@ -664,6 +684,8 @@ data ExtMsgContent = ExtMsgContent
data MsgMention = MsgMention {memberId :: MemberId}
deriving (Eq, Show)
$(JQ.deriveJSON (taggedObjectJSON $ dropPrefix "MCL") ''MsgChatLink)
$(JQ.deriveJSON defaultJSON ''MsgMention)
$(JQ.deriveJSON defaultJSON ''QuotedMsg)
@@ -773,6 +795,10 @@ instance FromJSON MsgContent where
text <- v .: "text"
reason <- v .: "reason"
pure MCReport {text, reason}
MCChat_ -> do
text <- v .: "text"
chatLink <- v .: "chatLink"
pure MCChat {text, chatLink}
MCUnknown_ tag -> do
text <- fromMaybe unknownMsgType <$> v .:? "text"
pure MCUnknown {tag, text, json = v}
@@ -807,6 +833,7 @@ instance ToJSON MsgContent where
MCVoice {text, duration} -> J.object ["type" .= MCVoice_, "text" .= text, "duration" .= duration]
MCFile t -> J.object ["type" .= MCFile_, "text" .= t]
MCReport {text, reason} -> J.object ["type" .= MCReport_, "text" .= text, "reason" .= reason]
MCChat {text, chatLink} -> J.object ["type" .= MCChat_, "text" .= text, "chatLink" .= chatLink]
toEncoding = \case
MCUnknown {json} -> JE.value $ J.Object json
MCText t -> J.pairs $ "type" .= MCText_ <> "text" .= t
@@ -816,6 +843,7 @@ instance ToJSON MsgContent where
MCVoice {text, duration} -> J.pairs $ "type" .= MCVoice_ <> "text" .= text <> "duration" .= duration
MCFile t -> J.pairs $ "type" .= MCFile_ <> "text" .= t
MCReport {text, reason} -> J.pairs $ "type" .= MCReport_ <> "text" .= text <> "reason" .= reason
MCChat {text, chatLink} -> J.pairs $ "type" .= MCChat_ <> "text" .= text <> "chatLink" .= chatLink
instance ToField MsgContent where
toField = toField . encodeJSON