aboutsummaryrefslogtreecommitdiffstats
path: root/filamento/src/logic/local_only.rs
blob: cabbef47681d1b32118a2e7ee8950a44c79ae36a (plain) (blame)
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
use jid::JID;
use uuid::Uuid;

use crate::{
    chat::{Chat, Message},
    error::DatabaseError,
    files::FileStore,
    user::User,
};

use super::ClientLogic;

pub async fn handle_get_chats<Fs: FileStore + Clone>(
    logic: &ClientLogic<Fs>,
) -> Result<Vec<Chat>, DatabaseError> {
    Ok(logic.db().read_chats().await?)
}

pub async fn handle_get_chats_ordered<Fs: FileStore + Clone>(
    logic: &ClientLogic<Fs>,
) -> Result<Vec<Chat>, DatabaseError> {
    Ok(logic.db().read_chats_ordered().await?)
}

pub async fn handle_get_chats_ordered_with_latest_messages<Fs: FileStore + Clone>(
    logic: &ClientLogic<Fs>,
) -> Result<Vec<(Chat, Message)>, DatabaseError> {
    Ok(logic.db().read_chats_ordered_with_latest_messages().await?)
}

pub async fn handle_get_chat<Fs: FileStore + Clone>(
    logic: &ClientLogic<Fs>,
    jid: JID,
) -> Result<Chat, DatabaseError> {
    Ok(logic.db().read_chat(jid).await?)
}

pub async fn handle_get_messages<Fs: FileStore + Clone>(
    logic: &ClientLogic<Fs>,
    jid: JID,
) -> Result<Vec<Message>, DatabaseError> {
    Ok(logic.db().read_message_history(jid).await?)
}

pub async fn handle_delete_chat<Fs: FileStore + Clone>(
    logic: &ClientLogic<Fs>,
    jid: JID,
) -> Result<(), DatabaseError> {
    Ok(logic.db().delete_chat(jid).await?)
}

pub async fn handle_delete_messaage<Fs: FileStore + Clone>(
    logic: &ClientLogic<Fs>,
    uuid: Uuid,
) -> Result<(), DatabaseError> {
    Ok(logic.db().delete_message(uuid).await?)
}

pub async fn handle_get_user<Fs: FileStore + Clone>(
    logic: &ClientLogic<Fs>,
    jid: JID,
) -> Result<User, DatabaseError> {
    Ok(logic.db().read_user(jid).await?)
}