From 693121a6f6b3c56e3babf3270cde81c0339ccada Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 5 Jun 2023 15:38:35 +0400 Subject: [PATCH 01/10] Add `ThreadId` newtype --- crates/teloxide-core/CHANGELOG.md | 2 + crates/teloxide-core/src/types.rs | 2 + crates/teloxide-core/src/types/thread_id.rs | 80 +++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 crates/teloxide-core/src/types/thread_id.rs diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index aac0f5d8..e6008955 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -15,8 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Update::from`, a replacement for `Update::user` ([#850][pr850]) - `Seconds` type, which represents a duration is seconds ([#859][pr859]) - `VideoChatEnded::duration` field that was previously missed ([#859][pr859]) +- `ThreadId` newtype over `MessageId`, used for identifying reply threads ([#887][pr887]) [pr851]: https://github.com/teloxide/teloxide/pull/851 +[pr887]: https://github.com/teloxide/teloxide/pull/887 ### Fixed diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index 27314302..96ae48ea 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -100,6 +100,7 @@ pub use sticker::*; pub use sticker_set::*; pub use successful_payment::*; pub use target_message::*; +pub use thread_id::*; pub use unit_false::*; pub use unit_true::*; pub use update::*; @@ -191,6 +192,7 @@ mod sticker; mod sticker_set; mod successful_payment; mod target_message; +mod thread_id; mod unit_false; mod unit_true; mod update; diff --git a/crates/teloxide-core/src/types/thread_id.rs b/crates/teloxide-core/src/types/thread_id.rs new file mode 100644 index 00000000..2e3f50ac --- /dev/null +++ b/crates/teloxide-core/src/types/thread_id.rs @@ -0,0 +1,80 @@ +use crate::types::MessageId; + +use serde::{Deserialize, Serialize}; + +/// Reply thread identifier. +/// +/// A message that isn't a reply and other messages that reply to it directly or +/// indirectly through a reply chain constitute a reply thread. All messages +/// except the initial root message have an additional [`thread_id`] field that +/// is equal to the root message's id. +/// +/// In other words a thread id can be found recursively following +/// `reply_to_message_id`, until you find a message which does not reply to +/// anything, it's id is the thread id. +/// +/// For example: +/// +/// ```text +/// lizard: Hi {id:17} <-------------+--------------+----+--------------+---------------------+ +/// | | | | | +/// wizard: hewwo {id:18, reply: 17 -+, thread: 17 -+} | | | +/// | | | +/// lizard: I've been wondering [...] {id:19, reply: 17 -+, thread: 17 -+} <---+ | +/// | | +/// neushoorn: wait, did y'all know that [...] {id:20} <-----------------------)--------------)--+-----+ +/// | | | | +/// wizard: so this is not an easy question, actually [...] {id:21, reply: 19 -+, thread: 17 -+} | | +/// +--------+ | +/// | | +/// wizard: everyone knows that, how did you not know that before?... {id:22, reply:20 -+, thread: 20 -+} +/// ``` +/// +/// Note that channel comments and forum topics, reuse threads for different +/// meanings. For channel comments every comment (indirectly) replies to the +/// channel post forwarded to the linked chat (i.e. the forwarded channel post +/// is the root of the comments thread). For forum topics every message in a +/// topic is in the same thread too (i.e. they (indirectly) reply to the start +/// of the topic). +/// +/// [`thread_id`]: crate::types::Message::thread_id +#[derive(Clone, Copy, Debug, derive_more::Display, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[serde(from = "ThreadIdRaw", into = "ThreadIdRaw")] +pub struct ThreadId(/** Identifier of the root message in a reply thread. */ pub MessageId); + +// N.B. this is a hack to [de]serialize `ThreadId`Β as just a number +// we need this since `MessageId` is [de]serialized as `{"message_id":n}`. + +#[derive(Serialize, Deserialize)] +struct ThreadIdRaw(i32); + +impl From for ThreadId { + fn from(ThreadIdRaw(message_id): ThreadIdRaw) -> Self { + ThreadId(MessageId(message_id)) + } +} + +impl From for ThreadIdRaw { + fn from(ThreadId(MessageId(message_id)): ThreadId) -> Self { + ThreadIdRaw(message_id) + } +} + +#[cfg(test)] +mod tests { + use crate::types::{MessageId, ThreadId}; + + #[test] + fn smoke_deser() { + let json = r#"123"#; + let mid: ThreadId = serde_json::from_str(json).unwrap(); + assert_eq!(mid, ThreadId(MessageId(123))); + } + + #[test] + fn smoke_ser() { + let mid: ThreadId = ThreadId(MessageId(123)); + let json = serde_json::to_string(&mid).unwrap(); + assert_eq!(json, r#"123"#); + } +} From 14b3955f6712c68aabd36e5360501efabcbd7424 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 5 Jun 2023 15:43:39 +0400 Subject: [PATCH 02/10] Use `ThreadId` in `Message` and `TopicForum` --- crates/teloxide-core/CHANGELOG.md | 2 ++ crates/teloxide-core/src/types/forum_topic.rs | 6 ++++-- crates/teloxide-core/src/types/message.rs | 5 ++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index e6008955..5878f77d 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -49,6 +49,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 are now defined as named (`struct S {}`) instead of unit (`struct S;`) in order to fix their deserialization ([#876][pr876]) - `Download` now uses GAT feature on the `Fut` and `Err` associated types, instead of a lifetime on the whole trait ([#885][pr885]) - MSRV (Minimal Supported Rust Version) was bumped from `1.64.0` to `1.65.0` +- Renamed `ForumTopic::message_thread_id` into `thread_id` ([#887][pr887]) +- `ForumTopic::thread_id` and `Message::thread_id` now use `ThreadId` instead of `i32` ([#887][pr887]) [pr852]: https://github.com/teloxide/teloxide/pull/853 [pr859]: https://github.com/teloxide/teloxide/pull/859 diff --git a/crates/teloxide-core/src/types/forum_topic.rs b/crates/teloxide-core/src/types/forum_topic.rs index 60c651b7..deeb6b64 100644 --- a/crates/teloxide-core/src/types/forum_topic.rs +++ b/crates/teloxide-core/src/types/forum_topic.rs @@ -1,3 +1,5 @@ +use crate::types::ThreadId; + use serde::{Deserialize, Serialize}; /// This object represents a forum topic. @@ -7,8 +9,8 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct ForumTopic { /// Unique identifier of the forum topic - // FIXME: MessageThreadId or something - pub message_thread_id: i32, + #[serde(rename = "message_thread_id")] + pub thread_id: ThreadId, /// Name of the topic. pub name: String, diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 61796508..bce58b21 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -11,7 +11,7 @@ use crate::types::{ MessageAutoDeleteTimerChanged, MessageEntity, MessageEntityRef, MessageId, PassportData, PhotoSize, Poll, ProximityAlertTriggered, Sticker, SuccessfulPayment, True, User, Venue, Video, VideoChatEnded, VideoChatParticipantsInvited, VideoChatScheduled, VideoChatStarted, VideoNote, - Voice, WebAppData, WriteAccessAllowed, + Voice, WebAppData, WriteAccessAllowed, ThreadId, }; /// This object represents a message. @@ -25,9 +25,8 @@ pub struct Message { /// Unique identifier of a message thread to which the message belongs; for /// supergroups only. - // FIXME: MessageThreadId or such #[serde(rename = "message_thread_id")] - pub thread_id: Option, + pub thread_id: Option, /// Date the message was sent in Unix time. #[serde(with = "crate::types::serde_date_from_unix_timestamp")] From 4a041ac4e0104aabd8347efad056f0333c55b7f0 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 5 Jun 2023 15:55:21 +0400 Subject: [PATCH 03/10] Use `ThreadId` in methods --- crates/teloxide-core/CHANGELOG.md | 1 + crates/teloxide-core/schema.ron | 50 +++++++++---------- crates/teloxide-core/src/adaptors/erased.rs | 20 ++++---- crates/teloxide-core/src/bot/api.rs | 20 +++++--- crates/teloxide-core/src/local_macros.rs | 20 ++++---- .../src/payloads/close_forum_topic.rs | 4 +- .../src/payloads/copy_message.rs | 4 +- .../src/payloads/delete_forum_topic.rs | 4 +- .../src/payloads/edit_forum_topic.rs | 4 +- .../src/payloads/forward_message.rs | 4 +- .../src/payloads/reopen_forum_topic.rs | 4 +- .../src/payloads/send_animation.rs | 4 +- .../teloxide-core/src/payloads/send_audio.rs | 4 +- .../src/payloads/send_chat_action.rs | 4 +- .../src/payloads/send_contact.rs | 4 +- .../teloxide-core/src/payloads/send_dice.rs | 4 +- .../src/payloads/send_document.rs | 4 +- .../teloxide-core/src/payloads/send_game.rs | 4 +- .../src/payloads/send_invoice.rs | 4 +- .../src/payloads/send_location.rs | 4 +- .../src/payloads/send_media_group.rs | 4 +- .../src/payloads/send_message.rs | 6 ++- .../teloxide-core/src/payloads/send_photo.rs | 4 +- .../teloxide-core/src/payloads/send_poll.rs | 4 +- .../src/payloads/send_sticker.rs | 4 +- .../teloxide-core/src/payloads/send_venue.rs | 4 +- .../teloxide-core/src/payloads/send_video.rs | 4 +- .../src/payloads/send_video_note.rs | 4 +- .../teloxide-core/src/payloads/send_voice.rs | 4 +- .../unpin_all_forum_topic_messages.rs | 4 +- .../teloxide-core/src/requests/requester.rs | 22 ++++++-- 31 files changed, 129 insertions(+), 106 deletions(-) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index 5878f77d..40d9a04a 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - MSRV (Minimal Supported Rust Version) was bumped from `1.64.0` to `1.65.0` - Renamed `ForumTopic::message_thread_id` into `thread_id` ([#887][pr887]) - `ForumTopic::thread_id` and `Message::thread_id` now use `ThreadId` instead of `i32` ([#887][pr887]) +- `message_thread_id` method parameters now use `ThreadId` instead of `i32` ([#887][pr887]) [pr852]: https://github.com/teloxide/teloxide/pull/853 [pr859]: https://github.com/teloxide/teloxide/pull/859 diff --git a/crates/teloxide-core/schema.ron b/crates/teloxide-core/schema.ron index 4dfcb368..66a35e33 100644 --- a/crates/teloxide-core/schema.ron +++ b/crates/teloxide-core/schema.ron @@ -232,7 +232,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( @@ -311,7 +311,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( @@ -356,7 +356,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( @@ -440,7 +440,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( @@ -530,7 +530,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( @@ -635,7 +635,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( @@ -733,7 +733,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( @@ -849,7 +849,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( @@ -963,7 +963,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( @@ -1048,7 +1048,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( @@ -1131,7 +1131,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( @@ -1181,7 +1181,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( @@ -1449,7 +1449,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( @@ -1548,7 +1548,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( @@ -1627,7 +1627,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( @@ -1746,7 +1746,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( @@ -1824,7 +1824,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread; supergroups only") ), ], @@ -2626,7 +2626,7 @@ Schema( ), Param( name: "message_thread_id", - ty: i32, + ty: RawTy("ThreadId"), descr: Doc(md: "Unique identifier for the target message thread of the forum topic"), ), Param( @@ -2655,7 +2655,7 @@ Schema( ), Param( name: "message_thread_id", - ty: i32, + ty: RawTy("ThreadId"), descr: Doc(md: "Unique identifier for the target message thread of the forum topic"), ), ], @@ -2674,7 +2674,7 @@ Schema( ), Param( name: "message_thread_id", - ty: i32, + ty: RawTy("ThreadId"), descr: Doc(md: "Unique identifier for the target message thread of the forum topic"), ), ], @@ -2693,7 +2693,7 @@ Schema( ), Param( name: "message_thread_id", - ty: i32, + ty: RawTy("ThreadId"), descr: Doc(md: "Unique identifier for the target message thread of the forum topic"), ), ], @@ -2712,7 +2712,7 @@ Schema( ), Param( name: "message_thread_id", - ty: i32, + ty: RawTy("ThreadId"), descr: Doc(md: "Unique identifier for the target message thread of the forum topic"), ), ], @@ -3411,7 +3411,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( @@ -3669,7 +3669,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( @@ -4026,7 +4026,7 @@ Schema( ), Param( name: "message_thread_id", - ty: Option(i32), + ty: Option(RawTy("ThreadId")), descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), ), Param( diff --git a/crates/teloxide-core/src/adaptors/erased.rs b/crates/teloxide-core/src/adaptors/erased.rs index 05cb03cf..0e5ac1db 100644 --- a/crates/teloxide-core/src/adaptors/erased.rs +++ b/crates/teloxide-core/src/adaptors/erased.rs @@ -628,31 +628,31 @@ trait ErasableRequester<'a> { fn edit_forum_topic( &self, chat_id: Recipient, - message_thread_id: i32, + message_thread_id: ThreadId, ) -> ErasedRequest<'a, EditForumTopic, Self::Err>; fn close_forum_topic( &self, chat_id: Recipient, - message_thread_id: i32, + message_thread_id: ThreadId, ) -> ErasedRequest<'a, CloseForumTopic, Self::Err>; fn reopen_forum_topic( &self, chat_id: Recipient, - message_thread_id: i32, + message_thread_id: ThreadId, ) -> ErasedRequest<'a, ReopenForumTopic, Self::Err>; fn delete_forum_topic( &self, chat_id: Recipient, - message_thread_id: i32, + message_thread_id: ThreadId, ) -> ErasedRequest<'a, DeleteForumTopic, Self::Err>; fn unpin_all_forum_topic_messages( &self, chat_id: Recipient, - message_thread_id: i32, + message_thread_id: ThreadId, ) -> ErasedRequest<'a, UnpinAllForumTopicMessages, Self::Err>; fn edit_general_forum_topic( @@ -1368,7 +1368,7 @@ where fn edit_forum_topic( &self, chat_id: Recipient, - message_thread_id: i32, + message_thread_id: ThreadId, ) -> ErasedRequest<'a, EditForumTopic, Self::Err> { Requester::edit_forum_topic(self, chat_id, message_thread_id).erase() } @@ -1376,7 +1376,7 @@ where fn close_forum_topic( &self, chat_id: Recipient, - message_thread_id: i32, + message_thread_id: ThreadId, ) -> ErasedRequest<'a, CloseForumTopic, Self::Err> { Requester::close_forum_topic(self, chat_id, message_thread_id).erase() } @@ -1384,7 +1384,7 @@ where fn reopen_forum_topic( &self, chat_id: Recipient, - message_thread_id: i32, + message_thread_id: ThreadId, ) -> ErasedRequest<'a, ReopenForumTopic, Self::Err> { Requester::reopen_forum_topic(self, chat_id, message_thread_id).erase() } @@ -1392,7 +1392,7 @@ where fn delete_forum_topic( &self, chat_id: Recipient, - message_thread_id: i32, + message_thread_id: ThreadId, ) -> ErasedRequest<'a, DeleteForumTopic, Self::Err> { Requester::delete_forum_topic(self, chat_id, message_thread_id).erase() } @@ -1400,7 +1400,7 @@ where fn unpin_all_forum_topic_messages( &self, chat_id: Recipient, - message_thread_id: i32, + message_thread_id: ThreadId, ) -> ErasedRequest<'a, UnpinAllForumTopicMessages, Self::Err> { Requester::unpin_all_forum_topic_messages(self, chat_id, message_thread_id).erase() } diff --git a/crates/teloxide-core/src/bot/api.rs b/crates/teloxide-core/src/bot/api.rs index 2fbedee0..1c73485f 100644 --- a/crates/teloxide-core/src/bot/api.rs +++ b/crates/teloxide-core/src/bot/api.rs @@ -6,7 +6,7 @@ use crate::{ requests::{JsonRequest, MultipartRequest}, types::{ BotCommand, ChatId, ChatPermissions, InlineQueryResult, InputFile, InputMedia, - InputSticker, LabeledPrice, MessageId, Recipient, UserId, + InputSticker, LabeledPrice, MessageId, Recipient, ThreadId, UserId, }, Bot, }; @@ -671,7 +671,7 @@ impl Requester for Bot { type EditForumTopic = JsonRequest; - fn edit_forum_topic(&self, chat_id: C, message_thread_id: i32) -> Self::EditForumTopic + fn edit_forum_topic(&self, chat_id: C, message_thread_id: ThreadId) -> Self::EditForumTopic where C: Into, { @@ -683,7 +683,7 @@ impl Requester for Bot { type CloseForumTopic = JsonRequest; - fn close_forum_topic(&self, chat_id: C, message_thread_id: i32) -> Self::CloseForumTopic + fn close_forum_topic(&self, chat_id: C, message_thread_id: ThreadId) -> Self::CloseForumTopic where C: Into, { @@ -695,7 +695,11 @@ impl Requester for Bot { type ReopenForumTopic = JsonRequest; - fn reopen_forum_topic(&self, chat_id: C, message_thread_id: i32) -> Self::ReopenForumTopic + fn reopen_forum_topic( + &self, + chat_id: C, + message_thread_id: ThreadId, + ) -> Self::ReopenForumTopic where C: Into, { @@ -707,7 +711,11 @@ impl Requester for Bot { type DeleteForumTopic = JsonRequest; - fn delete_forum_topic(&self, chat_id: C, message_thread_id: i32) -> Self::DeleteForumTopic + fn delete_forum_topic( + &self, + chat_id: C, + message_thread_id: ThreadId, + ) -> Self::DeleteForumTopic where C: Into, { @@ -722,7 +730,7 @@ impl Requester for Bot { fn unpin_all_forum_topic_messages( &self, chat_id: C, - message_thread_id: i32, + message_thread_id: ThreadId, ) -> Self::UnpinAllForumTopicMessages where C: Into, diff --git a/crates/teloxide-core/src/local_macros.rs b/crates/teloxide-core/src/local_macros.rs index 18b4a103..6b66dfe4 100644 --- a/crates/teloxide-core/src/local_macros.rs +++ b/crates/teloxide-core/src/local_macros.rs @@ -931,41 +931,41 @@ macro_rules! requester_forward { (@method edit_forum_topic $body:ident $ty:ident) => { type EditForumTopic = $ty![EditForumTopic]; - fn edit_forum_topic(&self, chat_id: C, message_thread_id: i32) -> Self::EditForumTopic where C: Into { + fn edit_forum_topic(&self, chat_id: C, message_thread_id: ThreadId) -> Self::EditForumTopic where C: Into { let this = self; - $body!(edit_forum_topic this (chat_id: C, message_thread_id: i32)) + $body!(edit_forum_topic this (chat_id: C, message_thread_id: ThreadId)) } }; (@method close_forum_topic $body:ident $ty:ident) => { type CloseForumTopic = $ty![CloseForumTopic]; - fn close_forum_topic(&self, chat_id: C, message_thread_id: i32) -> Self::CloseForumTopic where C: Into { + fn close_forum_topic(&self, chat_id: C, message_thread_id: ThreadId) -> Self::CloseForumTopic where C: Into { let this = self; - $body!(close_forum_topic this (chat_id: C, message_thread_id: i32)) + $body!(close_forum_topic this (chat_id: C, message_thread_id: ThreadId)) } }; (@method reopen_forum_topic $body:ident $ty:ident) => { type ReopenForumTopic = $ty![ReopenForumTopic]; - fn reopen_forum_topic(&self, chat_id: C, message_thread_id: i32) -> Self::ReopenForumTopic where C: Into { + fn reopen_forum_topic(&self, chat_id: C, message_thread_id: ThreadId) -> Self::ReopenForumTopic where C: Into { let this = self; - $body!(reopen_forum_topic this (chat_id: C, message_thread_id: i32)) + $body!(reopen_forum_topic this (chat_id: C, message_thread_id: ThreadId)) } }; (@method delete_forum_topic $body:ident $ty:ident) => { type DeleteForumTopic = $ty![DeleteForumTopic]; - fn delete_forum_topic(&self, chat_id: C, message_thread_id: i32) -> Self::DeleteForumTopic where C: Into { + fn delete_forum_topic(&self, chat_id: C, message_thread_id: ThreadId) -> Self::DeleteForumTopic where C: Into { let this = self; - $body!(delete_forum_topic this (chat_id: C, message_thread_id: i32)) + $body!(delete_forum_topic this (chat_id: C, message_thread_id: ThreadId)) } }; (@method unpin_all_forum_topic_messages $body:ident $ty:ident) => { type UnpinAllForumTopicMessages = $ty![UnpinAllForumTopicMessages]; - fn unpin_all_forum_topic_messages(&self, chat_id: C, message_thread_id: i32) -> Self::UnpinAllForumTopicMessages where C: Into { + fn unpin_all_forum_topic_messages(&self, chat_id: C, message_thread_id: ThreadId) -> Self::UnpinAllForumTopicMessages where C: Into { let this = self; - $body!(unpin_all_forum_topic_messages this (chat_id: C, message_thread_id: i32)) + $body!(unpin_all_forum_topic_messages this (chat_id: C, message_thread_id: ThreadId)) } }; (@method edit_general_forum_topic $body:ident $ty:ident) => { diff --git a/crates/teloxide-core/src/payloads/close_forum_topic.rs b/crates/teloxide-core/src/payloads/close_forum_topic.rs index 4e3d2674..1f81a7ce 100644 --- a/crates/teloxide-core/src/payloads/close_forum_topic.rs +++ b/crates/teloxide-core/src/payloads/close_forum_topic.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{Recipient, True}; +use crate::types::{Recipient, ThreadId, True}; impl_payload! { /// Use this method to close an open topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the _can\_manage\_topics_ administrator rights, unless it is the creator of the topic. Returns True on success. @@ -12,7 +12,7 @@ impl_payload! { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: Recipient [into], /// Unique identifier for the target message thread of the forum topic - pub message_thread_id: i32, + pub message_thread_id: ThreadId, } } } diff --git a/crates/teloxide-core/src/payloads/copy_message.rs b/crates/teloxide-core/src/payloads/copy_message.rs index ec5e7a9c..479cbae4 100644 --- a/crates/teloxide-core/src/payloads/copy_message.rs +++ b/crates/teloxide-core/src/payloads/copy_message.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{MessageEntity, MessageId, ParseMode, Recipient, ReplyMarkup}; +use crate::types::{MessageEntity, MessageId, ParseMode, Recipient, ReplyMarkup, ThreadId}; impl_payload! { /// Use this method to copy messages of any kind. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the [`MessageId`] of the sent message on success. @@ -21,7 +21,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// New caption for media, 0-1024 characters after entities parsing. If not specified, the original caption is kept pub caption: String [into], /// Mode for parsing entities in the photo caption. See [formatting options] for more details. diff --git a/crates/teloxide-core/src/payloads/delete_forum_topic.rs b/crates/teloxide-core/src/payloads/delete_forum_topic.rs index 05824937..66559272 100644 --- a/crates/teloxide-core/src/payloads/delete_forum_topic.rs +++ b/crates/teloxide-core/src/payloads/delete_forum_topic.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{Recipient, True}; +use crate::types::{Recipient, ThreadId, True}; impl_payload! { /// Use this method to delete a forum topic along with all its messages in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the _can\_delete\_messages_ administrator rights. Returns True on success. @@ -12,7 +12,7 @@ impl_payload! { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: Recipient [into], /// Unique identifier for the target message thread of the forum topic - pub message_thread_id: i32, + pub message_thread_id: ThreadId, } } } diff --git a/crates/teloxide-core/src/payloads/edit_forum_topic.rs b/crates/teloxide-core/src/payloads/edit_forum_topic.rs index dd311dea..cc589913 100644 --- a/crates/teloxide-core/src/payloads/edit_forum_topic.rs +++ b/crates/teloxide-core/src/payloads/edit_forum_topic.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{Recipient, True}; +use crate::types::{Recipient, ThreadId, True}; impl_payload! { /// Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have _can\_manage\_topics_ administrator rights, unless it is the creator of the topic. Returns True on success. @@ -12,7 +12,7 @@ impl_payload! { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: Recipient [into], /// Unique identifier for the target message thread of the forum topic - pub message_thread_id: i32, + pub message_thread_id: ThreadId, } optional { /// Topic name, 0-128 characters. If not specified or empty, the current name of the topic will be kept diff --git a/crates/teloxide-core/src/payloads/forward_message.rs b/crates/teloxide-core/src/payloads/forward_message.rs index 6b49df99..05be2f37 100644 --- a/crates/teloxide-core/src/payloads/forward_message.rs +++ b/crates/teloxide-core/src/payloads/forward_message.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{Message, MessageId, Recipient}; +use crate::types::{Message, MessageId, Recipient, ThreadId}; impl_payload! { /// Use this method to forward messages of any kind. On success, the sent [`Message`] is returned. @@ -21,7 +21,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// Sends the message [silently]. Users will receive a notification with no sound. /// /// [silently]: https://telegram.org/blog/channels-2-0#silent-messages diff --git a/crates/teloxide-core/src/payloads/reopen_forum_topic.rs b/crates/teloxide-core/src/payloads/reopen_forum_topic.rs index 793fb5ac..33adad27 100644 --- a/crates/teloxide-core/src/payloads/reopen_forum_topic.rs +++ b/crates/teloxide-core/src/payloads/reopen_forum_topic.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{Recipient, True}; +use crate::types::{Recipient, ThreadId, True}; impl_payload! { /// Use this method to reopen a closed topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the _can\_manage\_topics_ administrator rights, unless it is the creator of the topic. Returns True on success. @@ -12,7 +12,7 @@ impl_payload! { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: Recipient [into], /// Unique identifier for the target message thread of the forum topic - pub message_thread_id: i32, + pub message_thread_id: ThreadId, } } } diff --git a/crates/teloxide-core/src/payloads/send_animation.rs b/crates/teloxide-core/src/payloads/send_animation.rs index 3c4e487d..a1ee3129 100644 --- a/crates/teloxide-core/src/payloads/send_animation.rs +++ b/crates/teloxide-core/src/payloads/send_animation.rs @@ -3,7 +3,7 @@ use serde::Serialize; use crate::types::{ - InputFile, Message, MessageEntity, MessageId, ParseMode, Recipient, ReplyMarkup, + InputFile, Message, MessageEntity, MessageId, ParseMode, Recipient, ReplyMarkup, ThreadId, }; impl_payload! { @@ -23,7 +23,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// Duration of the animation in seconds pub duration: u32, /// Animation width diff --git a/crates/teloxide-core/src/payloads/send_audio.rs b/crates/teloxide-core/src/payloads/send_audio.rs index 5d01eb8b..2fbfe5f5 100644 --- a/crates/teloxide-core/src/payloads/send_audio.rs +++ b/crates/teloxide-core/src/payloads/send_audio.rs @@ -3,7 +3,7 @@ use serde::Serialize; use crate::types::{ - InputFile, Message, MessageEntity, MessageId, ParseMode, Recipient, ReplyMarkup, + InputFile, Message, MessageEntity, MessageId, ParseMode, Recipient, ReplyMarkup, ThreadId, }; impl_payload! { @@ -26,7 +26,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// Audio caption, 0-1024 characters after entities parsing pub caption: String [into], /// Mode for parsing entities in the audio caption. See [formatting options] for more details. diff --git a/crates/teloxide-core/src/payloads/send_chat_action.rs b/crates/teloxide-core/src/payloads/send_chat_action.rs index 50b4c3db..46726fba 100644 --- a/crates/teloxide-core/src/payloads/send_chat_action.rs +++ b/crates/teloxide-core/src/payloads/send_chat_action.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{ChatAction, Recipient, True}; +use crate::types::{ChatAction, Recipient, ThreadId, True}; impl_payload! { /// Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns True on success. @@ -31,7 +31,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread; supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, } } } diff --git a/crates/teloxide-core/src/payloads/send_contact.rs b/crates/teloxide-core/src/payloads/send_contact.rs index cc8a0c7a..7179cbcc 100644 --- a/crates/teloxide-core/src/payloads/send_contact.rs +++ b/crates/teloxide-core/src/payloads/send_contact.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{Message, MessageId, Recipient, ReplyMarkup}; +use crate::types::{Message, MessageId, Recipient, ReplyMarkup, ThreadId}; impl_payload! { /// Use this method to send phone contacts. On success, the sent [`Message`] is returned. @@ -20,7 +20,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// Contact's last name pub last_name: String [into], /// Additional data about the contact in the form of a [vCard], 0-2048 bytes diff --git a/crates/teloxide-core/src/payloads/send_dice.rs b/crates/teloxide-core/src/payloads/send_dice.rs index 53d1a54c..2a00cbd8 100644 --- a/crates/teloxide-core/src/payloads/send_dice.rs +++ b/crates/teloxide-core/src/payloads/send_dice.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{DiceEmoji, Message, MessageId, Recipient, ReplyMarkup}; +use crate::types::{DiceEmoji, Message, MessageId, Recipient, ReplyMarkup, ThreadId}; impl_payload! { /// Use this method to send an animated emoji that will display a random value. On success, the sent [`Message`] is returned. @@ -16,7 +16,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// Emoji on which the dice throw animation is based. Currently, must be one of β€œπŸŽ²β€, β€œπŸŽ―β€, β€œπŸ€β€, β€œβš½β€, β€œπŸŽ³β€, or β€œπŸŽ°β€. Dice can have values 1-6 for β€œπŸŽ²β€, β€œπŸŽ―β€ and β€œπŸŽ³β€, values 1-5 for β€œπŸ€β€ and β€œβš½β€, and values 1-64 for β€œπŸŽ°β€. Defaults to β€œπŸŽ²β€ pub emoji: DiceEmoji, /// Sends the message [silently]. Users will receive a notification with no sound. diff --git a/crates/teloxide-core/src/payloads/send_document.rs b/crates/teloxide-core/src/payloads/send_document.rs index 06fd9f3c..eda12a07 100644 --- a/crates/teloxide-core/src/payloads/send_document.rs +++ b/crates/teloxide-core/src/payloads/send_document.rs @@ -3,7 +3,7 @@ use serde::Serialize; use crate::types::{ - InputFile, Message, MessageEntity, MessageId, ParseMode, Recipient, ReplyMarkup, + InputFile, Message, MessageEntity, MessageId, ParseMode, Recipient, ReplyMarkup, ThreadId, }; impl_payload! { @@ -23,7 +23,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass β€œattach://” if the thumbnail was uploaded using multipart/form-data under . [More info on Sending Files Β»] /// /// [More info on Sending Files Β»]: crate::types::InputFile diff --git a/crates/teloxide-core/src/payloads/send_game.rs b/crates/teloxide-core/src/payloads/send_game.rs index be7144d0..734cfede 100644 --- a/crates/teloxide-core/src/payloads/send_game.rs +++ b/crates/teloxide-core/src/payloads/send_game.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{Message, ReplyMarkup}; +use crate::types::{Message, ReplyMarkup, ThreadId}; impl_payload! { /// Use this method to send a game. On success, the sent [`Message`] is returned. @@ -18,7 +18,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// Sends the message [silently]. Users will receive a notification with no sound. /// /// [silently]: https://telegram.org/blog/channels-2-0#silent-messages diff --git a/crates/teloxide-core/src/payloads/send_invoice.rs b/crates/teloxide-core/src/payloads/send_invoice.rs index a888f166..0d428229 100644 --- a/crates/teloxide-core/src/payloads/send_invoice.rs +++ b/crates/teloxide-core/src/payloads/send_invoice.rs @@ -3,7 +3,7 @@ use serde::Serialize; use url::Url; -use crate::types::{InlineKeyboardMarkup, LabeledPrice, Message, Recipient}; +use crate::types::{InlineKeyboardMarkup, LabeledPrice, Message, Recipient, ThreadId}; impl_payload! { /// Use this method to send invoices. On success, the sent [`Message`] is returned. @@ -31,7 +31,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// The maximum accepted amount for tips in the smallest units of the currency (integer, **not** float/double). For example, for a maximum tip of `US$ 1.45` pass `max_tip_amount = 145`. See the exp parameter in [`currencies.json`], it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0 /// /// [`currencies.json`]: https://core.telegram.org/bots/payments/currencies.json diff --git a/crates/teloxide-core/src/payloads/send_location.rs b/crates/teloxide-core/src/payloads/send_location.rs index 68b70791..5d61cbe1 100644 --- a/crates/teloxide-core/src/payloads/send_location.rs +++ b/crates/teloxide-core/src/payloads/send_location.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{Message, MessageId, Recipient, ReplyMarkup}; +use crate::types::{Message, MessageId, Recipient, ReplyMarkup, ThreadId}; impl_payload! { /// Use this method to send point on the map. On success, the sent [`Message`] is returned. @@ -20,7 +20,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// The radius of uncertainty for the location, measured in meters; 0-1500 pub horizontal_accuracy: f64, /// Period in seconds for which the location will be updated (see [Live Locations], should be between 60 and 86400. diff --git a/crates/teloxide-core/src/payloads/send_media_group.rs b/crates/teloxide-core/src/payloads/send_media_group.rs index edf224a9..29c40249 100644 --- a/crates/teloxide-core/src/payloads/send_media_group.rs +++ b/crates/teloxide-core/src/payloads/send_media_group.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{InputMedia, Message, MessageId, Recipient}; +use crate::types::{InputMedia, Message, MessageId, Recipient, ThreadId}; impl_payload! { /// Use this method to send a group of photos, videos, documents or audios as an album. Documents and audio files can be only grouped in an album with messages of the same type. On success, an array of [`Message`]s that were sent is returned. @@ -18,7 +18,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// Sends the message [silently]. Users will receive a notification with no sound. /// /// [silently]: https://telegram.org/blog/channels-2-0#silent-messages diff --git a/crates/teloxide-core/src/payloads/send_message.rs b/crates/teloxide-core/src/payloads/send_message.rs index 0b13dd23..b243aec3 100644 --- a/crates/teloxide-core/src/payloads/send_message.rs +++ b/crates/teloxide-core/src/payloads/send_message.rs @@ -2,7 +2,9 @@ use serde::Serialize; -use crate::types::{Message, MessageEntity, MessageId, ParseMode, Recipient, ReplyMarkup}; +use crate::types::{ + Message, MessageEntity, MessageId, ParseMode, Recipient, ReplyMarkup, ThreadId, +}; impl_payload! { /// Use this method to send text messages. On success, the sent [`Message`] is returned. @@ -18,7 +20,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// Mode for parsing entities in the message text. See [formatting options] for more details. /// /// [formatting options]: https://core.telegram.org/bots/api#formatting-options diff --git a/crates/teloxide-core/src/payloads/send_photo.rs b/crates/teloxide-core/src/payloads/send_photo.rs index 70e97bea..0c89cc90 100644 --- a/crates/teloxide-core/src/payloads/send_photo.rs +++ b/crates/teloxide-core/src/payloads/send_photo.rs @@ -3,7 +3,7 @@ use serde::Serialize; use crate::types::{ - InputFile, Message, MessageEntity, MessageId, ParseMode, Recipient, ReplyMarkup, + InputFile, Message, MessageEntity, MessageId, ParseMode, Recipient, ReplyMarkup, ThreadId, }; impl_payload! { @@ -23,7 +23,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// Photo caption (may also be used when resending photos by _file\_id_), 0-1024 characters after entities parsing pub caption: String [into], /// Mode for parsing entities in the photo caption. See [formatting options] for more details. diff --git a/crates/teloxide-core/src/payloads/send_poll.rs b/crates/teloxide-core/src/payloads/send_poll.rs index d346f61c..080b63d2 100644 --- a/crates/teloxide-core/src/payloads/send_poll.rs +++ b/crates/teloxide-core/src/payloads/send_poll.rs @@ -4,7 +4,7 @@ use chrono::{DateTime, Utc}; use serde::Serialize; use crate::types::{ - Message, MessageEntity, MessageId, ParseMode, PollType, Recipient, ReplyMarkup, + Message, MessageEntity, MessageId, ParseMode, PollType, Recipient, ReplyMarkup, ThreadId, }; impl_payload! { @@ -23,7 +23,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// True, if the poll needs to be anonymous, defaults to True pub is_anonymous: bool, /// Poll type, β€œquiz” or β€œregular”, defaults to β€œregular” diff --git a/crates/teloxide-core/src/payloads/send_sticker.rs b/crates/teloxide-core/src/payloads/send_sticker.rs index b677c5ef..7ab3b568 100644 --- a/crates/teloxide-core/src/payloads/send_sticker.rs +++ b/crates/teloxide-core/src/payloads/send_sticker.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{InputFile, Message, Recipient, ReplyMarkup}; +use crate::types::{InputFile, Message, Recipient, ReplyMarkup, ThreadId}; impl_payload! { @[multipart = sticker] @@ -21,7 +21,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// Sends the message [silently]. Users will receive a notification with no sound. /// /// [silently]: https://telegram.org/blog/channels-2-0#silent-messages diff --git a/crates/teloxide-core/src/payloads/send_venue.rs b/crates/teloxide-core/src/payloads/send_venue.rs index 9b88da62..59fcdcbb 100644 --- a/crates/teloxide-core/src/payloads/send_venue.rs +++ b/crates/teloxide-core/src/payloads/send_venue.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{Message, MessageId, Recipient, ReplyMarkup}; +use crate::types::{Message, MessageId, Recipient, ReplyMarkup, ThreadId}; impl_payload! { /// Use this method to send information about a venue. On success, the sent [`Message`] is returned. @@ -24,7 +24,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// Foursquare identifier of the venue pub foursquare_id: String [into], /// Foursquare type of the venue, if known. (For example, β€œarts_entertainment/default”, β€œarts_entertainment/aquarium” or β€œfood/icecream”.) diff --git a/crates/teloxide-core/src/payloads/send_video.rs b/crates/teloxide-core/src/payloads/send_video.rs index 2723e6e4..2c141e8c 100644 --- a/crates/teloxide-core/src/payloads/send_video.rs +++ b/crates/teloxide-core/src/payloads/send_video.rs @@ -3,7 +3,7 @@ use serde::Serialize; use crate::types::{ - InputFile, Message, MessageEntity, MessageId, ParseMode, Recipient, ReplyMarkup, + InputFile, Message, MessageEntity, MessageId, ParseMode, Recipient, ReplyMarkup, ThreadId, }; impl_payload! { @@ -24,7 +24,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// Duration of the video in seconds pub duration: u32, /// Video width diff --git a/crates/teloxide-core/src/payloads/send_video_note.rs b/crates/teloxide-core/src/payloads/send_video_note.rs index f4406d48..787e63cb 100644 --- a/crates/teloxide-core/src/payloads/send_video_note.rs +++ b/crates/teloxide-core/src/payloads/send_video_note.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{InputFile, Message, MessageId, Recipient, ReplyMarkup}; +use crate::types::{InputFile, Message, MessageId, Recipient, ReplyMarkup, ThreadId}; impl_payload! { @[multipart = video_note, thumb] @@ -22,7 +22,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// Duration of the video in seconds pub duration: u32, /// Video width and height, i.e. diameter of the video message diff --git a/crates/teloxide-core/src/payloads/send_voice.rs b/crates/teloxide-core/src/payloads/send_voice.rs index 5d854f52..5e5293ed 100644 --- a/crates/teloxide-core/src/payloads/send_voice.rs +++ b/crates/teloxide-core/src/payloads/send_voice.rs @@ -3,7 +3,7 @@ use serde::Serialize; use crate::types::{ - InputFile, Message, MessageEntity, MessageId, ParseMode, Recipient, ReplyMarkup, + InputFile, Message, MessageEntity, MessageId, ParseMode, Recipient, ReplyMarkup, ThreadId, }; impl_payload! { @@ -25,7 +25,7 @@ impl_payload! { } optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only - pub message_thread_id: i32, + pub message_thread_id: ThreadId, /// Voice message caption, 0-1024 characters after entities parsing pub caption: String [into], /// Mode for parsing entities in the voice message caption. See [formatting options] for more details. diff --git a/crates/teloxide-core/src/payloads/unpin_all_forum_topic_messages.rs b/crates/teloxide-core/src/payloads/unpin_all_forum_topic_messages.rs index 6b0cc7a4..36a839f4 100644 --- a/crates/teloxide-core/src/payloads/unpin_all_forum_topic_messages.rs +++ b/crates/teloxide-core/src/payloads/unpin_all_forum_topic_messages.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{Recipient, True}; +use crate::types::{Recipient, ThreadId, True}; impl_payload! { /// Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the chat for this to work and must have the _can\_pin\_messages_ administrator right in the supergroup. Returns True on success. @@ -12,7 +12,7 @@ impl_payload! { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: Recipient [into], /// Unique identifier for the target message thread of the forum topic - pub message_thread_id: i32, + pub message_thread_id: ThreadId, } } } diff --git a/crates/teloxide-core/src/requests/requester.rs b/crates/teloxide-core/src/requests/requester.rs index 87b9baf1..5336731e 100644 --- a/crates/teloxide-core/src/requests/requester.rs +++ b/crates/teloxide-core/src/requests/requester.rs @@ -678,28 +678,40 @@ pub trait Requester { type EditForumTopic: Request; /// For Telegram documentation see [`EditForumTopic`]. - fn edit_forum_topic(&self, chat_id: C, message_thread_id: i32) -> Self::EditForumTopic + fn edit_forum_topic(&self, chat_id: C, message_thread_id: ThreadId) -> Self::EditForumTopic where C: Into; type CloseForumTopic: Request; /// For Telegram documentation see [`CloseForumTopic`]. - fn close_forum_topic(&self, chat_id: C, message_thread_id: i32) -> Self::CloseForumTopic + fn close_forum_topic( + &self, + chat_id: C, + message_thread_id: ThreadId, + ) -> Self::CloseForumTopic where C: Into; type ReopenForumTopic: Request; /// For Telegram documentation see [`ReopenForumTopic`]. - fn reopen_forum_topic(&self, chat_id: C, message_thread_id: i32) -> Self::ReopenForumTopic + fn reopen_forum_topic( + &self, + chat_id: C, + message_thread_id: ThreadId, + ) -> Self::ReopenForumTopic where C: Into; type DeleteForumTopic: Request; /// For Telegram documentation see [`DeleteForumTopic`]. - fn delete_forum_topic(&self, chat_id: C, message_thread_id: i32) -> Self::DeleteForumTopic + fn delete_forum_topic( + &self, + chat_id: C, + message_thread_id: ThreadId, + ) -> Self::DeleteForumTopic where C: Into; @@ -709,7 +721,7 @@ pub trait Requester { fn unpin_all_forum_topic_messages( &self, chat_id: C, - message_thread_id: i32, + message_thread_id: ThreadId, ) -> Self::UnpinAllForumTopicMessages where C: Into; From 1b7252382f053ce51dde8a211f8f59b561368a73 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 5 Jun 2023 16:04:45 +0400 Subject: [PATCH 04/10] Fixup `Dice` and `DiceEmoji` --- crates/teloxide-core/CHANGELOG.md | 2 ++ crates/teloxide-core/src/types/dice.rs | 10 +++----- crates/teloxide-core/src/types/dice_emoji.rs | 24 ++++++++++---------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index 40d9a04a..772b4978 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -52,6 +52,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Renamed `ForumTopic::message_thread_id` into `thread_id` ([#887][pr887]) - `ForumTopic::thread_id` and `Message::thread_id` now use `ThreadId` instead of `i32` ([#887][pr887]) - `message_thread_id` method parameters now use `ThreadId` instead of `i32` ([#887][pr887]) +- `DiceEmoji` variant order ([#887][pr887]) +- `Dice::value` now use `u8`, instead of `i32` ([#887][pr887]) [pr852]: https://github.com/teloxide/teloxide/pull/853 [pr859]: https://github.com/teloxide/teloxide/pull/859 diff --git a/crates/teloxide-core/src/types/dice.rs b/crates/teloxide-core/src/types/dice.rs index 67f69bbb..72757c65 100644 --- a/crates/teloxide-core/src/types/dice.rs +++ b/crates/teloxide-core/src/types/dice.rs @@ -11,11 +11,7 @@ pub struct Dice { /// Value of the dice. /// - /// 1-6 for [`DiceEmoji::Dice`] and [`DiceEmoji::Darts`], 1-5 for - /// [`DiceEmoji::Basketball`]. - /// - /// [`DiceEmoji::Dice`]: crate::types::DiceEmoji::Dice - /// [`DiceEmoji::Darts`]:crate::types::DiceEmoji::Darts - /// [`DiceEmoji::Basketball`]:crate::types::DiceEmoji::Basketball - pub value: i32, + /// Value of the dice, 1-6 for 🎲, 🎯 and 🎳 base emoji, 1-5 for πŸ€ and ⚽ + /// base emoji, 1-64 for 🎰 base emoji + pub value: u8, } diff --git a/crates/teloxide-core/src/types/dice_emoji.rs b/crates/teloxide-core/src/types/dice_emoji.rs index c5e1a69b..0d73e667 100644 --- a/crates/teloxide-core/src/types/dice_emoji.rs +++ b/crates/teloxide-core/src/types/dice_emoji.rs @@ -2,27 +2,27 @@ use serde::{Deserialize, Serialize}; #[derive(Copy, Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub enum DiceEmoji { - /// Values from 1-6. Defaults to this variant. + /// "🎲" emoji. Values from 1-6. Defaults to this variant. #[serde(rename = "🎲")] Dice, - /// Values from 1-6. + /// "🎯" emoji. Values from 1-6. #[serde(rename = "🎯")] Darts, - /// Values from 1-5. - #[serde(rename = "πŸ€")] - Basketball, - - /// Values 1-5 - #[serde(rename = "⚽")] - Football, - - /// Values 1-5 + /// "🎳" emoji. Values 1-6 #[serde(rename = "🎳")] Bowling, - /// Values 1-64 + /// "πŸ€" emoji. Values from 1-5. + #[serde(rename = "πŸ€")] + Basketball, + + /// "⚽" emoji. Values 1-5 + #[serde(rename = "⚽")] + Football, + + /// "🎰" emoji. Values 1-64 #[serde(rename = "🎰")] SlotMachine, } From 70b9510e33ee43885b20d7198e7f259847bd3d8a Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 5 Jun 2023 17:09:35 +0400 Subject: [PATCH 05/10] Change payment ammounts from `i32` to `u32` --- crates/teloxide-core/CHANGELOG.md | 1 + crates/teloxide-core/src/types/invoice.rs | 2 +- crates/teloxide-core/src/types/label_price.rs | 6 +++--- crates/teloxide-core/src/types/pre_checkout_query.rs | 2 +- crates/teloxide-core/src/types/successful_payment.rs | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index 772b4978..6e2a1a00 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -54,6 +54,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `message_thread_id` method parameters now use `ThreadId` instead of `i32` ([#887][pr887]) - `DiceEmoji` variant order ([#887][pr887]) - `Dice::value` now use `u8`, instead of `i32` ([#887][pr887]) +- `Invoice::total_amount`, `LabeledPrice::amount`, `PreCheckoutQuery::total_amount`, `SuccessfulPayment::total_amout` now use `u32`, instead of `i32` ([#887][pr887]) [pr852]: https://github.com/teloxide/teloxide/pull/853 [pr859]: https://github.com/teloxide/teloxide/pull/859 diff --git a/crates/teloxide-core/src/types/invoice.rs b/crates/teloxide-core/src/types/invoice.rs index b9f2f5b6..122cec3f 100644 --- a/crates/teloxide-core/src/types/invoice.rs +++ b/crates/teloxide-core/src/types/invoice.rs @@ -25,5 +25,5 @@ pub struct Invoice { /// majority of currencies). /// /// [`currencies.json`]: https://core.telegram.org/bots/payments/currencies.json - pub total_amount: i32, + pub total_amount: u32, } diff --git a/crates/teloxide-core/src/types/label_price.rs b/crates/teloxide-core/src/types/label_price.rs index 28cf9b30..41804f41 100644 --- a/crates/teloxide-core/src/types/label_price.rs +++ b/crates/teloxide-core/src/types/label_price.rs @@ -16,11 +16,11 @@ pub struct LabeledPrice { /// /// [currency]: https://core.telegram.org/bots/payments#supported-currencies /// [`currencies.json`]: https://core.telegram.org/bots/payments/currencies.json - pub amount: i32, + pub amount: u32, } impl LabeledPrice { - pub fn new(label: S, amount: i32) -> Self + pub fn new(label: S, amount: u32) -> Self where S: Into, { @@ -36,7 +36,7 @@ impl LabeledPrice { } #[must_use] - pub fn amount(mut self, val: i32) -> Self { + pub fn amount(mut self, val: u32) -> Self { self.amount = val; self } diff --git a/crates/teloxide-core/src/types/pre_checkout_query.rs b/crates/teloxide-core/src/types/pre_checkout_query.rs index 75fb909c..50a94976 100644 --- a/crates/teloxide-core/src/types/pre_checkout_query.rs +++ b/crates/teloxide-core/src/types/pre_checkout_query.rs @@ -26,7 +26,7 @@ pub struct PreCheckoutQuery { /// majority of currencies). /// /// [`currencies.json`]: https://core.telegram.org/bots/payments/currencies.json - pub total_amount: i32, + pub total_amount: u32, /// Bot specified invoice payload. pub invoice_payload: String, diff --git a/crates/teloxide-core/src/types/successful_payment.rs b/crates/teloxide-core/src/types/successful_payment.rs index 270768c4..c35bb9b6 100644 --- a/crates/teloxide-core/src/types/successful_payment.rs +++ b/crates/teloxide-core/src/types/successful_payment.rs @@ -20,7 +20,7 @@ pub struct SuccessfulPayment { /// the majority of currencies). /// /// [`currencies.json`]: https://core.telegram.org/bots/payments/currencies.json - pub total_amount: i32, + pub total_amount: u32, /// Bot specified invoice payload. pub invoice_payload: String, From ad10c939234fc83060f4e307c5dca6a072972765 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 5 Jun 2023 17:20:05 +0400 Subject: [PATCH 06/10] Use `MessageId` for forwards --- crates/teloxide-core/CHANGELOG.md | 1 + crates/teloxide-core/src/types.rs | 36 ++++++++++++++++++++ crates/teloxide-core/src/types/message.rs | 25 ++++++++------ crates/teloxide-core/src/types/message_id.rs | 7 ++++ 4 files changed, 59 insertions(+), 10 deletions(-) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index 6e2a1a00..98ddb797 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -55,6 +55,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `DiceEmoji` variant order ([#887][pr887]) - `Dice::value` now use `u8`, instead of `i32` ([#887][pr887]) - `Invoice::total_amount`, `LabeledPrice::amount`, `PreCheckoutQuery::total_amount`, `SuccessfulPayment::total_amout` now use `u32`, instead of `i32` ([#887][pr887]) +- `Forward::message_id` and `Message::forward_from_message_id` now use `MessageId` instead of `i32` ([#887][pr887]) [pr852]: https://github.com/teloxide/teloxide/pull/853 [pr859]: https://github.com/teloxide/teloxide/pull/859 diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index 96ae48ea..371ab4c4 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -386,6 +386,42 @@ pub(crate) mod option_url_from_string { } } +pub(crate) mod option_msg_id_as_int { + use crate::types::MessageId; + + use serde::{Deserialize, Deserializer, Serialize, Serializer}; + + pub(crate) fn serialize(this: &Option, serializer: S) -> Result + where + S: Serializer, + { + this.map(|MessageId(id)| id).serialize(serializer) + } + + pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> + where + D: Deserializer<'de>, + { + Option::::deserialize(deserializer).map(|r| r.map(MessageId)) + } + + #[test] + fn test() { + #[derive(Serialize, Deserialize)] + struct Struct { + #[serde(with = "crate::types::option_msg_id_as_int")] + id: Option, + } + + { + let json = r#"{"id":123}"#; + let id: Struct = serde_json::from_str(json).unwrap(); + assert_eq!(id.id, Some(MessageId(123))); + assert_eq!(serde_json::to_string(&id).unwrap(), json.to_owned()); + } + } +} + pub(crate) fn serialize_reply_to_message_id( this: &Option, serializer: S, diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index bce58b21..889bfccc 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -9,9 +9,9 @@ use crate::types::{ ForumTopicCreated, ForumTopicEdited, ForumTopicReopened, Game, GeneralForumTopicHidden, GeneralForumTopicUnhidden, InlineKeyboardMarkup, Invoice, Location, MessageAutoDeleteTimerChanged, MessageEntity, MessageEntityRef, MessageId, PassportData, - PhotoSize, Poll, ProximityAlertTriggered, Sticker, SuccessfulPayment, True, User, Venue, Video, - VideoChatEnded, VideoChatParticipantsInvited, VideoChatScheduled, VideoChatStarted, VideoNote, - Voice, WebAppData, WriteAccessAllowed, ThreadId, + PhotoSize, Poll, ProximityAlertTriggered, Sticker, SuccessfulPayment, ThreadId, True, User, + Venue, Video, VideoChatEnded, VideoChatParticipantsInvited, VideoChatScheduled, + VideoChatStarted, VideoNote, Voice, WebAppData, WriteAccessAllowed, }; /// This object represents a message. @@ -290,8 +290,13 @@ pub struct Forward { /// For messages forwarded from channels, identifier of the original message /// in the channel - #[serde(rename = "forward_from_message_id")] - pub message_id: Option, + #[serde( + rename = "forward_from_message_id", + with = "crate::types::option_msg_id_as_int", + default, + skip_serializing_if = "Option::is_none" + )] + pub message_id: Option, } /// The entity that sent the original message that later was forwarded. @@ -614,10 +619,10 @@ mod getters { MediaLocation, MediaPhoto, MediaPoll, MediaSticker, MediaText, MediaVenue, MediaVideo, MediaVideoNote, MediaVoice, Message, MessageChannelChatCreated, MessageCommon, MessageConnectedWebsite, MessageDeleteChatPhoto, MessageDice, MessageEntity, - MessageGroupChatCreated, MessageInvoice, MessageLeftChatMember, MessageNewChatMembers, - MessageNewChatPhoto, MessageNewChatTitle, MessagePassportData, MessagePinned, - MessageProximityAlertTriggered, MessageSuccessfulPayment, MessageSupergroupChatCreated, - MessageVideoChatParticipantsInvited, PhotoSize, True, User, + MessageGroupChatCreated, MessageId, MessageInvoice, MessageLeftChatMember, + MessageNewChatMembers, MessageNewChatPhoto, MessageNewChatTitle, MessagePassportData, + MessagePinned, MessageProximityAlertTriggered, MessageSuccessfulPayment, + MessageSupergroupChatCreated, MessageVideoChatParticipantsInvited, PhotoSize, True, User, }; /// Getters for [Message] fields from [telegram docs]. @@ -696,7 +701,7 @@ mod getters { } #[must_use] - pub fn forward_from_message_id(&self) -> Option { + pub fn forward_from_message_id(&self) -> Option { self.forward().and_then(|f| f.message_id) } diff --git a/crates/teloxide-core/src/types/message_id.rs b/crates/teloxide-core/src/types/message_id.rs index c9c405ae..d0f1212b 100644 --- a/crates/teloxide-core/src/types/message_id.rs +++ b/crates/teloxide-core/src/types/message_id.rs @@ -5,6 +5,13 @@ use serde::{Deserialize, Serialize}; #[serde(from = "MessageIdRaw", into = "MessageIdRaw")] pub struct MessageId(pub i32); +// N.B. we [de]serialize `MessageId` as `{"message_id":n}`, which means that if +// you want just an integer, you need to special case it with something +// like `serde(with = "crate::types::option_msg_id_as_int")]` +// +// (we can't change the default format of `MessageId` because it's returned +// by some methods and we can't change serialization there) + #[derive(Serialize, Deserialize)] struct MessageIdRaw { message_id: i32, From efd801bf2df06903d6e08abd4138023d02ff42de Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 5 Jun 2023 17:21:56 +0400 Subject: [PATCH 07/10] Use `u32` for voter counts in polls and `u8` for option ids --- crates/teloxide-core/CHANGELOG.md | 2 ++ crates/teloxide-core/src/types/poll.rs | 4 ++-- crates/teloxide-core/src/types/poll_answer.rs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index 98ddb797..12b7192e 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -56,6 +56,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Dice::value` now use `u8`, instead of `i32` ([#887][pr887]) - `Invoice::total_amount`, `LabeledPrice::amount`, `PreCheckoutQuery::total_amount`, `SuccessfulPayment::total_amout` now use `u32`, instead of `i32` ([#887][pr887]) - `Forward::message_id` and `Message::forward_from_message_id` now use `MessageId` instead of `i32` ([#887][pr887]) +- `Poll::total_voter_count` and `PollOption::voter_count` now use `u32` instead of `i32` ([#887][pr887]) +- `PollAnswer::option_ids` now use `u8` instead of `i32` ([#887][pr887]) [pr852]: https://github.com/teloxide/teloxide/pull/853 [pr859]: https://github.com/teloxide/teloxide/pull/859 diff --git a/crates/teloxide-core/src/types/poll.rs b/crates/teloxide-core/src/types/poll.rs index e2022647..734b99a2 100644 --- a/crates/teloxide-core/src/types/poll.rs +++ b/crates/teloxide-core/src/types/poll.rs @@ -22,7 +22,7 @@ pub struct Poll { pub is_closed: bool, /// Total number of users that voted in the poll - pub total_voter_count: i32, + pub total_voter_count: u32, /// True, if the poll is anonymous pub is_anonymous: bool, @@ -64,7 +64,7 @@ pub struct PollOption { pub text: String, /// Number of users that voted for this option. - pub voter_count: i32, + pub voter_count: u32, } impl Poll { diff --git a/crates/teloxide-core/src/types/poll_answer.rs b/crates/teloxide-core/src/types/poll_answer.rs index b8f26968..cf17f307 100644 --- a/crates/teloxide-core/src/types/poll_answer.rs +++ b/crates/teloxide-core/src/types/poll_answer.rs @@ -12,5 +12,5 @@ pub struct PollAnswer { /// 0-based identifiers of answer options, chosen by the user. /// /// May be empty if the user retracted their vote. - pub option_ids: Vec, + pub option_ids: Vec, } From 15c742d90b455ad070ff925dfcb06dc91e25b21c Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 5 Jun 2023 17:36:15 +0400 Subject: [PATCH 08/10] Use more precise types in inline query results --- crates/teloxide-core/CHANGELOG.md | 1 + .../src/types/inline_query_result_article.rs | 8 ++++---- .../src/types/inline_query_result_contact.rs | 8 ++++---- .../src/types/inline_query_result_document.rs | 8 ++++---- .../src/types/inline_query_result_gif.rs | 14 +++++++------- .../src/types/inline_query_result_mpeg4_gif.rs | 16 +++++++++------- .../src/types/inline_query_result_photo.rs | 8 ++++---- .../src/types/inline_query_result_venue.rs | 8 ++++---- .../src/types/inline_query_result_video.rs | 14 +++++++------- .../src/types/inline_query_result_voice.rs | 6 +++--- 10 files changed, 47 insertions(+), 44 deletions(-) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index 12b7192e..d81afb58 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -58,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Forward::message_id` and `Message::forward_from_message_id` now use `MessageId` instead of `i32` ([#887][pr887]) - `Poll::total_voter_count` and `PollOption::voter_count` now use `u32` instead of `i32` ([#887][pr887]) - `PollAnswer::option_ids` now use `u8` instead of `i32` ([#887][pr887]) +- Use `u32` for sizes and `Seconds` for timespans in `InlineQueryResult*` ([#887][pr887]) [pr852]: https://github.com/teloxide/teloxide/pull/853 [pr859]: https://github.com/teloxide/teloxide/pull/859 diff --git a/crates/teloxide-core/src/types/inline_query_result_article.rs b/crates/teloxide-core/src/types/inline_query_result_article.rs index 5e0d3be9..132d8f0d 100644 --- a/crates/teloxide-core/src/types/inline_query_result_article.rs +++ b/crates/teloxide-core/src/types/inline_query_result_article.rs @@ -34,10 +34,10 @@ pub struct InlineQueryResultArticle { pub thumb_url: Option, /// Thumbnail width. - pub thumb_width: Option, + pub thumb_width: Option, /// Thumbnail height. - pub thumb_height: Option, + pub thumb_height: Option, } impl InlineQueryResultArticle { @@ -115,13 +115,13 @@ impl InlineQueryResultArticle { } #[must_use] - pub fn thumb_width(mut self, val: i32) -> Self { + pub fn thumb_width(mut self, val: u32) -> Self { self.thumb_width = Some(val); self } #[must_use] - pub fn thumb_height(mut self, val: i32) -> Self { + pub fn thumb_height(mut self, val: u32) -> Self { self.thumb_height = Some(val); self } diff --git a/crates/teloxide-core/src/types/inline_query_result_contact.rs b/crates/teloxide-core/src/types/inline_query_result_contact.rs index 16ae652b..ab1516d9 100644 --- a/crates/teloxide-core/src/types/inline_query_result_contact.rs +++ b/crates/teloxide-core/src/types/inline_query_result_contact.rs @@ -42,10 +42,10 @@ pub struct InlineQueryResultContact { pub thumb_url: Option, /// Thumbnail width. - pub thumb_width: Option, + pub thumb_width: Option, /// Thumbnail height. - pub thumb_height: Option, + pub thumb_height: Option, } impl InlineQueryResultContact { @@ -128,13 +128,13 @@ impl InlineQueryResultContact { } #[must_use] - pub fn thumb_width(mut self, val: i32) -> Self { + pub fn thumb_width(mut self, val: u32) -> Self { self.thumb_width = Some(val); self } #[must_use] - pub fn thumb_height(mut self, val: i32) -> Self { + pub fn thumb_height(mut self, val: u32) -> Self { self.thumb_height = Some(val); self } diff --git a/crates/teloxide-core/src/types/inline_query_result_document.rs b/crates/teloxide-core/src/types/inline_query_result_document.rs index 329f411d..7ca1c100 100644 --- a/crates/teloxide-core/src/types/inline_query_result_document.rs +++ b/crates/teloxide-core/src/types/inline_query_result_document.rs @@ -56,10 +56,10 @@ pub struct InlineQueryResultDocument { pub thumb_url: Option, /// Thumbnail width. - pub thumb_width: Option, + pub thumb_width: Option, /// Thumbnail height. - pub thumb_height: Option, + pub thumb_height: Option, } impl InlineQueryResultDocument { @@ -140,13 +140,13 @@ impl InlineQueryResultDocument { } #[must_use] - pub fn thumb_width(mut self, val: i32) -> Self { + pub fn thumb_width(mut self, val: u32) -> Self { self.thumb_width = Some(val); self } #[must_use] - pub fn thumb_height(mut self, val: i32) -> Self { + pub fn thumb_height(mut self, val: u32) -> Self { self.thumb_height = Some(val); self } diff --git a/crates/teloxide-core/src/types/inline_query_result_gif.rs b/crates/teloxide-core/src/types/inline_query_result_gif.rs index 8c1200f2..02cc7327 100644 --- a/crates/teloxide-core/src/types/inline_query_result_gif.rs +++ b/crates/teloxide-core/src/types/inline_query_result_gif.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode}; +use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode, Seconds}; /// Represents a link to an animated GIF file. /// @@ -19,13 +19,13 @@ pub struct InlineQueryResultGif { pub gif_url: reqwest::Url, /// Width of the GIF. - pub gif_width: Option, + pub gif_width: Option, /// Height of the GIFv. - pub gif_height: Option, + pub gif_height: Option, /// Duration of the GIF. - pub gif_duration: Option, + pub gif_duration: Option, /// URL of the static thumbnail for the result (jpeg or gif). pub thumb_url: reqwest::Url, @@ -93,19 +93,19 @@ impl InlineQueryResultGif { } #[must_use] - pub fn gif_width(mut self, val: i32) -> Self { + pub fn gif_width(mut self, val: u32) -> Self { self.gif_width = Some(val); self } #[must_use] - pub fn gif_height(mut self, val: i32) -> Self { + pub fn gif_height(mut self, val: u32) -> Self { self.gif_height = Some(val); self } #[must_use] - pub fn gif_duration(mut self, val: i32) -> Self { + pub fn gif_duration(mut self, val: Seconds) -> Self { self.gif_duration = Some(val); self } diff --git a/crates/teloxide-core/src/types/inline_query_result_mpeg4_gif.rs b/crates/teloxide-core/src/types/inline_query_result_mpeg4_gif.rs index 134f38f2..75dea28a 100644 --- a/crates/teloxide-core/src/types/inline_query_result_mpeg4_gif.rs +++ b/crates/teloxide-core/src/types/inline_query_result_mpeg4_gif.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode}; +use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode, Seconds}; /// Represents a link to a video animation (H.264/MPEG-4 AVC video without /// sound). @@ -16,17 +16,19 @@ pub struct InlineQueryResultMpeg4Gif { /// Unique identifier for this result, 1-64 bytes. pub id: String, + // FIXME: rename everything so that it doesn't have `mpeg4_` (and similarly for other + // `InlineQueryResult*`) /// A valid URL for the MP4 file. File size must not exceed 1MB. pub mpeg4_url: reqwest::Url, /// Video width. - pub mpeg4_width: Option, + pub mpeg4_width: Option, /// Video height. - pub mpeg4_height: Option, + pub mpeg4_height: Option, /// Video duration. - pub mpeg4_duration: Option, + pub mpeg4_duration: Option, /// URL of the static thumbnail (jpeg or gif) for the result. pub thumb_url: reqwest::Url, @@ -94,19 +96,19 @@ impl InlineQueryResultMpeg4Gif { } #[must_use] - pub fn mpeg4_width(mut self, val: i32) -> Self { + pub fn mpeg4_width(mut self, val: u32) -> Self { self.mpeg4_width = Some(val); self } #[must_use] - pub fn mpeg4_height(mut self, val: i32) -> Self { + pub fn mpeg4_height(mut self, val: u32) -> Self { self.mpeg4_height = Some(val); self } #[must_use] - pub fn mpeg4_duration(mut self, val: i32) -> Self { + pub fn mpeg4_duration(mut self, val: Seconds) -> Self { self.mpeg4_duration = Some(val); self } diff --git a/crates/teloxide-core/src/types/inline_query_result_photo.rs b/crates/teloxide-core/src/types/inline_query_result_photo.rs index 83ca4786..6e3459c3 100644 --- a/crates/teloxide-core/src/types/inline_query_result_photo.rs +++ b/crates/teloxide-core/src/types/inline_query_result_photo.rs @@ -23,10 +23,10 @@ pub struct InlineQueryResultPhoto { pub thumb_url: reqwest::Url, /// Width of the photo. - pub photo_width: Option, + pub photo_width: Option, /// Height of the photo. - pub photo_height: Option, + pub photo_height: Option, /// Title for the result. pub title: Option, @@ -100,13 +100,13 @@ impl InlineQueryResultPhoto { } #[must_use] - pub fn photo_width(mut self, val: i32) -> Self { + pub fn photo_width(mut self, val: u32) -> Self { self.photo_width = Some(val); self } #[must_use] - pub fn photo_height(mut self, val: i32) -> Self { + pub fn photo_height(mut self, val: u32) -> Self { self.photo_height = Some(val); self } diff --git a/crates/teloxide-core/src/types/inline_query_result_venue.rs b/crates/teloxide-core/src/types/inline_query_result_venue.rs index 43f57364..7449f035 100644 --- a/crates/teloxide-core/src/types/inline_query_result_venue.rs +++ b/crates/teloxide-core/src/types/inline_query_result_venue.rs @@ -55,10 +55,10 @@ pub struct InlineQueryResultVenue { pub thumb_url: Option, /// Thumbnail width. - pub thumb_width: Option, + pub thumb_width: Option, /// Thumbnail height. - pub thumb_height: Option, + pub thumb_height: Option, } impl InlineQueryResultVenue { @@ -173,13 +173,13 @@ impl InlineQueryResultVenue { } #[must_use] - pub fn thumb_width(mut self, val: i32) -> Self { + pub fn thumb_width(mut self, val: u32) -> Self { self.thumb_width = Some(val); self } #[must_use] - pub fn thumb_height(mut self, val: i32) -> Self { + pub fn thumb_height(mut self, val: u32) -> Self { self.thumb_height = Some(val); self } diff --git a/crates/teloxide-core/src/types/inline_query_result_video.rs b/crates/teloxide-core/src/types/inline_query_result_video.rs index 1ece1c8c..6dbb4189 100644 --- a/crates/teloxide-core/src/types/inline_query_result_video.rs +++ b/crates/teloxide-core/src/types/inline_query_result_video.rs @@ -1,7 +1,7 @@ use mime::Mime; use serde::{Deserialize, Serialize}; -use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode}; +use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode, Seconds}; /// Represents a link to a page containing an embedded video player or a video /// file. @@ -46,13 +46,13 @@ pub struct InlineQueryResultVideo { pub caption_entities: Option>, /// Video width. - pub video_width: Option, + pub video_width: Option, /// Video height. - pub video_height: Option, + pub video_height: Option, /// Video duration in seconds. - pub video_duration: Option, + pub video_duration: Option, /// Short description of the result. pub description: Option, @@ -158,19 +158,19 @@ impl InlineQueryResultVideo { } #[must_use] - pub fn video_width(mut self, val: i32) -> Self { + pub fn video_width(mut self, val: u32) -> Self { self.video_width = Some(val); self } #[must_use] - pub fn video_height(mut self, val: i32) -> Self { + pub fn video_height(mut self, val: u32) -> Self { self.video_height = Some(val); self } #[must_use] - pub fn video_duration(mut self, val: i32) -> Self { + pub fn video_duration(mut self, val: Seconds) -> Self { self.video_duration = Some(val); self } diff --git a/crates/teloxide-core/src/types/inline_query_result_voice.rs b/crates/teloxide-core/src/types/inline_query_result_voice.rs index c529ae34..d3975dea 100644 --- a/crates/teloxide-core/src/types/inline_query_result_voice.rs +++ b/crates/teloxide-core/src/types/inline_query_result_voice.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode}; +use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode, Seconds}; /// Represents a link to a voice recording in an .ogg container encoded with /// OPUS. @@ -38,7 +38,7 @@ pub struct InlineQueryResultVoice { pub caption_entities: Option>, /// Recording duration in seconds. - pub voice_duration: Option, + pub voice_duration: Option, /// [Inline keyboard] attached to the message. /// @@ -113,7 +113,7 @@ impl InlineQueryResultVoice { } #[must_use] - pub fn voice_duration(mut self, value: i32) -> Self { + pub fn voice_duration(mut self, value: Seconds) -> Self { self.voice_duration = Some(value); self } From 84683d3a356d441015fec71978aa7a61192c724c Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 5 Jun 2023 17:36:37 +0400 Subject: [PATCH 09/10] Remove outdated FIXME --- crates/teloxide-core/src/types/update.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index 82a77e78..de54208a 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -29,8 +29,6 @@ pub struct Update { } impl Update { - // FIXME: add mentioned_users -> impl Iterator<&User> - /// Returns the user that performed the action that caused this update, if /// known. /// From 9c2330897a5819c1e4e30e11ea7c9d894bade4ea Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 5 Jun 2023 17:58:25 +0400 Subject: [PATCH 10/10] Use `MessageId` for `reply_to_message_id` for some methods that were forgotten --- crates/teloxide-core/CHANGELOG.md | 1 + crates/teloxide-core/schema.ron | 6 +++--- crates/teloxide-core/src/payloads/send_game.rs | 5 +++-- crates/teloxide-core/src/payloads/send_invoice.rs | 5 +++-- crates/teloxide-core/src/payloads/send_sticker.rs | 5 +++-- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index d81afb58..6d0f2d73 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -59,6 +59,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Poll::total_voter_count` and `PollOption::voter_count` now use `u32` instead of `i32` ([#887][pr887]) - `PollAnswer::option_ids` now use `u8` instead of `i32` ([#887][pr887]) - Use `u32` for sizes and `Seconds` for timespans in `InlineQueryResult*` ([#887][pr887]) +- `SendGame::reply_to_message_id`, `SendSticker::reply_to_message_id` and `SendInvoice::reply_to_message_id` now use `MessageId` instead of `i32` ([#887][pr887]) [pr852]: https://github.com/teloxide/teloxide/pull/853 [pr859]: https://github.com/teloxide/teloxide/pull/859 diff --git a/crates/teloxide-core/schema.ron b/crates/teloxide-core/schema.ron index 66a35e33..d0519df9 100644 --- a/crates/teloxide-core/schema.ron +++ b/crates/teloxide-core/schema.ron @@ -3437,7 +3437,7 @@ Schema( ), Param( name: "reply_to_message_id", - ty: Option(i32), + ty: Option(RawTy("MessageId")), descr: Doc(md: "If the message is a reply, ID of the original message") ), Param( @@ -3798,7 +3798,7 @@ Schema( ), Param( name: "reply_to_message_id", - ty: Option(i32), + ty: Option(RawTy("MessageId")), descr: Doc(md: "If the message is a reply, ID of the original message") ), Param( @@ -4049,7 +4049,7 @@ Schema( ), Param( name: "reply_to_message_id", - ty: Option(i32), + ty: Option(RawTy("MessageId")), descr: Doc(md: "If the message is a reply, ID of the original message") ), Param( diff --git a/crates/teloxide-core/src/payloads/send_game.rs b/crates/teloxide-core/src/payloads/send_game.rs index 734cfede..551252f2 100644 --- a/crates/teloxide-core/src/payloads/send_game.rs +++ b/crates/teloxide-core/src/payloads/send_game.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{Message, ReplyMarkup, ThreadId}; +use crate::types::{Message, MessageId, ReplyMarkup, ThreadId}; impl_payload! { /// Use this method to send a game. On success, the sent [`Message`] is returned. @@ -26,7 +26,8 @@ impl_payload! { /// Protects the contents of sent messages from forwarding and saving pub protect_content: bool, /// If the message is a reply, ID of the original message - pub reply_to_message_id: i32, + #[serde(serialize_with = "crate::types::serialize_reply_to_message_id")] + pub reply_to_message_id: MessageId, /// Pass _True_, if the message should be sent even if the specified replied-to message is not found pub allow_sending_without_reply: bool, /// A JSON-serialized object for an [inline keyboard]. If empty, one 'Play game_title' button will be shown. If not empty, the first button must launch the game. diff --git a/crates/teloxide-core/src/payloads/send_invoice.rs b/crates/teloxide-core/src/payloads/send_invoice.rs index 0d428229..1156457c 100644 --- a/crates/teloxide-core/src/payloads/send_invoice.rs +++ b/crates/teloxide-core/src/payloads/send_invoice.rs @@ -3,7 +3,7 @@ use serde::Serialize; use url::Url; -use crate::types::{InlineKeyboardMarkup, LabeledPrice, Message, Recipient, ThreadId}; +use crate::types::{InlineKeyboardMarkup, LabeledPrice, Message, MessageId, Recipient, ThreadId}; impl_payload! { /// Use this method to send invoices. On success, the sent [`Message`] is returned. @@ -71,7 +71,8 @@ impl_payload! { /// Protects the contents of sent messages from forwarding and saving pub protect_content: bool, /// If the message is a reply, ID of the original message - pub reply_to_message_id: i32, + #[serde(serialize_with = "crate::types::serialize_reply_to_message_id")] + pub reply_to_message_id: MessageId, /// Pass _True_, if the message should be sent even if the specified replied-to message is not found pub allow_sending_without_reply: bool, /// A JSON-serialized object for an [inline keyboard]. If empty, one 'Pay `total price`' button will be shown. If not empty, the first button must be a Pay button. diff --git a/crates/teloxide-core/src/payloads/send_sticker.rs b/crates/teloxide-core/src/payloads/send_sticker.rs index 7ab3b568..da0d9e57 100644 --- a/crates/teloxide-core/src/payloads/send_sticker.rs +++ b/crates/teloxide-core/src/payloads/send_sticker.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{InputFile, Message, Recipient, ReplyMarkup, ThreadId}; +use crate::types::{InputFile, Message, MessageId, Recipient, ReplyMarkup, ThreadId}; impl_payload! { @[multipart = sticker] @@ -29,7 +29,8 @@ impl_payload! { /// Protects the contents of sent messages from forwarding and saving pub protect_content: bool, /// If the message is a reply, ID of the original message - pub reply_to_message_id: i32, + #[serde(serialize_with = "crate::types::serialize_reply_to_message_id")] + pub reply_to_message_id: MessageId, /// Pass _True_, if the message should be sent even if the specified replied-to message is not found pub allow_sending_without_reply: bool, /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.