diff --git a/CHANGELOG.md b/CHANGELOG.md index 88a2894aba..f7466bc054 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ incoming messages * `TelegramBotAPIMessageDeserializeOnlySerializer` was created. It **MUST NOT** be used to serialize messages * Update of description +* `RawUpdate` not is internal and not available outside of library ## 0.17.0 diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt index a79db0d088..06ce78b2ac 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt @@ -4,6 +4,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleReque import com.github.insanusmokrassar.TelegramBotAPI.types.ALL_UPDATES_LIST import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.update.RawUpdate +import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update +import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UpdateSerializerWithoutDeserialization import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.internal.ArrayListSerializer @@ -35,8 +37,10 @@ data class GetUpdates( val limit: Int? = null, val timeout: Int? = null, val allowed_updates: List? = ALL_UPDATES_LIST -): SimpleRequest> { +): SimpleRequest> { override fun method(): String = "getUpdates" - override fun resultDeserializer(): KSerializer> = ArrayListSerializer(RawUpdate.serializer()) + override fun resultDeserializer(): KSerializer> = ArrayListSerializer( + UpdateSerializerWithoutDeserialization + ) } diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/RawUpdate.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/RawUpdate.kt index 9299cbce03..6d237db6d6 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/RawUpdate.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/RawUpdate.kt @@ -14,10 +14,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update import com.github.insanusmokrassar.TelegramBotAPI.types.updateIdField import kotlinx.serialization.* -// TODO:: add ShippingQuery type -// TODO:: add PreCheckoutQuery type @Serializable -data class RawUpdate constructor( +internal data class RawUpdate constructor( @SerialName(updateIdField) val updateId: UpdateIdentifier, @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt index dacc8176ab..7bb89c0ffb 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt @@ -1,8 +1,29 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.update.RawUpdate +import kotlinx.serialization.* +import kotlinx.serialization.internal.StringDescriptor interface Update { val updateId: UpdateIdentifier val data: Any } + +object UpdateSerializerWithoutDeserialization : KSerializer { + override val descriptor: SerialDescriptor = StringDescriptor.withName("UpdateSerializerWithoutDeserialization") + + override fun deserialize(decoder: Decoder): Update = UpdateDeserializationStrategy.deserialize(decoder) + + override fun serialize(encoder: Encoder, obj: Update) = throw UnsupportedOperationException() +} + +object UpdateDeserializationStrategy : DeserializationStrategy { + override val descriptor: SerialDescriptor = StringDescriptor.withName("UpdateDeserializationStrategy") + + override fun patch(decoder: Decoder, old: Update): Update = throw UpdateNotSupportedException(descriptor.name) + + override fun deserialize(decoder: Decoder): Update { + return RawUpdate.serializer().deserialize(decoder).asUpdate + } +} diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/KtorUpdatesPoller.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/KtorUpdatesPoller.kt index 2f670113d5..941773383d 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/KtorUpdatesPoller.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/KtorUpdatesPoller.kt @@ -109,9 +109,7 @@ class KtorUpdatesPoller( timeoutSeconds, allowedUpdates ) - ).map { - it.asUpdate - } + ) } private suspend fun handleUpdates(updates: List) {