1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 16:47:13 +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`:
* Expected class `MimeType` was added
* 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

View File

@ -7,6 +7,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
import kotlinx.serialization.*
internal const val photoInputMediaType = "photo"
@Serializable
data class InputMediaPhoto(
override val file: InputFile,
@ -14,7 +16,7 @@ data class InputMediaPhoto(
@SerialName(parseModeField)
override val parseMode: ParseMode? = null
) : InputMedia, MediaGroupMemberInputMedia {
override val type: String = "photo"
override val type: String = photoInputMediaType
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 kotlinx.serialization.*
internal const val videoInputMediaType = "video"
@Serializable
data class InputMediaVideo(
override val file: InputFile,
@ -17,7 +19,7 @@ data class InputMediaVideo(
override val duration: Long? = null,
override val thumb: InputFile? = null
) : 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)

View File

@ -1,6 +1,9 @@
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.json.JsonObjectSerializer
@Serializer(MediaGroupMemberInputMedia::class)
internal object MediaGroupMemberInputMediaSerializer : KSerializer<MediaGroupMemberInputMedia> {
@ -13,6 +16,12 @@ internal object MediaGroupMemberInputMediaSerializer : KSerializer<MediaGroupMem
}
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")
}
}
}