diff --git a/CHANGELOG.md b/CHANGELOG.md index af0b3d4e5d..1aceca33db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # TelegramBotAPI changelog +## 9.2.1 + +* `Version`: + * `Ktor`: `2.3.3` -> `2.3.4` +* `Core`: + * All `ChatMember` inheritors have fixes `status` field + ## 9.2.0 **Add support of [Telegram Bots API 6.9](https://core.telegram.org/bots/api-changelog#september-22-2023)** diff --git a/gradle.properties b/gradle.properties index d7e79bba4f..83b46a74a2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ kotlin.incremental=true kotlin.incremental.js=true library_group=dev.inmo -library_version=9.2.0 +library_version=9.2.1 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 202011f887..0fba10635e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -8,7 +8,7 @@ javax-activation = "1.1.1" korlibs = "4.0.3" uuid = "0.7.1" -ktor = "2.3.3" +ktor = "2.3.4" ksp = "1.8.22-1.0.11" kotlin-poet = "1.14.2" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/AdministratorChatMemberImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/AdministratorChatMemberImpl.kt index 523ac72d19..928fdf8ae6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/AdministratorChatMemberImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/AdministratorChatMemberImpl.kt @@ -45,6 +45,5 @@ data class AdministratorChatMemberImpl( ) : AdministratorChatMember { @SerialName(statusField) @Required - override val status: ChatMember.Status - get() = ChatMember.Status.Administrator + override val status: ChatMember.Status = ChatMember.Status.Administrator } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/ChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/ChatMember.kt index d8ea2691e6..b2598b7d67 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/ChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/ChatMember.kt @@ -7,6 +7,7 @@ import dev.inmo.tgbotapi.utils.nonstrictJsonFormat import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable +import kotlinx.serialization.builtins.serializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder @@ -15,8 +16,11 @@ import kotlinx.serialization.json.jsonPrimitive @Serializable(ChatMemberSerializer::class) sealed interface ChatMember : WithUser { - @Serializable - enum class Status(val status: String, val deserializationStrategy: DeserializationStrategy) { + @Serializable(StatusSerializer::class) + enum class Status( + val status: String, + val deserializationStrategy: DeserializationStrategy + ) { Creator("creator", OwnerChatMember.serializer()), Administrator("administrator", AdministratorChatMemberImpl.serializer()), Member("member", MemberChatMemberImpl.serializer()), @@ -24,6 +28,23 @@ sealed interface ChatMember : WithUser { Left("left", LeftChatMemberImpl.serializer()), Kicked("kicked", KickedChatMember.serializer()) } + + object StatusSerializer : KSerializer { + override val descriptor: SerialDescriptor + get() = String.serializer().descriptor + + override fun deserialize(decoder: Decoder): Status { + val status = decoder.decodeString() + return Status.values().first { + it.status == status + } + } + + override fun serialize(encoder: Encoder, value: Status) { + encoder.encodeString(value.status) + } + } + val status: Status } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/KickedChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/KickedChatMember.kt index b54d906ed3..3da3b37c53 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/KickedChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/KickedChatMember.kt @@ -13,6 +13,5 @@ data class KickedChatMember( ) : BannedChatMember { @SerialName(statusField) @Required - override val status: ChatMember.Status - get() = ChatMember.Status.Kicked + override val status: ChatMember.Status = ChatMember.Status.Kicked } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/LeftChatMemberImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/LeftChatMemberImpl.kt index 1676372c04..aae25344e3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/LeftChatMemberImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/LeftChatMemberImpl.kt @@ -11,6 +11,5 @@ data class LeftChatMemberImpl( ) : LeftChatMember { @SerialName(statusField) @Required - override val status: ChatMember.Status - get() = ChatMember.Status.Left + override val status: ChatMember.Status = ChatMember.Status.Left } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/MemberChatMemberImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/MemberChatMemberImpl.kt index b2cc64be59..9edd84d50c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/MemberChatMemberImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/MemberChatMemberImpl.kt @@ -11,6 +11,5 @@ data class MemberChatMemberImpl( ) : MemberChatMember { @SerialName(statusField) @Required - override val status: ChatMember.Status - get() = ChatMember.Status.Member + override val status: ChatMember.Status = ChatMember.Status.Member } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/OwnerChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/OwnerChatMember.kt index 1a825d2db3..9be0119f5f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/OwnerChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/OwnerChatMember.kt @@ -45,6 +45,5 @@ data class OwnerChatMember( @SerialName(statusField) @Required - override val status: ChatMember.Status - get() = ChatMember.Status.Creator + override val status: ChatMember.Status = ChatMember.Status.Creator } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/RestrictedChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/RestrictedChatMember.kt index 2529b77eff..1d1b3b9e6c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/RestrictedChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/RestrictedChatMember.kt @@ -44,6 +44,5 @@ data class RestrictedChatMember( ) : BannedChatMember, SpecialRightsChatMember, ChatPermissions { @SerialName(statusField) @Required - override val status: ChatMember.Status - get() = ChatMember.Status.Restricted + override val status: ChatMember.Status = ChatMember.Status.Restricted }