diff --git a/crates/teloxide-core/src/types/animation.rs b/crates/teloxide-core/src/types/animation.rs index b583cce9..183f3b9e 100644 --- a/crates/teloxide-core/src/types/animation.rs +++ b/crates/teloxide-core/src/types/animation.rs @@ -1,7 +1,7 @@ use mime::Mime; use serde::{Deserialize, Serialize}; -use crate::types::{FileMeta, PhotoSize}; +use crate::types::{FileMeta, PhotoSize, Seconds}; /// This object represents an animation file (GIF or H.264/MPEG-4 AVC video /// without sound). @@ -21,7 +21,7 @@ pub struct Animation { pub height: u32, /// A duration of the video in seconds as defined by a sender. - pub duration: u32, + pub duration: Seconds, /// An animation thumbnail as defined by a sender. pub thumb: Option, @@ -62,7 +62,7 @@ mod tests { file: FileMeta { id: "id".to_string(), unique_id: "".to_string(), size: 6500 }, width: 320, height: 320, - duration: 59, + duration: Seconds::from_seconds(59), thumb: Some(PhotoSize { file: FileMeta { id: "id".to_owned(), unique_id: "".to_owned(), size: 3452 }, width: 320, diff --git a/crates/teloxide-core/src/types/audio.rs b/crates/teloxide-core/src/types/audio.rs index 87b0505e..dcdca901 100644 --- a/crates/teloxide-core/src/types/audio.rs +++ b/crates/teloxide-core/src/types/audio.rs @@ -1,7 +1,7 @@ use mime::Mime; use serde::{Deserialize, Serialize}; -use crate::types::{FileMeta, PhotoSize}; +use crate::types::{FileMeta, PhotoSize, Seconds}; /// This object represents an audio file to be treated as music by the Telegram /// clients. @@ -15,7 +15,7 @@ pub struct Audio { pub file: FileMeta, /// A duration of the audio in seconds as defined by a sender. - pub duration: u32, + pub duration: Seconds, /// A performer of the audio as defined by a sender or by audio tags. pub performer: Option, @@ -36,7 +36,7 @@ pub struct Audio { #[cfg(test)] mod tests { - use crate::types::FileMeta; + use crate::types::{FileMeta, Seconds}; use super::*; @@ -60,7 +60,7 @@ mod tests { }"#; let expected = Audio { file: FileMeta { id: "id".to_string(), unique_id: "".to_string(), size: 123_456 }, - duration: 60, + duration: Seconds::from_seconds(60), performer: Some("Performer".to_string()), title: Some("Title".to_string()), mime_type: Some("application/zip".parse().unwrap()), diff --git a/crates/teloxide-core/src/types/chat.rs b/crates/teloxide-core/src/types/chat.rs index 8dbb4d8d..2bd38dd9 100644 --- a/crates/teloxide-core/src/types/chat.rs +++ b/crates/teloxide-core/src/types/chat.rs @@ -1,6 +1,8 @@ use serde::{Deserialize, Serialize}; -use crate::types::{ChatId, ChatLocation, ChatPermissions, ChatPhoto, Message, True, User}; +use crate::types::{ + ChatId, ChatLocation, ChatPermissions, ChatPhoto, Message, Seconds, True, User, +}; /// This object represents a chat. /// @@ -29,7 +31,7 @@ pub struct Chat { /// deleted; in seconds. Returned only in [`GetChat`]. /// /// [`GetChat`]: crate::payloads::GetChat - pub message_auto_delete_time: Option, + pub message_auto_delete_time: Option, /// `true`, if non-administrators can only get the list of bots and /// administrators in the chat. Returned only in [`GetChat`]. @@ -202,7 +204,7 @@ pub struct PublicChatSupergroup { /// unpriviledged user. Returned only from [`GetChat`]. /// /// [`GetChat`]: crate::payloads::GetChat - pub slow_mode_delay: Option, + pub slow_mode_delay: Option, /// Unique identifier for the linked chat, i.e. the discussion group /// identifier for a channel and vice versa. Returned only in [`GetChat`]. @@ -355,7 +357,7 @@ impl Chat { /// /// [`GetChat`]: crate::payloads::GetChat #[must_use] - pub fn slow_mode_delay(&self) -> Option { + pub fn slow_mode_delay(&self) -> Option { if let ChatKind::Public(this) = &self.kind { if let PublicChatKind::Supergroup(this) = &this.kind { return this.slow_mode_delay; diff --git a/crates/teloxide-core/src/types/inline_query_result_location.rs b/crates/teloxide-core/src/types/inline_query_result_location.rs index aa8d6a66..5838085a 100644 --- a/crates/teloxide-core/src/types/inline_query_result_location.rs +++ b/crates/teloxide-core/src/types/inline_query_result_location.rs @@ -29,7 +29,7 @@ pub struct InlineQueryResultLocation { /// Period in seconds for which the location can be updated, should be /// between 60 and 86400. - pub live_period: Option, + pub live_period: Option, /// For live locations, a direction in which the user is moving, in degrees. /// Must be between 1 and 360 if specified. @@ -116,7 +116,7 @@ impl InlineQueryResultLocation { } #[must_use] - pub fn live_period(mut self, val: i32) -> Self { + pub fn live_period(mut self, val: u32) -> Self { self.live_period = Some(val); self } diff --git a/crates/teloxide-core/src/types/location.rs b/crates/teloxide-core/src/types/location.rs index eb417c52..d8e224ef 100644 --- a/crates/teloxide-core/src/types/location.rs +++ b/crates/teloxide-core/src/types/location.rs @@ -1,5 +1,7 @@ use serde::{Deserialize, Serialize}; +use crate::types::Seconds; + /// This object represents a point on the map. #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Location { @@ -14,7 +16,7 @@ pub struct Location { /// Time relative to the message sending date, during which the location can /// be updated, in seconds. For active live locations only. - pub live_period: Option, + pub live_period: Option, /// The direction in which user is moving, in degrees; 1-360. For active /// live locations only. diff --git a/crates/teloxide-core/src/types/message_auto_delete_timer_changed.rs b/crates/teloxide-core/src/types/message_auto_delete_timer_changed.rs index 0e24be5a..f8878beb 100644 --- a/crates/teloxide-core/src/types/message_auto_delete_timer_changed.rs +++ b/crates/teloxide-core/src/types/message_auto_delete_timer_changed.rs @@ -1,9 +1,11 @@ use serde::{Deserialize, Serialize}; +use crate::types::Seconds; + /// This object represents a service message about a change in auto-delete timer /// settings. #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct MessageAutoDeleteTimerChanged { /// New auto-delete time for messages in the chat - pub message_auto_delete_time: u32, + pub message_auto_delete_time: Seconds, } diff --git a/crates/teloxide-core/src/types/poll.rs b/crates/teloxide-core/src/types/poll.rs index 7725c961..e2022647 100644 --- a/crates/teloxide-core/src/types/poll.rs +++ b/crates/teloxide-core/src/types/poll.rs @@ -1,4 +1,4 @@ -use crate::types::{MessageEntity, PollType, User}; +use crate::types::{MessageEntity, PollType, Seconds, User}; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; @@ -48,7 +48,7 @@ pub struct Poll { pub explanation_entities: Option>, /// Amount of time in seconds the poll will be active after creation. - pub open_period: Option, + pub open_period: Option, /// Point in time when the poll will be automatically closed. #[serde(default, with = "crate::types::serde_opt_date_from_unix_timestamp")] diff --git a/crates/teloxide-core/src/types/response_parameters.rs b/crates/teloxide-core/src/types/response_parameters.rs index b792a626..8a68437b 100644 --- a/crates/teloxide-core/src/types/response_parameters.rs +++ b/crates/teloxide-core/src/types/response_parameters.rs @@ -1,7 +1,7 @@ -use std::time::Duration; - use serde::{Deserialize, Serialize}; +use crate::types::{ChatId, Seconds}; + /// Contains information about why a request was unsuccessful. /// /// [The official docs](https://core.telegram.org/bots/api#responseparameters). @@ -9,25 +9,22 @@ use serde::{Deserialize, Serialize}; #[serde(rename_all = "snake_case")] pub enum ResponseParameters { /// The group has been migrated to a supergroup with the specified - /// identifier. This number may be greater than 32 bits and some - /// programming languages may have difficulty/silent defects in - /// interpreting it. But it is smaller than 52 bits, so a signed 64 bit - /// integer or double-precision float type are safe for storing this /// identifier. - MigrateToChatId(i64), + MigrateToChatId(ChatId), /// In case of exceeding flood control, the number of seconds left to wait /// before the request can be repeated. - RetryAfter(#[serde(with = "crate::types::duration_secs")] Duration), + RetryAfter(Seconds), } #[cfg(test)] mod tests { use super::*; + use crate::types::{ChatId, Seconds}; #[test] fn migrate_to_chat_id_deserialization() { - let expected = ResponseParameters::MigrateToChatId(123_456); + let expected = ResponseParameters::MigrateToChatId(ChatId(123_456)); let actual: ResponseParameters = serde_json::from_str(r#"{"migrate_to_chat_id":123456}"#).unwrap(); @@ -36,7 +33,7 @@ mod tests { #[test] fn retry_after_deserialization() { - let expected = ResponseParameters::RetryAfter(Duration::from_secs(123_456)); + let expected = ResponseParameters::RetryAfter(Seconds::from_seconds(123_456)); let actual: ResponseParameters = serde_json::from_str(r#"{"retry_after":123456}"#).unwrap(); assert_eq!(expected, actual); diff --git a/crates/teloxide-core/src/types/video.rs b/crates/teloxide-core/src/types/video.rs index e127167b..f6d12b65 100644 --- a/crates/teloxide-core/src/types/video.rs +++ b/crates/teloxide-core/src/types/video.rs @@ -1,7 +1,7 @@ use mime::Mime; use serde::{Deserialize, Serialize}; -use crate::types::{FileMeta, PhotoSize}; +use crate::types::{FileMeta, PhotoSize, Seconds}; /// This object represents a video file. /// @@ -20,7 +20,7 @@ pub struct Video { pub height: u32, /// Duration of the video in seconds as defined by sender. - pub duration: u32, + pub duration: Seconds, /// Video thumbnail. pub thumb: Option, diff --git a/crates/teloxide-core/src/types/video_chat_ended.rs b/crates/teloxide-core/src/types/video_chat_ended.rs index 96775afd..99edaf9d 100644 --- a/crates/teloxide-core/src/types/video_chat_ended.rs +++ b/crates/teloxide-core/src/types/video_chat_ended.rs @@ -1,6 +1,11 @@ use serde::{Deserialize, Serialize}; +use crate::types::Seconds; + /// This object represents a service message about a video chat ended in the /// chat. #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] -pub struct VideoChatEnded {} +pub struct VideoChatEnded { + /// Video chat duration in seconds. + duration: Seconds, +} diff --git a/crates/teloxide-core/src/types/video_note.rs b/crates/teloxide-core/src/types/video_note.rs index d112c672..2c14b681 100644 --- a/crates/teloxide-core/src/types/video_note.rs +++ b/crates/teloxide-core/src/types/video_note.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::types::{FileMeta, PhotoSize}; +use crate::types::{FileMeta, PhotoSize, Seconds}; /// This object represents a [video message] (available in Telegram apps as of /// [v.4.0]). @@ -21,7 +21,7 @@ pub struct VideoNote { pub length: u32, /// Duration of the video in seconds as defined by sender. - pub duration: u32, + pub duration: Seconds, /// Video thumbnail. pub thumb: Option, diff --git a/crates/teloxide-core/src/types/voice.rs b/crates/teloxide-core/src/types/voice.rs index 0dbcd7b8..9501b9b8 100644 --- a/crates/teloxide-core/src/types/voice.rs +++ b/crates/teloxide-core/src/types/voice.rs @@ -1,7 +1,7 @@ use mime::Mime; use serde::{Deserialize, Serialize}; -use crate::types::FileMeta; +use crate::types::{FileMeta, Seconds}; /// This object represents a voice note. /// @@ -14,7 +14,7 @@ pub struct Voice { pub file: FileMeta, /// Duration of the audio in seconds as defined by sender. - pub duration: u32, + pub duration: Seconds, /// MIME type of the file as defined by sender. #[serde(with = "crate::types::non_telegram_types::mime::opt_deser")]