From c9eec050d0fcd0b451ed9ca1cbe6516d6cd973ae Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Thu, 22 Aug 2024 01:18:16 +0530 Subject: [PATCH] Wrap `Public` variant of `ChatKind` in `Box` --- crates/teloxide-core/CHANGELOG.md | 7 ++++++ crates/teloxide-core/src/types/chat.rs | 27 +++++++++++++++-------- crates/teloxide-core/src/types/message.rs | 24 ++++++++++---------- crates/teloxide-core/src/types/story.rs | 4 ++-- crates/teloxide-core/src/types/update.rs | 16 +++++++------- 5 files changed, 47 insertions(+), 31 deletions(-) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index 618d2ba4..a6ff75df 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -59,6 +59,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [pr1146]: https://github.com/teloxide/teloxide/pull/1146 +### Breaking Changes + +- Support for TBA 7.2 ([#1146](pr1146)) + - Wrap `Public` variant of `ChatKind` in `Box` + +[pr1146]: https://github.com/teloxide/teloxide/pull/1146 + ## 0.10.1 - 2024-08-17 ### Fixed diff --git a/crates/teloxide-core/src/types/chat.rs b/crates/teloxide-core/src/types/chat.rs index 1ae99527..f9e94d9c 100644 --- a/crates/teloxide-core/src/types/chat.rs +++ b/crates/teloxide-core/src/types/chat.rs @@ -63,7 +63,7 @@ pub struct Chat { #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum ChatKind { - Public(ChatPublic), + Public(Box), Private(ChatPrivate), } @@ -286,20 +286,29 @@ impl Chat { #[must_use] pub fn is_group(&self) -> bool { - matches!(self.kind, ChatKind::Public(ChatPublic { kind: PublicChatKind::Group(_), .. })) + if let ChatKind::Public(chat_pub) = &self.kind { + matches!(**chat_pub, ChatPublic { kind: PublicChatKind::Group(_), .. }) + } else { + false + } } #[must_use] pub fn is_supergroup(&self) -> bool { - matches!( - self.kind, - ChatKind::Public(ChatPublic { kind: PublicChatKind::Supergroup(_), .. }) - ) + if let ChatKind::Public(chat_pub) = &self.kind { + matches!(**chat_pub, ChatPublic { kind: PublicChatKind::Supergroup(_), .. }) + } else { + false + } } #[must_use] pub fn is_channel(&self) -> bool { - matches!(self.kind, ChatKind::Public(ChatPublic { kind: PublicChatKind::Channel(_), .. })) + if let ChatKind::Public(chat_pub) = &self.kind { + matches!(**chat_pub, ChatPublic { kind: PublicChatKind::Channel(_), .. }) + } else { + false + } } #[must_use] @@ -698,7 +707,7 @@ mod tests { fn channel_de() { let expected = Chat { id: ChatId(-1), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: None, kind: PublicChatKind::Channel(PublicChatChannel { username: Some("channel_name".into()), @@ -707,7 +716,7 @@ mod tests { description: None, invite_link: None, has_protected_content: None, - }), + })), photo: None, available_reactions: Some(vec![ReactionType::Emoji { emoji: "🌭".to_owned() }]), pinned_message: None, diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 3c28604b..cea0a3d1 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -2134,7 +2134,7 @@ mod tests { let group = Chat { id: ChatId(-1001160242915), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("a".to_owned()), kind: PublicChatKind::Supergroup(PublicChatSupergroup { username: None, @@ -2154,7 +2154,7 @@ mod tests { description: None, invite_link: None, has_protected_content: None, - }), + })), message_auto_delete_time: None, photo: None, available_reactions: None, @@ -2439,7 +2439,7 @@ mod tests { &Giveaway { chats: vec![Chat { id: ChatId(-1002236736395), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("Test".to_owned()), kind: PublicChatKind::Channel(PublicChatChannel { username: None, @@ -2448,7 +2448,7 @@ mod tests { description: None, invite_link: None, has_protected_content: None - }), + })), photo: None, available_reactions: None, pinned_message: None, @@ -2548,7 +2548,7 @@ mod tests { from: None, sender_chat: Some(Chat { id: ChatId(-1002236736395), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("Test".to_owned()), kind: PublicChatKind::Channel(PublicChatChannel { linked_chat_id: None, @@ -2557,7 +2557,7 @@ mod tests { description: None, invite_link: None, has_protected_content: None - }), + })), chat_full_info: ChatFullInfo::default(), available_reactions: None, photo: None, @@ -2570,7 +2570,7 @@ mod tests { date: DateTime::from_timestamp(1721161230, 0).unwrap(), chat: Chat { id: ChatId(-1002236736395), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("Test".to_owned()), kind: PublicChatKind::Channel(PublicChatChannel { username: None, @@ -2579,7 +2579,7 @@ mod tests { description: None, invite_link: None, has_protected_content: None - }), + })), photo: None, available_reactions: None, pinned_message: None, @@ -2595,7 +2595,7 @@ mod tests { giveaway: Giveaway { chats: vec![Chat { id: ChatId(-1002236736395), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("Test".to_owned()), kind: PublicChatKind::Channel(PublicChatChannel { username: None, @@ -2604,7 +2604,7 @@ mod tests { description: None, invite_link: None, has_protected_content: None - }), + })), photo: None, available_reactions: None, pinned_message: None, @@ -2696,7 +2696,7 @@ mod tests { &GiveawayWinners { chat: Chat { id: ChatId(-1002236736395), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("Test".to_owned()), kind: PublicChatKind::Channel(PublicChatChannel { username: None, @@ -2705,7 +2705,7 @@ mod tests { description: None, invite_link: None, has_protected_content: None - }), + })), photo: None, available_reactions: None, pinned_message: None, diff --git a/crates/teloxide-core/src/types/story.rs b/crates/teloxide-core/src/types/story.rs index 41ac32c5..abe63eac 100644 --- a/crates/teloxide-core/src/types/story.rs +++ b/crates/teloxide-core/src/types/story.rs @@ -44,7 +44,7 @@ mod tests { let story = Story { chat: Chat { id: ChatId(-1001389841361), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("GNOME".to_owned()), kind: PublicChatKind::Supergroup(PublicChatSupergroup { username: Some("gnome_ru".to_owned()), @@ -64,7 +64,7 @@ mod tests { description: None, invite_link: None, has_protected_content: None, - }), + })), photo: None, available_reactions: None, pinned_message: None, diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index 50f0daa1..6af03fba 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -930,7 +930,7 @@ mod test { kind: UpdateKind::MessageReaction(MessageReactionUpdated { chat: Chat { id: ChatId(-1002184233434), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("Test".to_owned()), kind: PublicChatKind::Supergroup(PublicChatSupergroup { username: None, @@ -950,7 +950,7 @@ mod test { description: None, invite_link: None, has_protected_content: None, - }), + })), photo: None, available_reactions: None, pinned_message: None, @@ -1090,7 +1090,7 @@ mod test { kind: UpdateKind::MessageReactionCount(MessageReactionCountUpdated { chat: Chat { id: ChatId(-1002236736395), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("Test".to_owned()), kind: PublicChatKind::Channel(PublicChatChannel { username: None, @@ -1099,7 +1099,7 @@ mod test { description: None, invite_link: None, has_protected_content: None, - }), + })), photo: None, available_reactions: None, pinned_message: None, @@ -1163,7 +1163,7 @@ mod test { kind: UpdateKind::ChatBoost(ChatBoostUpdated { chat: Chat { id: ChatId(-1002236736395), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("Test".to_owned()), kind: PublicChatKind::Channel(PublicChatChannel { username: None, @@ -1172,7 +1172,7 @@ mod test { description: None, invite_link: None, has_protected_content: None, - }), + })), photo: None, available_reactions: None, pinned_message: None, @@ -1238,7 +1238,7 @@ mod test { kind: UpdateKind::RemovedChatBoost(ChatBoostRemoved { chat: Chat { id: ChatId(-1002236736395), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("Test".to_owned()), kind: PublicChatKind::Channel(PublicChatChannel { username: None, @@ -1247,7 +1247,7 @@ mod test { description: None, invite_link: None, has_protected_content: None, - }), + })), photo: None, available_reactions: None, pinned_message: None,