mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 09:49:07 +01:00
changed type of field Message::from to Option<User> because message from channel no have sender + fmt
This commit is contained in:
parent
6de0c24ed2
commit
a8ced80f78
4 changed files with 26 additions and 26 deletions
|
@ -300,12 +300,14 @@ where
|
|||
update: Upd,
|
||||
) -> Option<Upd> {
|
||||
stream::iter(handlers)
|
||||
.fold(Some(update), |acc, handler| async move {
|
||||
.fold(Some(update), |acc, handler| {
|
||||
async move {
|
||||
// Option::and_then is not working here, because
|
||||
// Middleware::handle is asynchronous.
|
||||
match acc {
|
||||
Some(update) => {
|
||||
let DispatcherHandlerResult { next, result } = handler
|
||||
let DispatcherHandlerResult { next, result } =
|
||||
handler
|
||||
.handle_ctx(DispatcherHandlerCtx {
|
||||
bot: Arc::clone(&self.bot),
|
||||
update,
|
||||
|
@ -322,6 +324,7 @@ where
|
|||
}
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ impl Default for ChatPermissions {
|
|||
can_add_web_page_previews: None,
|
||||
can_change_info: None,
|
||||
can_invite_users: None,
|
||||
can_pin_messages: None
|
||||
can_pin_messages: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ pub struct Message {
|
|||
pub enum MessageKind {
|
||||
Common {
|
||||
/// Sender, empty for messages sent to channels.
|
||||
from: User,
|
||||
from: Option<User>,
|
||||
|
||||
#[serde(flatten)]
|
||||
forward_kind: ForwardKind,
|
||||
|
@ -328,8 +328,7 @@ mod getters {
|
|||
Pinned, SuccessfulPayment, SupergroupChatCreated,
|
||||
},
|
||||
},
|
||||
Chat, ForwardedFrom, Message, MessageEntity, PhotoSize, True,
|
||||
User,
|
||||
Chat, ForwardedFrom, Message, MessageEntity, PhotoSize, True, User,
|
||||
};
|
||||
|
||||
/// Getters for [Message] fields from [telegram docs].
|
||||
|
@ -340,7 +339,7 @@ mod getters {
|
|||
/// NOTE: this is getter for both `from` and `author_signature`
|
||||
pub fn from(&self) -> Option<&User> {
|
||||
match &self.kind {
|
||||
Common { from, .. } => Some(&from),
|
||||
Common { from, .. } => from.as_ref(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,9 +50,7 @@ impl MessageEntity {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::types::{
|
||||
Chat, ChatKind, ForwardKind, MediaKind, MessageKind,
|
||||
};
|
||||
use crate::types::{Chat, ChatKind, ForwardKind, MediaKind, MessageKind};
|
||||
|
||||
#[test]
|
||||
fn recursive_kind() {
|
||||
|
|
Loading…
Reference in a new issue