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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
use lampada::error::WriteError;
use crate::{
Command,
error::{RosterError, StatusError},
};
use super::ClientLogic;
pub async fn handle_offline(logic: ClientLogic, command: Command) {
match command {
Command::GetRoster(sender) => {
let roster = logic.db().read_cached_roster().await;
match roster {
Ok(roster) => {
let _ = sender.send(Ok(roster));
}
Err(e) => {
let _ = sender.send(Err(RosterError::Cache(e.into())));
}
}
}
Command::GetChats(sender) => {
let chats = logic.db().read_chats().await.map_err(|e| e.into());
sender.send(chats);
}
Command::GetChatsOrdered(sender) => {
let chats = logic.db().read_chats_ordered().await.map_err(|e| e.into());
sender.send(chats);
}
Command::GetChatsOrderedWithLatestMessages(sender) => {
let chats = logic
.db()
.read_chats_ordered_with_latest_messages()
.await
.map_err(|e| e.into());
sender.send(chats);
}
Command::GetChat(jid, sender) => {
let chats = logic.db().read_chat(jid).await.map_err(|e| e.into());
sender.send(chats);
}
Command::GetMessages(jid, sender) => {
let messages = logic
.db()
.read_message_history(jid)
.await
.map_err(|e| e.into());
sender.send(messages);
}
Command::DeleteChat(jid, sender) => {
let result = logic.db().delete_chat(jid).await.map_err(|e| e.into());
sender.send(result);
}
Command::DeleteMessage(uuid, sender) => {
let result = logic.db().delete_message(uuid).await.map_err(|e| e.into());
sender.send(result);
}
Command::GetUser(jid, sender) => {
let user = logic.db().read_user(jid).await.map_err(|e| e.into());
sender.send(user);
}
// TODO: offline queue to modify roster
Command::AddContact(_jid, sender) => {
sender.send(Err(RosterError::Write(WriteError::Disconnected)));
}
Command::BuddyRequest(_jid, sender) => {
sender.send(Err(WriteError::Disconnected));
}
Command::SubscriptionRequest(_jid, sender) => {
sender.send(Err(WriteError::Disconnected));
}
Command::AcceptBuddyRequest(_jid, sender) => {
sender.send(Err(WriteError::Disconnected));
}
Command::AcceptSubscriptionRequest(_jid, sender) => {
sender.send(Err(WriteError::Disconnected));
}
Command::UnsubscribeFromContact(_jid, sender) => {
sender.send(Err(WriteError::Disconnected));
}
Command::UnsubscribeContact(_jid, sender) => {
sender.send(Err(WriteError::Disconnected));
}
Command::UnfriendContact(_jid, sender) => {
sender.send(Err(WriteError::Disconnected));
}
Command::DeleteContact(_jid, sender) => {
sender.send(Err(RosterError::Write(WriteError::Disconnected)));
}
Command::UpdateContact(_jid, _contact_update, sender) => {
sender.send(Err(RosterError::Write(WriteError::Disconnected)));
}
Command::SetStatus(online, sender) => {
let result = logic
.db()
.upsert_cached_status(online)
.await
.map_err(|e| StatusError::Cache(e.into()));
sender.send(result);
}
// TODO: offline message queue
Command::SendMessage(_jid, _body, sender) => {
sender.send(Err(WriteError::Disconnected));
}
Command::SendPresence(_jid, _presence, sender) => {
sender.send(Err(WriteError::Disconnected));
}
}
}
|