1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

fixes in reactions

This commit is contained in:
InsanusMokrassar 2024-01-08 15:13:51 +06:00
parent d55253a81b
commit a106068af4

View File

@ -1,7 +1,7 @@
package dev.inmo.tgbotapi.types.reactions package dev.inmo.tgbotapi.types.reactions
import dev.inmo.tgbotapi.types.CustomEmojiId import dev.inmo.tgbotapi.types.CustomEmojiId
import dev.inmo.tgbotapi.types.customEmojiField import dev.inmo.tgbotapi.types.customEmojiIdField
import dev.inmo.tgbotapi.types.emojiField import dev.inmo.tgbotapi.types.emojiField
import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded
import kotlinx.serialization.KSerializer import kotlinx.serialization.KSerializer
@ -12,6 +12,7 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.JsonDecoder import kotlinx.serialization.json.JsonDecoder
import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonElement
import kotlin.jvm.JvmInline
@Serializable(Reaction.Companion::class) @Serializable(Reaction.Companion::class)
@ClassCastsIncluded @ClassCastsIncluded
@ -19,7 +20,8 @@ sealed interface Reaction {
val type: String val type: String
@Serializable(Reaction.Companion::class) @Serializable(Reaction.Companion::class)
data class Emoji( @JvmInline
value class Emoji(
val emoji: String val emoji: String
) : Reaction { ) : Reaction {
override val type: String override val type: String
@ -30,8 +32,9 @@ sealed interface Reaction {
} }
@Serializable(Reaction.Companion::class) @Serializable(Reaction.Companion::class)
data class CustomEmoji( @JvmInline
val customEmoji: CustomEmojiId value class CustomEmoji(
val customEmojiId: CustomEmojiId
) : Reaction { ) : Reaction {
override val type: String override val type: String
get() = Companion.type get() = Companion.type
@ -51,8 +54,8 @@ sealed interface Reaction {
val type: String, val type: String,
@SerialName(emojiField) @SerialName(emojiField)
val emoji: String? = null, val emoji: String? = null,
@SerialName(customEmojiField) @SerialName(customEmojiIdField)
val customEmoji: CustomEmojiId? = null val customEmojiId: CustomEmojiId? = null
) )
companion object : KSerializer<Reaction> { companion object : KSerializer<Reaction> {
@ -69,7 +72,7 @@ sealed interface Reaction {
return when { return when {
surrogate.emoji != null -> Emoji(surrogate.emoji) surrogate.emoji != null -> Emoji(surrogate.emoji)
surrogate.customEmoji != null -> CustomEmoji(surrogate.customEmoji) surrogate.customEmojiId != null -> CustomEmoji(surrogate.customEmojiId)
else -> Unknown(surrogate.type, json) else -> Unknown(surrogate.type, json)
} }
} }
@ -83,7 +86,7 @@ sealed interface Reaction {
Surrogate( Surrogate(
type = value.type, type = value.type,
emoji = (value as? Emoji) ?.emoji, emoji = (value as? Emoji) ?.emoji,
customEmoji = (value as? CustomEmoji) ?.customEmoji, customEmojiId = (value as? CustomEmoji) ?.customEmojiId,
) )
) )
} }