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

UnknownUpdateType even if serialization exception

This commit is contained in:
InsanusMokrassar 2020-04-13 11:17:15 +06:00
parent 82d3b3bc48
commit 31f7c7f31b
3 changed files with 33 additions and 20 deletions

View File

@ -46,6 +46,9 @@
[PR-80](https://github.com/InsanusMokrassar/TelegramBotAPI/pull/80)) [PR-80](https://github.com/InsanusMokrassar/TelegramBotAPI/pull/80))
* `UnknownInlineKeyboardButton` was added. It is unavailable for creating, but you can receive it, for example, in * `UnknownInlineKeyboardButton` was added. It is unavailable for creating, but you can receive it, for example, in
`InlineQueryResult` `InlineQueryResult`
* `Update` now will be created even if was `SerializationException` inside of creating the update instance - in this
case will be created `UnknownUpdateType`
* `UnknownUpdateType$rawJson` value now is included (`JsonElement`)
### 0.26.2 ### 0.26.2

View File

@ -13,8 +13,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.polls.PollAnswer
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UnknownUpdateType import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UnknownUpdateType
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
import com.github.insanusmokrassar.TelegramBotAPI.types.updateIdField import com.github.insanusmokrassar.TelegramBotAPI.types.updateIdField
import kotlinx.serialization.SerialName import kotlinx.serialization.*
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonElement
@Serializable @Serializable
@ -42,7 +41,8 @@ internal data class RawUpdate constructor(
* @return One of children of [Update] interface or null in case of unknown type of update * @return One of children of [Update] interface or null in case of unknown type of update
*/ */
fun asUpdate(raw: JsonElement): Update { fun asUpdate(raw: JsonElement): Update {
return initedUpdate ?: when { return initedUpdate ?: try {
when {
edited_message != null -> EditMessageUpdate(updateId, edited_message) edited_message != null -> EditMessageUpdate(updateId, edited_message)
message != null -> MessageUpdate(updateId, message) message != null -> MessageUpdate(updateId, message)
edited_channel_post != null -> EditChannelPostUpdate(updateId, edited_channel_post) edited_channel_post != null -> EditChannelPostUpdate(updateId, edited_channel_post)
@ -60,7 +60,15 @@ internal data class RawUpdate constructor(
poll_answer != null -> PollAnswerUpdate(updateId, poll_answer) poll_answer != null -> PollAnswerUpdate(updateId, poll_answer)
else -> UnknownUpdateType( else -> UnknownUpdateType(
updateId, updateId,
raw.toString() raw.toString(),
raw
)
}
} catch (e: SerializationException) {
UnknownUpdateType(
updateId,
raw.toString(),
raw
) )
}.also { }.also {
initedUpdate = it initedUpdate = it

View File

@ -4,6 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.update.RawUpdate import com.github.insanusmokrassar.TelegramBotAPI.types.update.RawUpdate
import com.github.insanusmokrassar.TelegramBotAPI.utils.nonstrictJsonFormat import com.github.insanusmokrassar.TelegramBotAPI.utils.nonstrictJsonFormat
import kotlinx.serialization.* import kotlinx.serialization.*
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonElementSerializer import kotlinx.serialization.json.JsonElementSerializer
interface Update { interface Update {
@ -13,7 +14,8 @@ interface Update {
data class UnknownUpdateType( data class UnknownUpdateType(
override val updateId: UpdateIdentifier, override val updateId: UpdateIdentifier,
override val data: String override val data: String,
val rawJson: JsonElement
) : Update ) : Update
internal object UpdateSerializerWithoutDeserialization : KSerializer<Update> { internal object UpdateSerializerWithoutDeserialization : KSerializer<Update> {