desktop, android: fix parser for reactions (#5629)

* desktop, android: fix parser for reactions

* core: restrict API to known reactions
This commit is contained in:
Evgeny
2025-02-14 23:37:06 +00:00
committed by GitHub
parent 56eaf12840
commit dfe5a4464b
4 changed files with 23 additions and 7 deletions
@@ -2981,7 +2981,7 @@ sealed class MsgReaction {
MREmojiChar.Heart -> "❤️"
else -> emoji.value
}
is Unknown -> ""
is Unknown -> "?"
}
companion object {
@@ -3003,8 +3003,13 @@ object MsgReactionSerializer : KSerializer<MsgReaction> {
return if (json is JsonObject && "type" in json) {
when(val t = json["type"]?.jsonPrimitive?.content ?: "") {
"emoji" -> {
val emoji = Json.decodeFromString<MREmojiChar>(json["emoji"].toString())
if (emoji == null) MsgReaction.Unknown(t, json) else MsgReaction.Emoji(emoji)
val msgReaction = try {
val emoji = Json.decodeFromString<MREmojiChar>(json["emoji"].toString())
MsgReaction.Emoji(emoji)
} catch (e: Throwable) {
MsgReaction.Unknown(t, json)
}
msgReaction
}
else -> MsgReaction.Unknown(t, json)
}