From 301f5929ad4f4a08f25cc65dded0550512a65187 Mon Sep 17 00:00:00 2001 From: Henriquelay <37563861+Henriquelay@users.noreply.github.com> Date: Thu, 8 Feb 2024 02:59:53 -0300 Subject: [PATCH] Remove impl GetChatId for UpdateKind --- CHANGELOG.md | 2 +- .../src/dispatching/dialogue/get_chat_id.rs | 53 ++++++------------- 2 files changed, 17 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b72fa104..25418fef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/crates/teloxide/src/dispatching/dialogue/get_chat_id.rs b/crates/teloxide/src/dispatching/dialogue/get_chat_id.rs index c80bd76a..30f8f41d 100644 --- a/crates/teloxide/src/dispatching/dialogue/get_chat_id.rs +++ b/crates/teloxide/src/dispatching/dialogue/get_chat_id.rs @@ -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 { - 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 { 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 { - Some(self.chat.id) - } - } - )* - }; +impl GetChatId for Message { + fn chat_id(&self) -> Option { + Some(self.chat.id) + } } -impl_GetChatId_for_chat_field!(Message, ChatMemberUpdated, ChatJoinRequest); +impl GetChatId for ChatMemberUpdated { + fn chat_id(&self) -> Option { + Some(self.chat.id) + } +} + +impl GetChatId for ChatJoinRequest { + fn chat_id(&self) -> Option { + Some(self.chat.id) + } +}