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
.as_ref()
// 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 {
Self::Regular(message) => Some(message),
Self::Inaccessible(_) => None,
}
}
pub fn chat_and_id(&self) -> (&Chat, MessageId) {
(self.chat(), self.id())
}
#[must_use]
pub fn chat(&self) -> &Chat {
match self {
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?;
// Edit text of the message to which the buttons were attached
if let Some(maybe_message) = q.message {
let (chat, id) = maybe_message.chat_and_id();
bot.edit_message_text(chat.id, id, text).await?;
if let Some(message) = q.message {
bot.edit_message_text(message.chat().id, message.id(), text).await?;
} else if let Some(id) = q.inline_message_id {
bot.edit_message_text_inline(id, text).await?;
}