changed type of field Message::from to Option<User> because message from channel no have sender + fmt

This commit is contained in:
p0lunin 2020-02-12 20:54:54 +02:00
parent 6de0c24ed2
commit a8ced80f78
4 changed files with 26 additions and 26 deletions

View file

@ -300,27 +300,30 @@ where
update: Upd, update: Upd,
) -> Option<Upd> { ) -> Option<Upd> {
stream::iter(handlers) stream::iter(handlers)
.fold(Some(update), |acc, handler| async move { .fold(Some(update), |acc, handler| {
// Option::and_then is not working here, because async move {
// Middleware::handle is asynchronous. // Option::and_then is not working here, because
match acc { // Middleware::handle is asynchronous.
Some(update) => { match acc {
let DispatcherHandlerResult { next, result } = handler Some(update) => {
.handle_ctx(DispatcherHandlerCtx { let DispatcherHandlerResult { next, result } =
bot: Arc::clone(&self.bot), handler
update, .handle_ctx(DispatcherHandlerCtx {
}) bot: Arc::clone(&self.bot),
.await; update,
})
.await;
if let Err(error) = result { if let Err(error) = result {
self.handlers_error_handler self.handlers_error_handler
.handle_error(error) .handle_error(error)
.await .await
}
next
} }
None => None,
next
} }
None => None,
} }
}) })
.await .await

View file

@ -50,7 +50,7 @@ impl Default for ChatPermissions {
can_add_web_page_previews: None, can_add_web_page_previews: None,
can_change_info: None, can_change_info: None,
can_invite_users: None, can_invite_users: None,
can_pin_messages: None can_pin_messages: None,
} }
} }
} }

View file

@ -34,7 +34,7 @@ pub struct Message {
pub enum MessageKind { pub enum MessageKind {
Common { Common {
/// Sender, empty for messages sent to channels. /// Sender, empty for messages sent to channels.
from: User, from: Option<User>,
#[serde(flatten)] #[serde(flatten)]
forward_kind: ForwardKind, forward_kind: ForwardKind,
@ -328,8 +328,7 @@ mod getters {
Pinned, SuccessfulPayment, SupergroupChatCreated, Pinned, SuccessfulPayment, SupergroupChatCreated,
}, },
}, },
Chat, ForwardedFrom, Message, MessageEntity, PhotoSize, True, Chat, ForwardedFrom, Message, MessageEntity, PhotoSize, True, User,
User,
}; };
/// Getters for [Message] fields from [telegram docs]. /// Getters for [Message] fields from [telegram docs].
@ -340,7 +339,7 @@ mod getters {
/// NOTE: this is getter for both `from` and `author_signature` /// NOTE: this is getter for both `from` and `author_signature`
pub fn from(&self) -> Option<&User> { pub fn from(&self) -> Option<&User> {
match &self.kind { match &self.kind {
Common { from, .. } => Some(&from), Common { from, .. } => from.as_ref(),
_ => None, _ => None,
} }
} }

View file

@ -50,9 +50,7 @@ impl MessageEntity {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::types::{ use crate::types::{Chat, ChatKind, ForwardKind, MediaKind, MessageKind};
Chat, ChatKind, ForwardKind, MediaKind, MessageKind,
};
#[test] #[test]
fn recursive_kind() { fn recursive_kind() {