mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Replace useless structs ChatBoostSource
and ReactionType
with enums
This commit is contained in:
parent
ab069009b5
commit
62000c8204
5 changed files with 50 additions and 78 deletions
|
@ -90,7 +90,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- Add `from_request` and `from_attachment_menu` fields to `WriteAccessAllowed`
|
- Add `from_request` and `from_attachment_menu` fields to `WriteAccessAllowed`
|
||||||
- Support for TBA 7.0 ([#1101](pr1101))
|
- Support for TBA 7.0 ([#1101](pr1101))
|
||||||
- Reactions:
|
- Reactions:
|
||||||
- Add `ReactionType`, `MessageReactionUpdated` and `MessageReactionCountUpdated` structs
|
- Add `ReactionType` enum
|
||||||
|
- Add `MessageReactionUpdated` and `MessageReactionCountUpdated` structs
|
||||||
- Add `MessageReaction` and `MessageReactionCount` variants to `UpdateKind` enum
|
- Add `MessageReaction` and `MessageReactionCount` variants to `UpdateKind` enum
|
||||||
- Add `filter_message_reaction_updated` and `filter_message_reaction_count_updated` filters to `UpdateFilterExt` trait
|
- Add `filter_message_reaction_updated` and `filter_message_reaction_count_updated` filters to `UpdateFilterExt` trait
|
||||||
- Add `set_message_reaction` TBA method to `Requester` trait
|
- Add `set_message_reaction` TBA method to `Requester` trait
|
||||||
|
@ -106,7 +107,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- Multiple Message Actions
|
- Multiple Message Actions
|
||||||
- Add TBA methods `delete_messages`, `forward_messages` and `copy_messages` to `Requester` trait
|
- Add TBA methods `delete_messages`, `forward_messages` and `copy_messages` to `Requester` trait
|
||||||
- Chat Boost
|
- Chat Boost
|
||||||
- Add `ChatBoost`, `ChatBoostSource`, `ChatBoostUpdated`, `ChatBoostRemoved` and `UserChatBoosts` structs
|
- Add `ChatBoostSource` enum
|
||||||
|
- Add `ChatBoost`, `ChatBoostUpdated`, `ChatBoostRemoved` and `UserChatBoosts` structs
|
||||||
- Add `ChatBoost` and `RemovedChatBoost` variants to `UpdateKind` enum
|
- Add `ChatBoost` and `RemovedChatBoost` variants to `UpdateKind` enum
|
||||||
- Add `filter_chat_boost` and `filter_removed_chat_boost` filters to `UpdateFilterExt` trait
|
- Add `filter_chat_boost` and `filter_removed_chat_boost` filters to `UpdateFilterExt` trait
|
||||||
- Add `get_user_chat_boosts` TBA method to `Requester` trait
|
- Add `get_user_chat_boosts` TBA method to `Requester` trait
|
||||||
|
|
|
@ -609,9 +609,7 @@ mod tests {
|
||||||
has_protected_content: None,
|
has_protected_content: None,
|
||||||
}),
|
}),
|
||||||
photo: None,
|
photo: None,
|
||||||
available_reactions: Some(vec![ReactionType {
|
available_reactions: Some(vec![ReactionType::Emoji { emoji: "🌭".to_owned() }]),
|
||||||
kind: ReactionTypeKind::Emoji { emoji: "🌭".to_owned() },
|
|
||||||
}]),
|
|
||||||
pinned_message: None,
|
pinned_message: None,
|
||||||
message_auto_delete_time: None,
|
message_auto_delete_time: None,
|
||||||
has_hidden_members: false,
|
has_hidden_members: false,
|
||||||
|
@ -649,9 +647,7 @@ mod tests {
|
||||||
has_restricted_voice_and_video_messages: None,
|
has_restricted_voice_and_video_messages: None,
|
||||||
}),
|
}),
|
||||||
photo: None,
|
photo: None,
|
||||||
available_reactions: Some(vec![ReactionType {
|
available_reactions: Some(vec![ReactionType::Emoji { emoji: "🌭".to_owned() }]),
|
||||||
kind: ReactionTypeKind::Emoji { emoji: "🌭".to_owned() },
|
|
||||||
}]),
|
|
||||||
pinned_message: None,
|
pinned_message: None,
|
||||||
message_auto_delete_time: None,
|
message_auto_delete_time: None,
|
||||||
has_hidden_members: false,
|
has_hidden_members: false,
|
||||||
|
|
|
@ -3,18 +3,11 @@ use serde::{Deserialize, Serialize};
|
||||||
use crate::types::{MessageId, User};
|
use crate::types::{MessageId, User};
|
||||||
|
|
||||||
/// This object describes the source of a chat boost.
|
/// This object describes the source of a chat boost.
|
||||||
#[serde_with::skip_serializing_none]
|
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
||||||
pub struct ChatBoostSource {
|
|
||||||
#[serde(flatten)]
|
|
||||||
pub kind: ChatBoostSourceKind,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[serde_with::skip_serializing_none]
|
#[serde_with::skip_serializing_none]
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
#[serde(tag = "source")]
|
#[serde(tag = "source")]
|
||||||
pub enum ChatBoostSourceKind {
|
pub enum ChatBoostSource {
|
||||||
Premium(ChatBoostSourcePremium),
|
Premium(ChatBoostSourcePremium),
|
||||||
GiftCode(ChatBoostSourceGiftCode),
|
GiftCode(ChatBoostSourceGiftCode),
|
||||||
Giveaway(ChatBoostSourceGiveaway),
|
Giveaway(ChatBoostSourceGiveaway),
|
||||||
|
@ -62,10 +55,10 @@ pub struct ChatBoostSourceGiveaway {
|
||||||
impl ChatBoostSource {
|
impl ChatBoostSource {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn user(&self) -> Option<&User> {
|
pub fn user(&self) -> Option<&User> {
|
||||||
Some(match &self.kind {
|
Some(match &self {
|
||||||
ChatBoostSourceKind::Premium(premium) => &premium.user,
|
Self::Premium(premium) => &premium.user,
|
||||||
ChatBoostSourceKind::GiftCode(gift_code) => &gift_code.user,
|
Self::GiftCode(gift_code) => &gift_code.user,
|
||||||
ChatBoostSourceKind::Giveaway(giveaway) => return giveaway.user.as_ref(),
|
Self::Giveaway(giveaway) => return giveaway.user.as_ref(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,10 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// The reaction type is based on an emoji.
|
/// The reaction type is based on an emoji or custom emoji.
|
||||||
#[serde_with::skip_serializing_none]
|
|
||||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
|
||||||
pub struct ReactionType {
|
|
||||||
/// Kind of this reaction type - emoji or custom emoji.
|
|
||||||
#[serde(flatten)]
|
|
||||||
pub kind: ReactionTypeKind,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Kind of a [`ReactionType`] - emoji or custom emoji.
|
|
||||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum ReactionTypeKind {
|
pub enum ReactionType {
|
||||||
/// "emoji" or "custom_emoji" reaction
|
/// "emoji" or "custom_emoji" reaction
|
||||||
Emoji {
|
Emoji {
|
||||||
/// Reaction emoji. Currently, it can be one of "👍", "👎", "❤", "🔥",
|
/// Reaction emoji. Currently, it can be one of "👍", "👎", "❤", "🔥",
|
||||||
|
@ -36,16 +27,16 @@ pub enum ReactionTypeKind {
|
||||||
impl ReactionType {
|
impl ReactionType {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn emoji(&self) -> Option<&String> {
|
pub fn emoji(&self) -> Option<&String> {
|
||||||
match &self.kind {
|
match &self {
|
||||||
ReactionTypeKind::Emoji { emoji } => Some(emoji),
|
Self::Emoji { emoji } => Some(emoji),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn custom_emoji_id(&self) -> Option<&String> {
|
pub fn custom_emoji_id(&self) -> Option<&String> {
|
||||||
match &self.kind {
|
match &self {
|
||||||
ReactionTypeKind::CustomEmoji { custom_emoji_id } => Some(custom_emoji_id),
|
Self::CustomEmoji { custom_emoji_id } => Some(custom_emoji_id),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -467,12 +467,12 @@ fn empty_error() -> UpdateKind {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
Chat, ChatBoost, ChatBoostRemoved, ChatBoostSource, ChatBoostSourceKind,
|
Chat, ChatBoost, ChatBoostRemoved, ChatBoostSource, ChatBoostSourcePremium,
|
||||||
ChatBoostSourcePremium, ChatBoostUpdated, ChatFullInfo, ChatId, ChatKind, ChatPrivate,
|
ChatBoostUpdated, ChatFullInfo, ChatId, ChatKind, ChatPrivate, ChatPublic,
|
||||||
ChatPublic, LinkPreviewOptions, MediaKind, MediaText, Message, MessageCommon, MessageId,
|
LinkPreviewOptions, MediaKind, MediaText, Message, MessageCommon, MessageId, MessageKind,
|
||||||
MessageKind, MessageReactionCountUpdated, MessageReactionUpdated, PublicChatChannel,
|
MessageReactionCountUpdated, MessageReactionUpdated, PublicChatChannel, PublicChatKind,
|
||||||
PublicChatKind, PublicChatSupergroup, ReactionCount, ReactionType, ReactionTypeKind,
|
PublicChatSupergroup, ReactionCount, ReactionType, Update, UpdateId, UpdateKind, User,
|
||||||
Update, UpdateId, UpdateKind, User, UserId,
|
UserId,
|
||||||
};
|
};
|
||||||
|
|
||||||
use chrono::DateTime;
|
use chrono::DateTime;
|
||||||
|
@ -901,9 +901,7 @@ mod test {
|
||||||
actor_chat: None,
|
actor_chat: None,
|
||||||
date: DateTime::from_timestamp(1721306082, 0).unwrap(),
|
date: DateTime::from_timestamp(1721306082, 0).unwrap(),
|
||||||
old_reaction: vec![],
|
old_reaction: vec![],
|
||||||
new_reaction: vec![ReactionType {
|
new_reaction: vec![ReactionType::Emoji { emoji: "🌭".to_owned() }],
|
||||||
kind: ReactionTypeKind::Emoji { emoji: "🌭".to_owned() },
|
|
||||||
}],
|
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -971,15 +969,11 @@ mod test {
|
||||||
date: DateTime::from_timestamp(1721306391, 0).unwrap(),
|
date: DateTime::from_timestamp(1721306391, 0).unwrap(),
|
||||||
reactions: vec![
|
reactions: vec![
|
||||||
ReactionCount {
|
ReactionCount {
|
||||||
r#type: ReactionType {
|
r#type: ReactionType::Emoji { emoji: "🗿".to_owned() },
|
||||||
kind: ReactionTypeKind::Emoji { emoji: "🗿".to_owned() },
|
|
||||||
},
|
|
||||||
total_count: 2,
|
total_count: 2,
|
||||||
},
|
},
|
||||||
ReactionCount {
|
ReactionCount {
|
||||||
r#type: ReactionType {
|
r#type: ReactionType::Emoji { emoji: "🌭".to_owned() },
|
||||||
kind: ReactionTypeKind::Emoji { emoji: "🌭".to_owned() },
|
|
||||||
},
|
|
||||||
total_count: 1,
|
total_count: 1,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1048,20 +1042,18 @@ mod test {
|
||||||
boost_id: "4506e1b7e866e33fcbde78fe1746ec3a".to_owned(),
|
boost_id: "4506e1b7e866e33fcbde78fe1746ec3a".to_owned(),
|
||||||
add_date: DateTime::from_timestamp(1721399621, 0).unwrap(),
|
add_date: DateTime::from_timestamp(1721399621, 0).unwrap(),
|
||||||
expiration_date: DateTime::from_timestamp(1745088963, 0).unwrap(),
|
expiration_date: DateTime::from_timestamp(1745088963, 0).unwrap(),
|
||||||
source: ChatBoostSource {
|
source: ChatBoostSource::Premium(ChatBoostSourcePremium {
|
||||||
kind: ChatBoostSourceKind::Premium(ChatBoostSourcePremium {
|
user: User {
|
||||||
user: User {
|
id: UserId(1459074222),
|
||||||
id: UserId(1459074222),
|
is_bot: false,
|
||||||
is_bot: false,
|
first_name: "shadowchain".to_owned(),
|
||||||
first_name: "shadowchain".to_owned(),
|
last_name: None,
|
||||||
last_name: None,
|
username: Some("shdwchn10".to_owned()),
|
||||||
username: Some("shdwchn10".to_owned()),
|
language_code: Some("en".to_owned()),
|
||||||
language_code: Some("en".to_owned()),
|
is_premium: true,
|
||||||
is_premium: true,
|
added_to_attachment_menu: false,
|
||||||
added_to_attachment_menu: false,
|
},
|
||||||
},
|
}),
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
@ -1123,20 +1115,18 @@ mod test {
|
||||||
},
|
},
|
||||||
boost_id: "4506e1b7e866e33fcbde78fe1746ec3a".to_owned(),
|
boost_id: "4506e1b7e866e33fcbde78fe1746ec3a".to_owned(),
|
||||||
remove_date: DateTime::from_timestamp(1721999621, 0).unwrap(),
|
remove_date: DateTime::from_timestamp(1721999621, 0).unwrap(),
|
||||||
source: ChatBoostSource {
|
source: ChatBoostSource::Premium(ChatBoostSourcePremium {
|
||||||
kind: ChatBoostSourceKind::Premium(ChatBoostSourcePremium {
|
user: User {
|
||||||
user: User {
|
id: UserId(1459074222),
|
||||||
id: UserId(1459074222),
|
is_bot: false,
|
||||||
is_bot: false,
|
first_name: "shadowchain".to_owned(),
|
||||||
first_name: "shadowchain".to_owned(),
|
last_name: None,
|
||||||
last_name: None,
|
username: Some("shdwchn10".to_owned()),
|
||||||
username: Some("shdwchn10".to_owned()),
|
language_code: Some("en".to_owned()),
|
||||||
language_code: Some("en".to_owned()),
|
is_premium: true,
|
||||||
is_premium: true,
|
added_to_attachment_menu: false,
|
||||||
added_to_attachment_menu: false,
|
},
|
||||||
},
|
}),
|
||||||
}),
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue