1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
//use super::{auth, handlers};
use log::{debug, error, info};
use serde_json::Value as JsonValue;
use crate::client_ext::Update;
#[derive(Clone)]
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.clone()).map_err(|err| error!("going to panic: invalid update: {:?} {:?}", req, err)).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);
}
Update::UpdateUser(update) => {
//let id = update.user.id;
let name = format!("{}{}", update.user.first_name, update.user.last_name);
info!("update user: {}, status: {}", name, update.user.status);
//let _ = data.insert_user(update.user).await;
//info!("update user {}", data.get_username_lossy(id).await);
}
Update::UpdateUserStatus(update) => {
info!(
"{} is now {}",
//data.get_username_lossy(update.user_id).await,
update.user_id, 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),
}
})
}
}
|