mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-23 00:57:13 +00:00
adapt code to new versions
This commit is contained in:
parent
6c5fc8144b
commit
128e69e3e3
@ -28,7 +28,9 @@
|
||||
* `kotlin serialization`: 0.11.1 -> 0.14.0
|
||||
* `joda time`: 2.10.3 -> 2.10.5
|
||||
* `ktor`: 1.2.3 -> 1.2.5
|
||||
|
||||
* `BotAction` now will be deserialized in a little bit other way
|
||||
* `BotActionSerializer` now is internal
|
||||
* Most part of serializers now are objects (instead of classes as was previously)
|
||||
|
||||
## 0.17.0 July 29, 2019 API Update
|
||||
|
||||
|
@ -37,7 +37,7 @@ data class Username(
|
||||
fun String.toUsername(): Username = Username(this)
|
||||
|
||||
@Serializer(ChatIdentifier::class)
|
||||
internal class ChatIdentifierSerializer: KSerializer<ChatIdentifier> {
|
||||
internal object ChatIdentifierSerializer : KSerializer<ChatIdentifier> {
|
||||
override fun deserialize(decoder: Decoder): ChatIdentifier {
|
||||
val id = decoder.decodeString()
|
||||
return id.toLongOrNull() ?.let {
|
||||
|
@ -27,7 +27,7 @@ typealias Markdown = MarkdownParseMode
|
||||
typealias HTML = HTMLParseMode
|
||||
|
||||
@Serializer(ParseMode::class)
|
||||
internal class ParseModeSerializerObject: KSerializer<ParseMode> {
|
||||
internal object ParseModeSerializerObject : KSerializer<ParseMode> {
|
||||
override fun deserialize(decoder: Decoder): ParseMode {
|
||||
val mode = decoder.decodeString()
|
||||
return when (mode) {
|
||||
|
@ -21,7 +21,7 @@ class TelegramDate(
|
||||
fun DateTime.toTelegramDate(): TelegramDate = TelegramDate(this)
|
||||
|
||||
@Serializer(TelegramDate::class)
|
||||
internal class TelegramDateSerializer: KSerializer<TelegramDate> {
|
||||
internal object TelegramDateSerializer : KSerializer<TelegramDate> {
|
||||
override fun serialize(encoder: Encoder, obj: TelegramDate) {
|
||||
encoder.encodeLong(
|
||||
TimeUnit.MILLISECONDS.toSeconds(obj.asDate.millis)
|
||||
|
@ -2,31 +2,29 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.actions
|
||||
|
||||
import kotlinx.serialization.*
|
||||
|
||||
private val actions = listOf(
|
||||
TypingAction,
|
||||
UploadPhotoAction,
|
||||
RecordVideoAction,
|
||||
UploadVideoAction,
|
||||
RecordAudioAction,
|
||||
UploadAudioAction,
|
||||
UploadDocumentAction,
|
||||
FindLocationAction
|
||||
)
|
||||
|
||||
@Serializable(BotActionSerializer::class)
|
||||
sealed class BotAction {
|
||||
abstract val actionName: String
|
||||
}
|
||||
|
||||
@Serializer(BotAction::class)
|
||||
class BotActionSerializer: KSerializer<BotAction> {
|
||||
internal object BotActionSerializer: KSerializer<BotAction> {
|
||||
override fun serialize(encoder: Encoder, obj: BotAction) {
|
||||
encoder.encodeString(obj.actionName)
|
||||
}
|
||||
|
||||
override fun deserialize(decoder: Decoder): BotAction {
|
||||
val actionName = decoder.decodeString()
|
||||
return actions.firstOrNull { it.actionName == actionName } ?: throw IllegalStateException("Unknown action type: $actionName")
|
||||
return when (val actionName = decoder.decodeString()) {
|
||||
TypingAction.actionName -> TypingAction
|
||||
UploadPhotoAction.actionName -> UploadPhotoAction
|
||||
RecordVideoAction.actionName -> RecordVideoAction
|
||||
UploadVideoAction.actionName -> UploadVideoAction
|
||||
RecordAudioAction.actionName -> RecordAudioAction
|
||||
UploadAudioAction.actionName -> UploadAudioAction
|
||||
UploadDocumentAction.actionName -> UploadDocumentAction
|
||||
FindLocationAction.actionName -> FindLocationAction
|
||||
else -> throw IllegalStateException("Unknown action type: $actionName")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user