Wrap Public variant of ChatKind in Box

This commit is contained in:
Akshett Rai Jindal 2024-08-22 01:18:16 +05:30
parent 057a37cea0
commit c9eec050d0
5 changed files with 47 additions and 31 deletions

View file

@ -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

View file

@ -63,7 +63,7 @@ pub struct Chat {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ChatKind {
Public(ChatPublic),
Public(Box<ChatPublic>),
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,

View file

@ -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,

View file

@ -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,

View file

@ -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,