1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +00:00

MediaGroupMemberInputMedia deserialization

This commit is contained in:
InsanusMokrassar 2020-05-10 15:26:07 +06:00
parent 9b16d5d82b
commit e87c4a0126
4 changed files with 17 additions and 3 deletions

View File

@ -58,6 +58,7 @@
* `TelegramBotAPI`: * `TelegramBotAPI`:
* Expected class `MimeType` was added * Expected class `MimeType` was added
* Field `MimeTyped#mimeType` now typed by `MimeType` instead of `String` * Field `MimeTyped#mimeType` now typed by `MimeType` instead of `String`
* `MediaGroupMemberInputMedia` children now can be deserialized (but only those ones who are declared inside library)
### 0.27.1 ### 0.27.1

View File

@ -7,6 +7,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
import kotlinx.serialization.* import kotlinx.serialization.*
internal const val photoInputMediaType = "photo"
@Serializable @Serializable
data class InputMediaPhoto( data class InputMediaPhoto(
override val file: InputFile, override val file: InputFile,
@ -14,7 +16,7 @@ data class InputMediaPhoto(
@SerialName(parseModeField) @SerialName(parseModeField)
override val parseMode: ParseMode? = null override val parseMode: ParseMode? = null
) : InputMedia, MediaGroupMemberInputMedia { ) : InputMedia, MediaGroupMemberInputMedia {
override val type: String = "photo" override val type: String = photoInputMediaType
override fun serialize(format: StringFormat): String = format.stringify(serializer(), this) override fun serialize(format: StringFormat): String = format.stringify(serializer(), this)

View File

@ -6,6 +6,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
import kotlinx.serialization.* import kotlinx.serialization.*
internal const val videoInputMediaType = "video"
@Serializable @Serializable
data class InputMediaVideo( data class InputMediaVideo(
override val file: InputFile, override val file: InputFile,
@ -17,7 +19,7 @@ data class InputMediaVideo(
override val duration: Long? = null, override val duration: Long? = null,
override val thumb: InputFile? = null override val thumb: InputFile? = null
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, MediaGroupMemberInputMedia { ) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, MediaGroupMemberInputMedia {
override val type: String = "video" override val type: String = videoInputMediaType
override fun serialize(format: StringFormat): String = format.stringify(serializer(), this) override fun serialize(format: StringFormat): String = format.stringify(serializer(), this)

View File

@ -1,6 +1,9 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
import com.github.insanusmokrassar.TelegramBotAPI.types.typeField
import com.github.insanusmokrassar.TelegramBotAPI.utils.nonstrictJsonFormat
import kotlinx.serialization.* import kotlinx.serialization.*
import kotlinx.serialization.json.JsonObjectSerializer
@Serializer(MediaGroupMemberInputMedia::class) @Serializer(MediaGroupMemberInputMedia::class)
internal object MediaGroupMemberInputMediaSerializer : KSerializer<MediaGroupMemberInputMedia> { internal object MediaGroupMemberInputMediaSerializer : KSerializer<MediaGroupMemberInputMedia> {
@ -13,6 +16,12 @@ internal object MediaGroupMemberInputMediaSerializer : KSerializer<MediaGroupMem
} }
override fun deserialize(decoder: Decoder): MediaGroupMemberInputMedia { override fun deserialize(decoder: Decoder): MediaGroupMemberInputMedia {
TODO("not implemented") val json = JsonObjectSerializer.deserialize(decoder)
return when (json.getPrimitiveOrNull(typeField) ?.contentOrNull) {
photoInputMediaType -> nonstrictJsonFormat.fromJson(InputMediaPhoto.serializer(), json)
videoInputMediaType -> nonstrictJsonFormat.fromJson(InputMediaVideo.serializer(), json)
else -> error("Illegal type of incoming MediaGroupMemberInputMedia")
}
} }
} }