This commit is contained in:
Temirkhan Myrzamadi 2020-01-17 20:19:13 +06:00
parent 510e5d8630
commit c0f83a4999
2 changed files with 18 additions and 7 deletions

View file

@ -3,10 +3,12 @@ use super::{
storage::{InMemStorage, Storage},
};
use crate::{
dispatching::{chat::ChatUpdate, Handler, SessionState},
dispatching::{
chat::{ChatUpdate, ChatUpdateKind},
Handler, SessionState,
},
types::{Update, UpdateKind},
};
use crate::dispatching::chat::ChatUpdateKind;
/// A dispatcher that dispatches updates from chats.
pub struct Dispatcher<'a, Session, H> {
@ -53,9 +55,18 @@ where
/// crate::dispatching::DispatchResult::Unhandled
pub async fn dispatch(&mut self, update: Update) -> DispatchResult {
let chat_update = match update.kind {
UpdateKind::Message(msg) => ChatUpdate { id: update.id, kind: ChatUpdateKind::Message(msg) },
UpdateKind::EditedMessage(msg) => ChatUpdate { id: update.id, kind: ChatUpdateKind::EditedMessage(msg) },
UpdateKind::CallbackQuery(query) => ChatUpdate { id: update.id, kind: ChatUpdateKind::CallbackQuery(query) },
UpdateKind::Message(msg) => ChatUpdate {
id: update.id,
kind: ChatUpdateKind::Message(msg),
},
UpdateKind::EditedMessage(msg) => ChatUpdate {
id: update.id,
kind: ChatUpdateKind::EditedMessage(msg),
},
UpdateKind::CallbackQuery(query) => ChatUpdate {
id: update.id,
kind: ChatUpdateKind::CallbackQuery(query),
},
_ => return DispatchResult::Unhandled,
};

View file

@ -25,7 +25,7 @@ pub trait Handler<Session, U> {
) -> Pin<Box<dyn Future<Output = SessionState<Session>> + 'a>>
where
Session: 'a,
U: 'a;
U: 'a;
}
/// The implementation of `Handler` for `Fn(Session, Update) -> Future<Output =
@ -42,7 +42,7 @@ where
) -> Pin<Box<dyn Future<Output = Fut::Output> + 'a>>
where
Session: 'a,
U: 'a,
U: 'a,
{
Box::pin(async move { self(session, update).await })
}