mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-03-30 20:45:49 +00:00
core: forward compatible format encoding (for remote desktop) (#6147)
* core: forward compatible format encoding (for remote desktop) * fix ios
This commit is contained in:
@@ -373,6 +373,7 @@ func messageText(
|
||||
attrs[linkAttrKey] = NSURL(string: "tel:" + t.replacingOccurrences(of: " ", with: ""))
|
||||
handleTaps = true
|
||||
}
|
||||
case .unknown: ()
|
||||
case .none: ()
|
||||
}
|
||||
res.append(NSAttributedString(string: t, attributes: attrs))
|
||||
|
||||
@@ -4449,6 +4449,7 @@ public enum Format: Decodable, Equatable, Hashable {
|
||||
case mention(memberName: String)
|
||||
case email
|
||||
case phone
|
||||
case unknown
|
||||
|
||||
public var isSimplexLink: Bool {
|
||||
get {
|
||||
|
||||
@@ -4352,6 +4352,7 @@ sealed class Format {
|
||||
@Serializable @SerialName("mention") class Mention(val memberName: String): Format()
|
||||
@Serializable @SerialName("email") class Email: Format()
|
||||
@Serializable @SerialName("phone") class Phone: Format()
|
||||
@Serializable @SerialName("unknown") class Unknown: Format()
|
||||
|
||||
val style: SpanStyle @Composable get() = when (this) {
|
||||
is Bold -> SpanStyle(fontWeight = FontWeight.Bold)
|
||||
@@ -4365,6 +4366,7 @@ sealed class Format {
|
||||
is Mention -> SpanStyle(fontWeight = FontWeight.Medium)
|
||||
is Email -> linkStyle
|
||||
is Phone -> linkStyle
|
||||
is Unknown -> SpanStyle()
|
||||
}
|
||||
|
||||
val isSimplexLink = this is SimplexLink
|
||||
|
||||
@@ -255,7 +255,7 @@ chatTypesDocsData =
|
||||
(sti @FileProtocol, (STEnum' $ consLower "FP"), "", [], "", ""),
|
||||
(sti @FileStatus, STEnum, "FS", [], "", ""),
|
||||
(sti @FileTransferMeta, STRecord, "", [], "", ""),
|
||||
(sti @Format, STUnion, "", [], "", ""),
|
||||
(sti @Format, STUnion, "", ["Unknown"], "", ""),
|
||||
(sti @FormattedText, STRecord, "", [], "", ""),
|
||||
(sti @FullGroupPreferences, STRecord, "", [], "", ""),
|
||||
(sti @FullPreferences, STRecord, "", [], "", ""),
|
||||
|
||||
@@ -170,6 +170,7 @@ toTypeInfo tr =
|
||||
"FormatColor" -> ST "Color" []
|
||||
"CustomData" -> ST "JSONObject" []
|
||||
"KeyMap" -> ST "JSONObject" []
|
||||
"Value" -> ST "JSONObject" []
|
||||
"CIQDirection" -> ST "CIDirection" []
|
||||
"SendRef" -> ST "ChatRef" []
|
||||
t
|
||||
|
||||
@@ -53,6 +53,7 @@ data Format
|
||||
| Mention {memberName :: Text}
|
||||
| Email
|
||||
| Phone
|
||||
| Unknown {json :: J.Value}
|
||||
deriving (Eq, Show)
|
||||
|
||||
mentionedNames :: MarkdownList -> [Text]
|
||||
@@ -305,6 +306,7 @@ markdownText (FormattedText f_ t) = case f_ of
|
||||
Mention _ -> t
|
||||
Email -> t
|
||||
Phone -> t
|
||||
Unknown _ -> t
|
||||
where
|
||||
around c = c `T.cons` t `T.snoc` c
|
||||
color c = case colorStr c of
|
||||
@@ -340,7 +342,10 @@ viewName s = if T.any isSpace s || maybe False (isPunctuation . snd) (T.unsnoc s
|
||||
|
||||
$(JQ.deriveJSON (enumJSON $ dropPrefix "XL") ''SimplexLinkType)
|
||||
|
||||
$(JQ.deriveJSON (sumTypeJSON fstToLower) ''Format)
|
||||
$(JQ.deriveToJSON (sumTypeJSON fstToLower) ''Format)
|
||||
|
||||
instance FromJSON Format where
|
||||
parseJSON v = $(JQ.mkParseJSON (sumTypeJSON fstToLower) ''Format) v <|> pure (Unknown v)
|
||||
|
||||
$(JQ.deriveJSON defaultJSON ''FormattedText)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user