From e641baa0a5e88c356587fec7dd8fb511a81e509f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=8B=D1=80=D1=86=D0=B5=D0=B2=20=D0=92=D0=B0=D0=B4?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=98=D0=B3=D0=BE=D1=80=D0=B5=D0=B2=D0=B8=D1=87?= Date: Sun, 9 Jun 2024 18:53:37 +0300 Subject: [PATCH] Remove weird type from Sticker type --- crates/teloxide-core/src/types/sticker.rs | 38 +++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/crates/teloxide-core/src/types/sticker.rs b/crates/teloxide-core/src/types/sticker.rs index 1c4d314b..128ec4dd 100644 --- a/crates/teloxide-core/src/types/sticker.rs +++ b/crates/teloxide-core/src/types/sticker.rs @@ -2,7 +2,7 @@ use std::ops::Deref; use serde::{Deserialize, Serialize}; -use crate::types::{FileMeta, MaskPosition, PhotoSize, True}; +use crate::types::{FileMeta, MaskPosition, PhotoSize}; /// This object represents a sticker. /// @@ -58,7 +58,8 @@ pub struct Sticker { /// True, if the sticker must be repainted to a text color in messages, the /// color of the Telegram Premium badge in emoji status, white color on /// chat photos, or another appropriate color in other places - pub needs_repainting: Option, + #[serde(default)] + pub needs_repainting: bool, } /// Kind of a [`Sticker`] - regular, mask or custom emoji. @@ -431,6 +432,39 @@ mod tests { assert_eq!(sticker, sticker2); } + #[test] + fn regular_serde_with_options() { + let json = r#"{ + "width": 463, + "height": 512, + "is_animated": false, + "is_video": false, + "type": "regular", + "file_id": "CAACAgIAAxUAAWMwcTidRlq7bai-xUkcHQLa6vgJAALZBwACwRieC1FFIeQlHsPdKQQ", + "file_unique_id": "AgAD2QcAAsEYngs", + "file_size": 25734 + }"#; + + let sticker: Sticker = serde_json::from_str(json).unwrap(); + + // Assert some basic properties are correctly deserialized + assert_eq!(sticker.type_(), StickerType::Regular); + assert_eq!(sticker.premium_animation(), None); + assert_eq!(sticker.is_animated(), false); + assert_eq!(sticker.is_video(), false); + assert_eq!(sticker.thumbnail, None); + assert_eq!(sticker.emoji, None); + assert_eq!(sticker.file.size, 25734); + assert_eq!(sticker.width, 463); + assert_eq!(sticker.height, 512); + assert_eq!(sticker.set_name, None); + assert_eq!(sticker.needs_repainting, false); + + let json2 = serde_json::to_string(&sticker).unwrap(); + let sticker2: Sticker = serde_json::from_str(&json2).unwrap(); + assert_eq!(sticker, sticker2); + } + #[test] fn sticker_format_flags_serde() { {