mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Tweak MaybeInaccessibleMessage
This commit is contained in:
parent
0cb716a9ac
commit
3029dcdee6
3 changed files with 6 additions and 9 deletions
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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?;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue