From a74066cf626017187dfe716da7ea5e0e13ff40a4 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 6 May 2023 11:38:05 +0600 Subject: [PATCH 1/4] start 7.1.2 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1da1dac2c7..cffb3eb608 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 7.1.2 + ## 7.1.1 * `Versions`: diff --git a/gradle.properties b/gradle.properties index a40b773158..187a1d1c57 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ kotlin.incremental=true kotlin.incremental.js=true library_group=dev.inmo -library_version=7.1.1 +library_version=7.1.2 From 9ede545e56caaba5c42b9c6eebad53d9f340b5a0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 6 May 2023 12:00:08 +0600 Subject: [PATCH 2/4] add serialization of Stickers --- CHANGELOG.md | 3 + .../dev/inmo/tgbotapi/types/files/Sticker.kt | 124 +++++++++++++++--- 2 files changed, 109 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cffb3eb608..df58407553 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 7.1.2 +* `Core`: + * Noe it is possible to serialize `Sticker`s + ## 7.1.1 * `Versions`: diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt index 575dd1fba5..b05bb06971 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt @@ -22,7 +22,7 @@ data class StickerSurrogate( val height: Int, val is_animated: Boolean? = null, val is_video: Boolean? = null, - val thumb: PhotoSize? = null, + val thumbnail: PhotoSize? = null, val emoji: String? = null, val set_name: StickerSetName? = null, val premium_animation: File? = null, @@ -43,6 +43,7 @@ sealed interface Sticker : TelegramMediaFile, SizedMediaFile, ThumbedMediaFile { get() = false val isVideo get() = false + val type: StickerType fun asInputSticker(emojis: List = emoji ?.let { listOf(it) } ?: error("Unable to create input sticker without emojis")): InputSticker } @@ -62,7 +63,7 @@ object StickerSerializer : KSerializer { surrogate.file_unique_id, surrogate.width, surrogate.height, - surrogate.thumb, + surrogate.thumbnail, surrogate.emoji, surrogate.set_name, surrogate.premium_animation, @@ -73,7 +74,7 @@ object StickerSerializer : KSerializer { surrogate.file_unique_id, surrogate.width, surrogate.height, - surrogate.thumb, + surrogate.thumbnail, surrogate.emoji, surrogate.set_name, surrogate.premium_animation, @@ -84,7 +85,7 @@ object StickerSerializer : KSerializer { surrogate.file_unique_id, surrogate.width, surrogate.height, - surrogate.thumb, + surrogate.thumbnail, surrogate.emoji, surrogate.set_name, surrogate.premium_animation, @@ -98,7 +99,7 @@ object StickerSerializer : KSerializer { surrogate.width, surrogate.height, surrogate.mask_position, - surrogate.thumb, + surrogate.thumbnail, surrogate.emoji, surrogate.set_name, surrogate.file_size @@ -109,7 +110,7 @@ object StickerSerializer : KSerializer { surrogate.width, surrogate.height, surrogate.mask_position, - surrogate.thumb, + surrogate.thumbnail, surrogate.emoji, surrogate.set_name, surrogate.file_size @@ -120,7 +121,7 @@ object StickerSerializer : KSerializer { surrogate.width, surrogate.height, surrogate.mask_position, - surrogate.thumb, + surrogate.thumbnail, surrogate.emoji, surrogate.set_name, surrogate.file_size @@ -133,7 +134,7 @@ object StickerSerializer : KSerializer { surrogate.width, surrogate.height, surrogate.custom_emoji_id ?: error("For custom emoji stickers field custom_emoji_id should be presented"), - surrogate.thumb, + surrogate.thumbnail, surrogate.emoji, surrogate.set_name, surrogate.file_size, @@ -145,7 +146,7 @@ object StickerSerializer : KSerializer { surrogate.width, surrogate.height, surrogate.custom_emoji_id ?: error("For custom emoji stickers field custom_emoji_id should be presented"), - surrogate.thumb, + surrogate.thumbnail, surrogate.emoji, surrogate.set_name, surrogate.file_size, @@ -157,7 +158,7 @@ object StickerSerializer : KSerializer { surrogate.width, surrogate.height, surrogate.custom_emoji_id ?: error("For custom emoji stickers field custom_emoji_id should be presented"), - surrogate.thumb, + surrogate.thumbnail, surrogate.emoji, surrogate.set_name, surrogate.file_size, @@ -169,7 +170,7 @@ object StickerSerializer : KSerializer { surrogate.file_unique_id, surrogate.width, surrogate.height, - surrogate.thumb, + surrogate.thumbnail, surrogate.emoji, surrogate.set_name, surrogate.file_size, @@ -178,13 +179,35 @@ object StickerSerializer : KSerializer { surrogate.is_video == true -> StickerFormat.Video else -> StickerFormat.Static }, + surrogate.type, json ) } } override fun serialize(encoder: Encoder, value: Sticker) { - TODO("Not yet implemented") + with(value) { + StickerSurrogate.serializer().serialize( + encoder, + StickerSurrogate( + fileId, + fileUniqueId, + type, + width, + height, + isAnimated, + isVideo, + thumbnail, + emoji, + stickerSetName, + (this as? RegularSticker) ?.premiumAnimationFile, + (this as? MaskSticker) ?.maskPosition, + (this as? CustomEmojiSticker) ?.customEmojiId, + fileSize, + (this as? CustomEmojiSticker) ?.needsRepainting ?: false + ) + ) + } } } @@ -210,6 +233,9 @@ sealed interface AnimatedSticker : Sticker { sealed interface RegularSticker : Sticker { val premiumAnimationFile: File? + override val type: StickerType.Regular + get() = StickerType.Regular + override fun asInputSticker(emojis: List) = InputSticker.WithKeywords.Regular( fileId, emojis, @@ -241,6 +267,11 @@ data class RegularSimpleSticker( @SerialName(stickerFormatField) @EncodeDefault override val stickerFormat: StickerFormat = StickerFormat.Static + @SerialName(stickerTypeField) + @Serializable(StickerType.Serializer::class) + @EncodeDefault + override val type: StickerType.Regular + get() = StickerType.Regular } @Serializable @@ -263,7 +294,13 @@ data class RegularAnimatedSticker( override val premiumAnimationFile: File? = null, @SerialName(fileSizeField) override val fileSize: Long? = null, -) : RegularSticker, AnimatedSticker +) : RegularSticker, AnimatedSticker { + @SerialName(stickerTypeField) + @Serializable(StickerType.Serializer::class) + @EncodeDefault + override val type: StickerType.Regular + get() = StickerType.Regular +} @Serializable data class RegularVideoSticker( @SerialName(fileIdField) @@ -284,13 +321,22 @@ data class RegularVideoSticker( override val premiumAnimationFile: File? = null, @SerialName(fileSizeField) override val fileSize: Long? = null, -) : RegularSticker, VideoSticker +) : RegularSticker, VideoSticker { + @SerialName(stickerTypeField) + @Serializable(StickerType.Serializer::class) + @EncodeDefault + override val type: StickerType.Regular + get() = StickerType.Regular +} @Serializable sealed interface MaskSticker : Sticker { val maskPosition: MaskPosition? + override val type: StickerType.Mask + get() = StickerType.Mask + override fun asInputSticker(emojis: List) = InputSticker.Mask( fileId, emojis, @@ -321,6 +367,12 @@ data class MaskSimpleSticker( @SerialName(stickerFormatField) @EncodeDefault override val stickerFormat: StickerFormat = StickerFormat.Static + + @SerialName(stickerTypeField) + @Serializable(StickerType.Serializer::class) + @EncodeDefault + override val type: StickerType.Mask + get() = StickerType.Mask } @Serializable data class MaskAnimatedSticker( @@ -342,7 +394,13 @@ data class MaskAnimatedSticker( override val stickerSetName: StickerSetName? = null, @SerialName(fileSizeField) override val fileSize: Long? = null, -) : MaskSticker, AnimatedSticker +) : MaskSticker, AnimatedSticker { + @SerialName(stickerTypeField) + @Serializable(StickerType.Serializer::class) + @EncodeDefault + override val type: StickerType.Mask + get() = StickerType.Mask +} @Serializable data class MaskVideoSticker( @SerialName(fileIdField) @@ -363,13 +421,22 @@ data class MaskVideoSticker( override val stickerSetName: StickerSetName? = null, @SerialName(fileSizeField) override val fileSize: Long? = null, -) : MaskSticker, VideoSticker +) : MaskSticker, VideoSticker { + @SerialName(stickerTypeField) + @Serializable(StickerType.Serializer::class) + @EncodeDefault + override val type: StickerType.Mask + get() = StickerType.Mask +} @Serializable sealed interface CustomEmojiSticker : Sticker { val customEmojiId: CustomEmojiId val needsRepainting: Boolean + override val type: StickerType.CustomEmoji + get() = StickerType.CustomEmoji + override fun asInputSticker(emojis: List) = InputSticker.WithKeywords.CustomEmoji( fileId, emojis, @@ -403,6 +470,12 @@ data class CustomEmojiSimpleSticker( @SerialName(stickerFormatField) @EncodeDefault override val stickerFormat: StickerFormat = StickerFormat.Static + + @SerialName(stickerTypeField) + @Serializable(StickerType.Serializer::class) + @EncodeDefault + override val type: StickerType.CustomEmoji + get() = StickerType.CustomEmoji } @Serializable data class CustomEmojiAnimatedSticker( @@ -426,7 +499,13 @@ data class CustomEmojiAnimatedSticker( override val fileSize: Long? = null, @SerialName(needsRepaintingField) override val needsRepainting: Boolean = false, -) : CustomEmojiSticker, AnimatedSticker +) : CustomEmojiSticker, AnimatedSticker { + @SerialName(stickerTypeField) + @Serializable(StickerType.Serializer::class) + @EncodeDefault + override val type: StickerType.CustomEmoji + get() = StickerType.CustomEmoji +} @Serializable data class CustomEmojiVideoSticker( @SerialName(fileIdField) @@ -449,7 +528,13 @@ data class CustomEmojiVideoSticker( override val fileSize: Long? = null, @SerialName(needsRepaintingField) override val needsRepainting: Boolean = false, -) : CustomEmojiSticker, VideoSticker +) : CustomEmojiSticker, VideoSticker { + @SerialName(stickerTypeField) + @Serializable(StickerType.Serializer::class) + @EncodeDefault + override val type: StickerType.CustomEmoji + get() = StickerType.CustomEmoji +} @Serializable data class UnknownSticker( @@ -471,6 +556,9 @@ data class UnknownSticker( override val fileSize: Long? = null, @SerialName(stickerFormatField) override val stickerFormat: StickerFormat = StickerFormat.Static, + @SerialName(stickerTypeField) + @Serializable(StickerType.Serializer::class) + override val type: StickerType = StickerType.Regular, val raw: JsonElement ) : Sticker { override fun asInputSticker(emojis: List) = InputSticker.WithKeywords.Regular( From 6686aef4faf42da863612423e7ac7d43e58ea763 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 6 May 2023 12:25:24 +0600 Subject: [PATCH 3/4] update dependencies in preview mode --- CHANGELOG.md | 5 ++++- gradle/libs.versions.toml | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df58407553..cb664dc79b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,11 @@ ## 7.1.2 +* `Versions`: + * `Coroutines`: `1.6.4` -> `1.7.0` + * `MicroUtils`: `0.18.0` -> `0.18.2` * `Core`: - * Noe it is possible to serialize `Sticker`s + * Now it is possible to serialize `Sticker`s ## 7.1.1 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e8b8d7ddad..3ea2147018 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ kotlin = "1.8.21" kotlin-serialization = "1.5.0" -kotlin-coroutines = "1.6.4" +kotlin-coroutines = "1.7.0" javax-activation = "1.1.1" @@ -11,9 +11,9 @@ uuid = "0.7.0" ktor = "2.3.0" ksp = "1.8.21-1.0.11" -kotlin-poet = "1.13.1" +kotlin-poet = "1.13.2" -microutils = "0.18.0" +microutils = "0.18.2-branch_0.18.2-build474" github-release-plugin = "2.4.1" dokka = "1.8.10" From ced11ab336bdb9913b27e9da4b830f383f2ce257 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 6 May 2023 13:25:27 +0600 Subject: [PATCH 4/4] downgrade microutils and revert coroutines --- CHANGELOG.md | 3 +-- gradle/libs.versions.toml | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb664dc79b..e76cd51097 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,7 @@ ## 7.1.2 * `Versions`: - * `Coroutines`: `1.6.4` -> `1.7.0` - * `MicroUtils`: `0.18.0` -> `0.18.2` + * `MicroUtils`: `0.18.0` -> `0.18.1` * `Core`: * Now it is possible to serialize `Sticker`s diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3ea2147018..26c68c0fcc 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ kotlin = "1.8.21" kotlin-serialization = "1.5.0" -kotlin-coroutines = "1.7.0" +kotlin-coroutines = "1.6.4" javax-activation = "1.1.1" @@ -13,7 +13,7 @@ ktor = "2.3.0" ksp = "1.8.21-1.0.11" kotlin-poet = "1.13.2" -microutils = "0.18.2-branch_0.18.2-build474" +microutils = "0.18.1" github-release-plugin = "2.4.1" dokka = "1.8.10"