Tweak MaybeInaccessibleMessage

This commit is contained in:
Сырцев Вадим Игоревич 2024-07-31 16:00:25 +03:00 committed by Andrey Brusnik
parent 0cb716a9ac
commit 3029dcdee6
No known key found for this signature in database
GPG key ID: D33232F28CFF442C
3 changed files with 6 additions and 9 deletions

View file

@ -68,7 +68,7 @@ impl CallbackQuery {
self.message self.message
.as_ref() .as_ref()
// If we can access the message // If we can access the message
.and_then(|maybe| maybe.message()) .and_then(|maybe| maybe.regular_message())
} }
} }

View file

@ -21,17 +21,15 @@ impl MaybeInaccessibleMessage {
} }
} }
pub fn message(&self) -> Option<&Message> { #[must_use]
pub fn regular_message(&self) -> Option<&Message> {
match self { match self {
Self::Regular(message) => Some(message), Self::Regular(message) => Some(message),
Self::Inaccessible(_) => None, Self::Inaccessible(_) => None,
} }
} }
pub fn chat_and_id(&self) -> (&Chat, MessageId) { #[must_use]
(self.chat(), self.id())
}
pub fn chat(&self) -> &Chat { pub fn chat(&self) -> &Chat {
match self { match self {
Self::Regular(message) => &message.chat, Self::Regular(message) => &message.chat,

View file

@ -116,9 +116,8 @@ async fn callback_handler(bot: Bot, q: CallbackQuery) -> Result<(), Box<dyn Erro
bot.answer_callback_query(q.id).await?; bot.answer_callback_query(q.id).await?;
// Edit text of the message to which the buttons were attached // Edit text of the message to which the buttons were attached
if let Some(maybe_message) = q.message { if let Some(message) = q.message {
let (chat, id) = maybe_message.chat_and_id(); bot.edit_message_text(message.chat().id, message.id(), text).await?;
bot.edit_message_text(chat.id, id, text).await?;
} else if let Some(id) = q.inline_message_id { } else if let Some(id) = q.inline_message_id {
bot.edit_message_text_inline(id, text).await?; bot.edit_message_text_inline(id, text).await?;
} }