[TBA-6.1] Support premium stuff

This commit is contained in:
Maybe Waffle 2022-06-26 19:30:35 +04:00
parent 44e4ead385
commit 46ffd51ec9
8 changed files with 20 additions and 9 deletions

View file

@ -38,7 +38,7 @@ pub struct Animation {
pub mime_type: Option<Mime>, pub mime_type: Option<Mime>,
/// File size in bytes. /// File size in bytes.
pub file_size: Option<u32>, pub file_size: Option<u64>,
} }
#[cfg(test)] #[cfg(test)]

View file

@ -35,7 +35,7 @@ pub struct Audio {
pub mime_type: Option<Mime>, pub mime_type: Option<Mime>,
/// File size in bytes. /// File size in bytes.
pub file_size: Option<u32>, pub file_size: Option<u64>,
/// A thumbnail of the album cover to which the music file belongs. /// A thumbnail of the album cover to which the music file belongs.
pub thumb: Option<PhotoSize>, pub thumb: Option<PhotoSize>,

View file

@ -33,5 +33,5 @@ pub struct Document {
pub mime_type: Option<Mime>, pub mime_type: Option<Mime>,
/// File size in bytes. /// File size in bytes.
pub file_size: Option<u32>, pub file_size: Option<u64>,
} }

View file

@ -27,7 +27,7 @@ pub struct File {
/// errourneusly marked as required in Teloxide. To workaround this issue, /// errourneusly marked as required in Teloxide. To workaround this issue,
/// when `file_size` is not present, it is deserialized as [`u32::MAX`]. /// when `file_size` is not present, it is deserialized as [`u32::MAX`].
#[serde(default = "default_file_size")] #[serde(default = "default_file_size")]
pub file_size: u32, pub file_size: u64,
/// File path. Use [`Bot::download_file(file_path, dst)`] to get the file. /// File path. Use [`Bot::download_file(file_path, dst)`] to get the file.
/// ///
@ -40,8 +40,8 @@ pub struct File {
pub file_path: String, pub file_path: String,
} }
const fn default_file_size() -> u32 { const fn default_file_size() -> u64 {
u32::MAX u64::MAX
} }
#[cfg(test)] #[cfg(test)]
@ -59,7 +59,7 @@ mod tests {
File { File {
file_id: "FILE_ID".to_owned(), file_id: "FILE_ID".to_owned(),
file_unique_id: "FILE_UNIQUE_ID".to_owned(), file_unique_id: "FILE_UNIQUE_ID".to_owned(),
file_size: u32::MAX, file_size: u64::MAX,
file_path: "FILE_PATH".to_owned(), file_path: "FILE_PATH".to_owned(),
} }
); );

View file

@ -66,6 +66,7 @@ mod tests {
last_name: None, last_name: None,
username: Some("SomethingSomethingBot".to_owned()), username: Some("SomethingSomethingBot".to_owned()),
language_code: None, language_code: None,
is_premium: false,
}, },
can_join_groups: false, can_join_groups: false,
can_read_all_group_messages: false, can_read_all_group_messages: false,

View file

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::types::{MaskPosition, PhotoSize}; use crate::types::{File, MaskPosition, PhotoSize};
/// This object represents a sticker. /// This object represents a sticker.
/// ///
@ -41,6 +41,9 @@ pub struct Sticker {
/// Name of the sticker set to which the sticker belongs. /// Name of the sticker set to which the sticker belongs.
pub set_name: Option<String>, pub set_name: Option<String>,
/// Premium animation for the sticker, if the sticker is premium.
pub premium_animation: Option<File>,
/// For mask stickers, the position where the mask should be placed. /// For mask stickers, the position where the mask should be placed.
pub mask_position: Option<MaskPosition>, pub mask_position: Option<MaskPosition>,

View file

@ -27,6 +27,10 @@ pub struct User {
/// ///
/// [IETF language tag]: https://en.wikipedia.org/wiki/IETF_language_tag /// [IETF language tag]: https://en.wikipedia.org/wiki/IETF_language_tag
pub language_code: Option<String>, pub language_code: Option<String>,
/// `true`, if this user is a Telegram Premium user.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub is_premium: bool,
} }
impl User { impl User {
@ -137,6 +141,7 @@ mod tests {
last_name: Some("lastName".to_string()), last_name: Some("lastName".to_string()),
username: Some("Username".to_string()), username: Some("Username".to_string()),
language_code: Some(String::from("ru")), language_code: Some(String::from("ru")),
is_premium: false,
}; };
let actual = serde_json::from_str::<User>(json).unwrap(); let actual = serde_json::from_str::<User>(json).unwrap();
assert_eq!(actual, expected) assert_eq!(actual, expected)
@ -151,6 +156,7 @@ mod tests {
last_name: Some("Last".to_owned()), last_name: Some("Last".to_owned()),
username: Some("aaaaaaaaaaaaaaaa".to_owned()), username: Some("aaaaaaaaaaaaaaaa".to_owned()),
language_code: None, language_code: None,
is_premium: false,
}; };
let user_b = User { let user_b = User {
@ -160,6 +166,7 @@ mod tests {
last_name: None, last_name: None,
username: None, username: None,
language_code: None, language_code: None,
is_premium: false,
}; };
assert_eq!(user_a.full_name(), "First Last"); assert_eq!(user_a.full_name(), "First Last");

View file

@ -37,5 +37,5 @@ pub struct Video {
pub mime_type: Option<Mime>, pub mime_type: Option<Mime>,
/// File size in bytes. /// File size in bytes.
pub file_size: Option<u32>, pub file_size: Option<u64>,
} }