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,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
}

View file

@ -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,
}
}
}

View file

@ -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,
}
}

View file

@ -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() {