mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 17:52:12 +01:00
Fix Update::user
(return Some
on some forgotten variants)
The following update types now are handled in `Update::user`: - chat join requests - chat members - channel post
This commit is contained in:
parent
7a871b7487
commit
b5bd147c7c
1 changed files with 38 additions and 22 deletions
|
@ -31,32 +31,48 @@ pub struct Update {
|
|||
impl Update {
|
||||
#[must_use]
|
||||
pub fn user(&self) -> Option<&User> {
|
||||
match &self.kind {
|
||||
UpdateKind::Message(m) => m.from(),
|
||||
UpdateKind::EditedMessage(m) => m.from(),
|
||||
UpdateKind::CallbackQuery(query) => Some(&query.from),
|
||||
UpdateKind::ChosenInlineResult(chosen) => Some(&chosen.from),
|
||||
UpdateKind::InlineQuery(query) => Some(&query.from),
|
||||
UpdateKind::ShippingQuery(query) => Some(&query.from),
|
||||
UpdateKind::PreCheckoutQuery(query) => Some(&query.from),
|
||||
UpdateKind::PollAnswer(answer) => Some(&answer.user),
|
||||
_ => None,
|
||||
}
|
||||
use UpdateKind::*;
|
||||
|
||||
let from = match &self.kind {
|
||||
Message(m) | EditedMessage(m) | ChannelPost(m) | EditedChannelPost(m) => m.from()?,
|
||||
|
||||
CallbackQuery(query) => &query.from,
|
||||
ChosenInlineResult(chosen) => &chosen.from,
|
||||
InlineQuery(query) => &query.from,
|
||||
ShippingQuery(query) => &query.from,
|
||||
PreCheckoutQuery(query) => &query.from,
|
||||
PollAnswer(answer) => &answer.user,
|
||||
|
||||
MyChatMember(m) | ChatMember(m) => &m.from,
|
||||
ChatJoinRequest(r) => &r.from,
|
||||
|
||||
Poll(_) | Error(_) => return None,
|
||||
};
|
||||
|
||||
Some(from)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn chat(&self) -> Option<&Chat> {
|
||||
match &self.kind {
|
||||
UpdateKind::Message(m) => Some(&m.chat),
|
||||
UpdateKind::EditedMessage(m) => Some(&m.chat),
|
||||
UpdateKind::ChannelPost(p) => Some(&p.chat),
|
||||
UpdateKind::EditedChannelPost(p) => Some(&p.chat),
|
||||
UpdateKind::CallbackQuery(q) => Some(&q.message.as_ref()?.chat),
|
||||
UpdateKind::ChatMember(m) => Some(&m.chat),
|
||||
UpdateKind::MyChatMember(m) => Some(&m.chat),
|
||||
UpdateKind::ChatJoinRequest(c) => Some(&c.chat),
|
||||
_ => None,
|
||||
}
|
||||
use UpdateKind::*;
|
||||
|
||||
let chat = match &self.kind {
|
||||
Message(m) | EditedMessage(m) | ChannelPost(m) | EditedChannelPost(m) => &m.chat,
|
||||
CallbackQuery(q) => &q.message.as_ref()?.chat,
|
||||
ChatMember(m) => &m.chat,
|
||||
MyChatMember(m) => &m.chat,
|
||||
ChatJoinRequest(c) => &c.chat,
|
||||
|
||||
InlineQuery(_)
|
||||
| ChosenInlineResult(_)
|
||||
| ShippingQuery(_)
|
||||
| PreCheckoutQuery(_)
|
||||
| Poll(_)
|
||||
| PollAnswer(_)
|
||||
| Error(_) => return None,
|
||||
};
|
||||
|
||||
Some(chat)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue