diff options
Diffstat (limited to 'src/router.rs')
-rw-r--r-- | src/router.rs | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/router.rs b/src/router.rs new file mode 100644 index 0000000..f98be7d --- /dev/null +++ b/src/router.rs @@ -0,0 +1,78 @@ +//use super::{auth, handlers}; +use log::{debug, error, info}; +use serde_json::Value as JsonValue; +use crate::client_ext::Update; + +#[derive(Debug)] +pub struct UpdateHandler(); //pub crate::airdata::AsyncData); + +impl tdlib_rs::update::Handler for UpdateHandler { + fn handle_json( + &self, + client: tdlib_rs::client::Client, + req: JsonValue, + ) -> futures::future::BoxFuture<'static, ()> { + //let data = self.0.clone(); + Box::pin(async move { + let update: Update = serde_json::from_value(req).expect("invalid update"); + match update { + Update::UpdateAuthorizationState(state) => { + if let Err(e) = crate::auth::continue_auth(&client, state.authorization_state).await { + error!("auth failed: {}", e); + } + } + Update::UpdateOption(upd) => { + debug!("update option: '{}'", upd.name); + } + /* + UpdateMessageContent(update) => { + handlers::update_message_content(data, update).await; + } + UpdateNewMessage(update) => { + handlers::update_new_message(&client, data.clone(), update).await; + }*/ + Update::UpdateConnectionState(upd) => { + info!("connection: {:?}", upd.state); + } /* + UpdateUser(update) => { + let id = update.user.id; + let _ = data.insert_user(update.user).await; + info!("update user {}", data.get_username_lossy(id).await); + } + UpdateUserStatus(update) => { + info!( + "{} is now {:?}", + data.get_username_lossy(update.user_id).await, + update.status + ); + } + UpdateNewChat(update) => { + let chat = update.chat; + info!("new chat: {}", chat.title); + let _ = data.insert_chat(chat).await; + } + UpdateDeleteMessages(update) => { + handlers::update_delete_messages(data, update).await; + } + UpdateDiceEmojis(_) + | UpdateSelectedBackground(_) + | UpdateHavePendingNotifications(_) + | UpdateUnreadChatCount(_) + | UpdateChatLastMessage(_) + | UpdateChatChatList(_) + | UpdateChatReadInbox(_) + | UpdateScopeNotificationSettings(_) + | UpdateUserFullInfo(_) => {}*/ + /*UpdateFile(update) => { + trace!( + "Update file {}: progress: {}/{}", + update.file.id, + update.file.local.downloaded_size, + update.file.size + ); + }*/ + _ => debug!("unknown update: {:?}", update), + } + }) + } +} |