mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
RawUpdate is internal
This commit is contained in:
parent
c7a8bc5c9d
commit
617bccaa81
@ -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
|
||||
|
||||
|
@ -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<String>? = ALL_UPDATES_LIST
|
||||
): SimpleRequest<List<RawUpdate>> {
|
||||
): SimpleRequest<List<Update>> {
|
||||
override fun method(): String = "getUpdates"
|
||||
|
||||
override fun resultDeserializer(): KSerializer<List<RawUpdate>> = ArrayListSerializer(RawUpdate.serializer())
|
||||
override fun resultDeserializer(): KSerializer<List<Update>> = ArrayListSerializer(
|
||||
UpdateSerializerWithoutDeserialization
|
||||
)
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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<Update> {
|
||||
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<Update> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -109,9 +109,7 @@ class KtorUpdatesPoller(
|
||||
timeoutSeconds,
|
||||
allowedUpdates
|
||||
)
|
||||
).map {
|
||||
it.asUpdate
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun handleUpdates(updates: List<Update>) {
|
||||
|
Loading…
Reference in New Issue
Block a user