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
|
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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue