diff options
Diffstat (limited to 'filamento/src/logic')
-rw-r--r-- | filamento/src/logic/connect.rs | 38 | ||||
-rw-r--r-- | filamento/src/logic/mod.rs | 6 | ||||
-rw-r--r-- | filamento/src/logic/online.rs | 23 | ||||
-rw-r--r-- | filamento/src/logic/process_stanza.rs | 12 |
4 files changed, 27 insertions, 52 deletions
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))) } |