diff options
author | 2025-04-03 03:41:38 +0100 | |
---|---|---|
committer | 2025-04-03 03:41:38 +0100 | |
commit | 91f1994af940085d5d475a97820900ebbf0eb553 (patch) | |
tree | 6aab872f71d17a785d3d9286742fef38983d274c /filamento/src/logic/offline.rs | |
parent | 9ce3827a7d25714d17f266f0f50bb29f41090175 (diff) | |
download | luz-91f1994af940085d5d475a97820900ebbf0eb553.tar.gz luz-91f1994af940085d5d475a97820900ebbf0eb553.tar.bz2 luz-91f1994af940085d5d475a97820900ebbf0eb553.zip |
feat: better message handling, pep publish, xep_0172: nick
Diffstat (limited to 'filamento/src/logic/offline.rs')
-rw-r--r-- | filamento/src/logic/offline.rs | 64 |
1 files changed, 57 insertions, 7 deletions
diff --git a/filamento/src/logic/offline.rs b/filamento/src/logic/offline.rs index bc2666a..6399cf7 100644 --- a/filamento/src/logic/offline.rs +++ b/filamento/src/logic/offline.rs @@ -1,8 +1,14 @@ +use chrono::Utc; use lampada::error::WriteError; +use uuid::Uuid; use crate::{ Command, - error::{DatabaseError, DiscoError, Error, RosterError, StatusError}, + chat::{Delivery, Message}, + error::{ + DatabaseError, DiscoError, Error, IqRequestError, MessageSendError, NickError, RosterError, + StatusError, + }, presence::Online, roster::Contact, }; @@ -76,16 +82,16 @@ pub async fn handle_offline_result(logic: &ClientLogic, command: Command) -> Res sender.send(Err(RosterError::Write(WriteError::Disconnected))); } Command::BuddyRequest(_jid, sender) => { - sender.send(Err(WriteError::Disconnected)); + sender.send(Err(WriteError::Disconnected.into())); } Command::SubscriptionRequest(_jid, sender) => { - sender.send(Err(WriteError::Disconnected)); + sender.send(Err(WriteError::Disconnected.into())); } Command::AcceptBuddyRequest(_jid, sender) => { - sender.send(Err(WriteError::Disconnected)); + sender.send(Err(WriteError::Disconnected.into())); } Command::AcceptSubscriptionRequest(_jid, sender) => { - sender.send(Err(WriteError::Disconnected)); + sender.send(Err(WriteError::Disconnected.into())); } Command::UnsubscribeFromContact(_jid, sender) => { sender.send(Err(WriteError::Disconnected)); @@ -107,8 +113,42 @@ pub async fn handle_offline_result(logic: &ClientLogic, command: Command) -> Res sender.send(result); } // TODO: offline message queue - Command::SendMessage(_jid, _body, sender) => { - sender.send(Err(WriteError::Disconnected)); + Command::SendMessage(jid, body) => { + let id = Uuid::new_v4(); + let timestamp = Utc::now(); + + let message = Message { + id, + from: logic.bare_jid.clone(), + // TODO: failure reason + delivery: Some(Delivery::Failed), + timestamp, + body, + }; + // try to store in message history that there is a new message that is sending. if client is quit mid-send then can mark as failed and re-send + // TODO: mark these as potentially failed upon client launch + if let Err(e) = logic + .db() + .create_message_with_self_resource( + message.clone(), + jid.clone(), + // TODO: when message is queued and sent, the from must also be updated with the correct resource + logic.bare_jid.clone(), + ) + .await + { + // TODO: should these really be handle_error or just the error macro? + logic + .handle_error(MessageSendError::MessageHistory(e.into()).into()) + .await; + } + logic + .update_sender() + .send(crate::UpdateMessage::Message { + to: jid.as_bare(), + message, + }) + .await; } Command::SendPresence(_jid, _presence, sender) => { sender.send(Err(WriteError::Disconnected)); @@ -119,6 +159,16 @@ pub async fn handle_offline_result(logic: &ClientLogic, command: Command) -> Res Command::DiscoItems(_jid, _node, sender) => { sender.send(Err(DiscoError::Write(WriteError::Disconnected))); } + Command::Publish { + item: _, + node: _, + sender, + } => { + sender.send(Err(IqRequestError::Write(WriteError::Disconnected).into())); + } + Command::ChangeNick(_, sender) => { + sender.send(Err(NickError::Disconnected)); + } } Ok(()) } |