Remove useless impl, order diff

This commit is contained in:
Henriquelay 2024-03-05 22:19:53 -03:00
parent 301f5929ad
commit 69874823d7
No known key found for this signature in database
GPG key ID: 02843DDA217C9D81
2 changed files with 7 additions and 36 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_ended`
- `filter_video_chat_participants_invited` - `filter_video_chat_participants_invited`
- `filter_web_app_data` - `filter_web_app_data`
- Implement `GetChatId` for `teloxide_core::types::{BotCommandScope, Chat, ChatJoinRequest, ChatMemberUpdated, MessageCommon, Recipient, ResponseParameters, TargetMessage}`. - Implement `GetChatId` for `teloxide_core::types::{Chat, ChatJoinRequest, ChatMemberUpdated, Recipient, TargetMessage}`.
### Fixed ### Fixed

View file

@ -1,6 +1,6 @@
use crate::types::{ use crate::types::{
BotCommandScope, CallbackQuery, Chat, ChatId, ChatJoinRequest, ChatMemberUpdated, Message, CallbackQuery, Chat, ChatId, ChatJoinRequest, ChatMemberUpdated, Message,
MessageCommon, Recipient, ResponseParameters, TargetMessage, Update, Recipient, TargetMessage, Update,
}; };
/// Something that may have a chat ID. /// Something that may have a chat ID.
@ -9,15 +9,15 @@ pub trait GetChatId {
fn chat_id(&self) -> Option<ChatId>; fn chat_id(&self) -> Option<ChatId>;
} }
impl GetChatId for CallbackQuery { impl GetChatId for Message {
fn chat_id(&self) -> Option<ChatId> { fn chat_id(&self) -> Option<ChatId> {
self.message.as_ref().map(|mes| mes.chat.id) Some(self.chat.id)
} }
} }
impl GetChatId for MessageCommon { impl GetChatId for CallbackQuery {
fn chat_id(&self) -> Option<ChatId> { fn chat_id(&self) -> Option<ChatId> {
self.sender_chat.as_ref().map(|chat| chat.id) self.message.as_ref().map(|mes| mes.chat.id)
} }
} }
@ -36,35 +36,12 @@ impl GetChatId for Recipient {
} }
} }
impl GetChatId for BotCommandScope {
fn chat_id(&self) -> Option<ChatId> {
match self {
BotCommandScope::Default
| BotCommandScope::AllPrivateChats
| BotCommandScope::AllGroupChats
| BotCommandScope::AllChatAdministrators => None,
BotCommandScope::Chat { chat_id: recipient }
| BotCommandScope::ChatAdministrators { chat_id: recipient }
| BotCommandScope::ChatMember { chat_id: recipient, .. } => recipient.chat_id(),
}
}
}
impl GetChatId for Chat { impl GetChatId for Chat {
fn chat_id(&self) -> Option<ChatId> { fn chat_id(&self) -> Option<ChatId> {
Some(self.id) Some(self.id)
} }
} }
impl GetChatId for ResponseParameters {
fn chat_id(&self) -> Option<ChatId> {
match self {
ResponseParameters::MigrateToChatId(chat_id) => Some(*chat_id),
ResponseParameters::RetryAfter(_) => None,
}
}
}
impl GetChatId for TargetMessage { impl GetChatId for TargetMessage {
fn chat_id(&self) -> Option<ChatId> { fn chat_id(&self) -> Option<ChatId> {
match self { match self {
@ -74,12 +51,6 @@ impl GetChatId for TargetMessage {
} }
} }
impl GetChatId for Message {
fn chat_id(&self) -> Option<ChatId> {
Some(self.chat.id)
}
}
impl GetChatId for ChatMemberUpdated { impl GetChatId for ChatMemberUpdated {
fn chat_id(&self) -> Option<ChatId> { fn chat_id(&self) -> Option<ChatId> {
Some(self.chat.id) Some(self.chat.id)