Remove impl GetChatId for UpdateKind

This commit is contained in:
Henriquelay 2024-02-08 02:59:53 -03:00
parent 24310df9b3
commit 301f5929ad
No known key found for this signature in database
GPG key ID: 02843DDA217C9D81
2 changed files with 17 additions and 38 deletions

View file

@ -44,7 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `filter_video_chat_ended`
- `filter_video_chat_participants_invited`
- `filter_web_app_data`
- Implement `GetChatId` for `teloxide_core::types::{BotCommandScope, Chat, ChatJoinRequest, ChatMemberUpdated, MessageCommon, Recipient, ResponseParameters, TargetMessage, UpdateKind}`.
- Implement `GetChatId` for `teloxide_core::types::{BotCommandScope, Chat, ChatJoinRequest, ChatMemberUpdated, MessageCommon, Recipient, ResponseParameters, TargetMessage}`.
### Fixed

View file

@ -1,6 +1,6 @@
use crate::types::{
BotCommandScope, CallbackQuery, Chat, ChatId, ChatJoinRequest, ChatMemberUpdated, Message,
MessageCommon, Recipient, ResponseParameters, TargetMessage, Update, UpdateKind,
MessageCommon, Recipient, ResponseParameters, TargetMessage, Update,
};
/// Something that may have a chat ID.
@ -56,28 +56,6 @@ impl GetChatId for Chat {
}
}
impl GetChatId for UpdateKind {
fn chat_id(&self) -> Option<ChatId> {
match self {
UpdateKind::Message(message)
| UpdateKind::EditedMessage(message)
| UpdateKind::ChannelPost(message)
| UpdateKind::EditedChannelPost(message) => GetChatId::chat_id(message),
UpdateKind::CallbackQuery(callback_query) => callback_query.chat_id(),
UpdateKind::MyChatMember(chat_member_updated) => chat_member_updated.chat_id(),
UpdateKind::ChatMember(chat_member_updated) => chat_member_updated.chat_id(),
UpdateKind::ChatJoinRequest(chat_join_request) => chat_join_request.chat_id(),
UpdateKind::InlineQuery(_)
| UpdateKind::ChosenInlineResult(_)
| UpdateKind::ShippingQuery(_)
| UpdateKind::PreCheckoutQuery(_)
| UpdateKind::Poll(_)
| UpdateKind::PollAnswer(_)
| UpdateKind::Error(_) => None,
}
}
}
impl GetChatId for ResponseParameters {
fn chat_id(&self) -> Option<ChatId> {
match self {
@ -96,19 +74,20 @@ impl GetChatId for TargetMessage {
}
}
/// Implements [`GetChatId`] for all types passed in, as long as they have a
/// `chat` field with a `Chat` type
macro_rules! impl_GetChatId_for_chat_field {
// Comma-separated list of types bound to `t`
($($t:ty),* $(,)?) => {
$(
impl GetChatId for $t {
fn chat_id(&self) -> Option<ChatId> {
Some(self.chat.id)
}
}
)*
};
impl GetChatId for Message {
fn chat_id(&self) -> Option<ChatId> {
Some(self.chat.id)
}
}
impl_GetChatId_for_chat_field!(Message, ChatMemberUpdated, ChatJoinRequest);
impl GetChatId for ChatMemberUpdated {
fn chat_id(&self) -> Option<ChatId> {
Some(self.chat.id)
}
}
impl GetChatId for ChatJoinRequest {
fn chat_id(&self) -> Option<ChatId> {
Some(self.chat.id)
}
}