aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2025-03-27 14:57:48 +0000
committerLibravatar cel 🌸 <cel@bunny.garden>2025-03-27 14:57:48 +0000
commit83a6aa0574190137b38331bd53795324139237cf (patch)
tree0cfbe858fb09325d8347b15b641a06df8d82db15
parente703284539384b461d204c73e7e14daead3f06d9 (diff)
downloadluz-83a6aa0574190137b38331bd53795324139237cf.tar.gz
luz-83a6aa0574190137b38331bd53795324139237cf.tar.bz2
luz-83a6aa0574190137b38331bd53795324139237cf.zip
feat: remove `UpdateMessage::Error` variant
-rw-r--r--filamento/src/error.rs6
-rw-r--r--filamento/src/lib.rs2
-rw-r--r--filamento/src/logic/connect.rs38
-rw-r--r--filamento/src/logic/mod.rs6
-rw-r--r--filamento/src/logic/online.rs23
-rw-r--r--filamento/src/logic/process_stanza.rs12
6 files changed, 31 insertions, 56 deletions
diff --git a/filamento/src/error.rs b/filamento/src/error.rs
index 206d6be..6277292 100644
--- a/filamento/src/error.rs
+++ b/filamento/src/error.rs
@@ -26,11 +26,11 @@ pub enum Error {
SetStatus(#[from] StatusError),
// TODO: have different ones for get/update/set
#[error("roster: {0}")]
- Roster(RosterError),
+ Roster(#[from] RosterError),
#[error("stream error: {0}")]
Stream(#[from] stanza::stream::Error),
#[error("message send error: {0}")]
- MessageSend(MessageSendError),
+ MessageSend(#[from] MessageSendError),
#[error("message receive error: {0}")]
MessageRecv(#[from] MessageRecvError),
}
@@ -82,6 +82,8 @@ pub enum RosterError {
Read(#[from] ReadError),
#[error("stanza error: {0}")]
StanzaError(#[from] stanza::client::error::Error),
+ #[error("could not reply to roster push: {0}")]
+ PushReply(WriteError),
}
#[derive(Debug, Error, Clone)]
diff --git a/filamento/src/lib.rs b/filamento/src/lib.rs
index b284c7e..1e9207c 100644
--- a/filamento/src/lib.rs
+++ b/filamento/src/lib.rs
@@ -101,7 +101,6 @@ pub enum Command {
#[derive(Debug, Clone)]
pub enum UpdateMessage {
- Error(Error),
Online(Online, Vec<Contact>),
Offline(Offline),
/// received roster from jabber server (replace full app roster state with this)
@@ -122,7 +121,6 @@ pub enum UpdateMessage {
message: Message,
},
SubscriptionRequest(jid::JID),
- Unsupported(Stanza),
}
/// an xmpp client that is suited for a chat client use case
diff --git a/filamento/src/logic/connect.rs b/filamento/src/logic/connect.rs
index 4dc789e..d7b9fee 100644
--- a/filamento/src/logic/connect.rs
+++ b/filamento/src/logic/connect.rs
@@ -27,11 +27,8 @@ pub async fn handle_connect(logic: ClientLogic, connection: Connected) {
let online = match online {
Ok(online) => online,
Err(e) => {
- let _ = logic
- .update_sender()
- .send(UpdateMessage::Error(Error::Connecting(
- ConnectionJobError::StatusCacheError(e.into()),
- )))
+ logic
+ .handle_error(ConnectionJobError::StatusCacheError(e.into()).into())
.await;
Online::default()
}
@@ -53,37 +50,26 @@ pub async fn handle_connect(logic: ClientLogic, connection: Connected) {
.send(UpdateMessage::Online(online, roster))
.await;
}
- Err(e) => {
- let _ = logic
- .update_sender()
- .send(UpdateMessage::Error(Error::Connecting(e.into())))
- .await;
- }
+ Err(e) => logic.handle_error(Error::Connecting(e.into())).await,
},
Err(e) => {
- let _ = logic
- .update_sender()
- .send(UpdateMessage::Error(Error::Connecting(
- ConnectionJobError::SendPresence(WriteError::Actor(e.into())),
- )))
+ logic
+ .handle_error(
+ ConnectionJobError::SendPresence(WriteError::Actor(e.into()))
+ .into(),
+ )
.await;
}
}
}
Err(e) => {
- let _ = logic
- .update_sender()
- .send(UpdateMessage::Error(Error::Connecting(e.into())))
- .await;
+ logic.handle_error(Error::Connecting(e.into())).await;
}
},
Err(e) => {
- let _ = logic
- .update_sender()
- .send(UpdateMessage::Error(Error::Connecting(
- ConnectionJobError::RosterRetreival(RosterError::Write(WriteError::Actor(
- e.into(),
- ))),
+ logic
+ .handle_error(Error::Connecting(ConnectionJobError::RosterRetreival(
+ RosterError::Write(WriteError::Actor(e.into())),
)))
.await;
}
diff --git a/filamento/src/logic/mod.rs b/filamento/src/logic/mod.rs
index dc262a9..61d78bf 100644
--- a/filamento/src/logic/mod.rs
+++ b/filamento/src/logic/mod.rs
@@ -54,12 +54,6 @@ impl ClientLogic {
&self.update_sender
}
- pub async fn handle_unsupported(&self, stanza: impl Into<Stanza>) {
- let stanza: Stanza = stanza.into();
- warn!("received unsupported stanza: {:?}", stanza);
- self.handle_update(UpdateMessage::Unsupported(stanza)).await;
- }
-
pub async fn handle_update(&self, update: UpdateMessage) {
// TODO: impl fmt
info!("{:?}", update);
diff --git a/filamento/src/logic/online.rs b/filamento/src/logic/online.rs
index e8cbb33..967ebb2 100644
--- a/filamento/src/logic/online.rs
+++ b/filamento/src/logic/online.rs
@@ -75,10 +75,7 @@ pub async fn handle_online(logic: ClientLogic, command: Command, connection: Con
items.into_iter().map(|item| item.into()).collect();
if let Err(e) = logic.db().replace_cached_roster(contacts.clone()).await {
logic
- .update_sender()
- .send(UpdateMessage::Error(Error::Roster(RosterError::Cache(
- e.into(),
- ))))
+ .handle_error(Error::Roster(RosterError::Cache(e.into())))
.await;
};
result_sender.send(Ok(contacts));
@@ -573,11 +570,8 @@ pub async fn handle_online(logic: ClientLogic, command: Command, connection: Con
Command::SetStatus(online, sender) => {
let result = logic.db().upsert_cached_status(online.clone()).await;
if let Err(e) = result {
- let _ = logic
- .update_sender()
- .send(UpdateMessage::Error(Error::SetStatus(StatusError::Cache(
- e.into(),
- ))))
+ logic
+ .handle_error(StatusError::Cache(e.into()).into())
.await;
}
let result = connection
@@ -623,15 +617,10 @@ pub async fn handle_online(logic: ClientLogic, command: Command, connection: Con
.db()
.create_message_with_self_resource_and_chat(message.clone(), jid.clone())
.await
- .map_err(|e| e.into())
{
- tracing::error!("{}", e);
- let _ =
- logic
- .update_sender()
- .send(UpdateMessage::Error(Error::MessageSend(
- MessageSendError::MessageHistory(e),
- )));
+ logic
+ .handle_error(MessageSendError::MessageHistory(e.into()).into())
+ .await;
}
// TODO: don't do this, have separate from from details
message.from = message.from.as_bare();
diff --git a/filamento/src/logic/process_stanza.rs b/filamento/src/logic/process_stanza.rs
index 3dfe9fb..94257aa 100644
--- a/filamento/src/logic/process_stanza.rs
+++ b/filamento/src/logic/process_stanza.rs
@@ -271,7 +271,9 @@ pub async fn recv_iq(
if let Err(e) =
logic.db().delete_contact(item.jid.clone()).await
{
- error!("{}", RosterError::Cache(e.into()));
+ logic
+ .handle_error(RosterError::Cache(e.into()).into())
+ .await;
}
Ok(Some(UpdateMessage::RosterDelete(item.jid)))
}
@@ -279,7 +281,9 @@ pub async fn recv_iq(
let contact: Contact = item.into();
if let Err(e) = logic.db().upsert_contact(contact.clone()).await
{
- error!("{}", RosterError::Cache(e.into()));
+ logic
+ .handle_error(RosterError::Cache(e.into()).into())
+ .await;
}
let iq = Iq {
from: Some(connection.jid().clone()),
@@ -293,7 +297,9 @@ pub async fn recv_iq(
if let Err(e) =
connection.write_handle().write(Stanza::Iq(iq)).await
{
- error!("could not reply to roster set: {}", e);
+ logic
+ .handle_error(RosterError::PushReply(e.into()).into())
+ .await;
}
Ok(Some(UpdateMessage::RosterUpdate(contact)))
}