mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2026-09-15 12:34:37 +00:00
Compare commits
6 Commits
15.0.0
...
0d4452d0f5
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d4452d0f5 | |||
| e02f74d77d | |||
| 47a8739db5 | |||
| 760e8b0491 | |||
| fe518a0d8f | |||
| 227849a14c |
@@ -1,5 +1,10 @@
|
||||
# TelegramBotAPI changelog
|
||||
|
||||
## 15.1.0
|
||||
|
||||
* `Version`:
|
||||
* `MicroUtils`: `0.21.1` -> `0.21.2`
|
||||
|
||||
## 15.0.0
|
||||
|
||||
**THIS UPDATE CONTAINS BREAKING CHANGES**
|
||||
|
||||
@@ -24,9 +24,9 @@ plugins {
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
maven { url "https://nexus.inmo.dev/repository/maven-releases/" }
|
||||
mavenCentral()
|
||||
google()
|
||||
maven { url "https://nexus.inmo.dev/repository/maven-releases/" }
|
||||
}
|
||||
if (it != rootProject.findProject("docs")) {
|
||||
tasks.whenTaskAdded { task ->
|
||||
|
||||
@@ -6,4 +6,4 @@ kotlin.incremental=true
|
||||
kotlin.incremental.js=true
|
||||
|
||||
library_group=dev.inmo
|
||||
library_version=15.0.0
|
||||
library_version=15.1.0
|
||||
|
||||
@@ -13,7 +13,7 @@ ktor = "2.3.11"
|
||||
ksp = "1.9.23-1.0.20"
|
||||
kotlin-poet = "1.16.0"
|
||||
|
||||
microutils = "0.21.1"
|
||||
microutils = "0.21.2"
|
||||
kslog = "1.3.4"
|
||||
|
||||
versions = "0.51.0"
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
package dev.inmo.tgbotapi.types.payments.stars
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.files.PhotoSize
|
||||
import dev.inmo.tgbotapi.utils.decodeDataAndJson
|
||||
import kotlinx.serialization.EncodeDefault
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
|
||||
@Serializable(PaidMedia.Companion::class)
|
||||
sealed interface PaidMedia {
|
||||
val type: String
|
||||
|
||||
@Serializable
|
||||
data class Preview(
|
||||
@SerialName(widthField)
|
||||
val width: Int? = null,
|
||||
@SerialName(heightField)
|
||||
val height: Int? = null,
|
||||
@SerialName(durationField)
|
||||
val duration: Int? = null
|
||||
) : PaidMedia {
|
||||
@EncodeDefault
|
||||
@SerialName(typeField)
|
||||
override val type: String = Companion.type
|
||||
|
||||
companion object {
|
||||
val type: String = "preview"
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class Photo(
|
||||
@SerialName(photoField)
|
||||
val photo: Photo
|
||||
) : PaidMedia {
|
||||
@EncodeDefault
|
||||
@SerialName(typeField)
|
||||
override val type: String = Companion.type
|
||||
|
||||
companion object {
|
||||
val type: String = "photo"
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class Video(
|
||||
@SerialName(videoField)
|
||||
val video: Video
|
||||
) : PaidMedia {
|
||||
@EncodeDefault
|
||||
@SerialName(typeField)
|
||||
override val type: String = Companion.type
|
||||
|
||||
companion object {
|
||||
val type: String = "video"
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable(PaidMedia.Companion::class)
|
||||
data class Unknown(
|
||||
@SerialName(typeField)
|
||||
override val type: String,
|
||||
val raw: JsonElement?
|
||||
) : PaidMedia
|
||||
|
||||
companion object : KSerializer<PaidMedia> {
|
||||
@Serializable
|
||||
private class Surrogate(
|
||||
@SerialName(typeField)
|
||||
val type: String,
|
||||
@SerialName(widthField)
|
||||
val width: Int? = null,
|
||||
@SerialName(heightField)
|
||||
val height: Int? = null,
|
||||
@SerialName(durationField)
|
||||
val duration: Int? = null,
|
||||
@SerialName(photoField)
|
||||
val photo: Photo? = null,
|
||||
@SerialName(videoField)
|
||||
val video: Video? = null
|
||||
)
|
||||
|
||||
override val descriptor: SerialDescriptor
|
||||
get() = Surrogate.serializer().descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): PaidMedia {
|
||||
val (data, json) = decoder.decodeDataAndJson(Surrogate.serializer())
|
||||
val unknown by lazy {
|
||||
Unknown(data.type, json)
|
||||
}
|
||||
return when (data.type) {
|
||||
Preview.type -> Preview(
|
||||
data.width,
|
||||
data.height,
|
||||
data.duration
|
||||
)
|
||||
Photo.type -> Photo(
|
||||
data.photo ?: return unknown
|
||||
)
|
||||
Video.type -> Video(
|
||||
data.video ?: return unknown
|
||||
)
|
||||
else -> unknown
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: PaidMedia) {
|
||||
if (value is Unknown && value.raw != null) {
|
||||
JsonElement.serializer().serialize(encoder, value.raw)
|
||||
} else {
|
||||
val surrogate = Surrogate(
|
||||
value.type,
|
||||
(value as? Preview) ?.width,
|
||||
(value as? Preview) ?.height,
|
||||
(value as? Preview) ?.duration,
|
||||
(value as? Photo) ?.photo,
|
||||
(value as? Video) ?.video,
|
||||
)
|
||||
Surrogate.serializer().serialize(encoder, surrogate)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user