From a367aca33fecc03270b5b9ad2a6a21281d760fd8 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Thu, 27 Mar 2025 19:09:35 +0000 Subject: refactor(filamento): handle_online logic --- filamento/src/logic/local_only.rs | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 filamento/src/logic/local_only.rs (limited to 'filamento/src/logic/local_only.rs') diff --git a/filamento/src/logic/local_only.rs b/filamento/src/logic/local_only.rs new file mode 100644 index 0000000..3f6fe8d --- /dev/null +++ b/filamento/src/logic/local_only.rs @@ -0,0 +1,47 @@ +use jid::JID; +use uuid::Uuid; + +use crate::{ + chat::{Chat, Message}, + error::DatabaseError, + user::User, +}; + +use super::ClientLogic; + +pub async fn handle_get_chats(logic: &ClientLogic) -> Result, DatabaseError> { + Ok(logic.db().read_chats().await?) +} + +pub async fn handle_get_chats_ordered(logic: &ClientLogic) -> Result, DatabaseError> { + Ok(logic.db().read_chats_ordered().await?) +} + +pub async fn handle_get_chats_ordered_with_latest_messages( + logic: &ClientLogic, +) -> Result, DatabaseError> { + Ok(logic.db().read_chats_ordered_with_latest_messages().await?) +} + +pub async fn handle_get_chat(logic: &ClientLogic, jid: JID) -> Result { + Ok(logic.db().read_chat(jid).await?) +} + +pub async fn handle_get_messages( + logic: &ClientLogic, + jid: JID, +) -> Result, DatabaseError> { + Ok(logic.db().read_message_history(jid).await?) +} + +pub async fn handle_delete_chat(logic: &ClientLogic, jid: JID) -> Result<(), DatabaseError> { + Ok(logic.db().delete_chat(jid).await?) +} + +pub async fn handle_delete_messaage(logic: &ClientLogic, uuid: Uuid) -> Result<(), DatabaseError> { + Ok(logic.db().delete_message(uuid).await?) +} + +pub async fn handle_get_user(logic: &ClientLogic, jid: JID) -> Result { + Ok(logic.db().read_user(jid).await?) +} -- cgit