diff options
Diffstat (limited to 'luz/src/connection/read.rs')
-rw-r--r-- | luz/src/connection/read.rs | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/luz/src/connection/read.rs b/luz/src/connection/read.rs index 4390e00..0590ce3 100644 --- a/luz/src/connection/read.rs +++ b/luz/src/connection/read.rs @@ -18,16 +18,13 @@ use uuid::Uuid; use crate::{ chat::{Body, Message}, db::Db, - error::{Error, IqError, PresenceError, Reason, RecvMessageError}, + error::{Error, IqError, MessageRecvError, PresenceError, ReadError, RosterError}, presence::{Offline, Online, Presence, Show}, roster::Contact, UpdateMessage, }; -use super::{ - write::{WriteHandle, WriteMessage}, - SupervisorCommand, -}; +use super::{write::WriteHandle, SupervisorCommand}; pub struct Read { control_receiver: mpsc::Receiver<ReadControl>, @@ -38,7 +35,7 @@ pub struct Read { JoinSet<()>, mpsc::Sender<SupervisorCommand>, WriteHandle, - Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, Reason>>>>>, + Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, ReadError>>>>>, )>, db: Db, update_sender: mpsc::Sender<UpdateMessage>, @@ -48,7 +45,7 @@ pub struct Read { disconnecting: bool, disconnect_timedout: oneshot::Receiver<()>, // TODO: use proper stanza ids - pending_iqs: Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, Reason>>>>>, + pending_iqs: Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, ReadError>>>>>, } impl Read { @@ -61,7 +58,7 @@ impl Read { JoinSet<()>, mpsc::Sender<SupervisorCommand>, WriteHandle, - Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, Reason>>>>>, + Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, ReadError>>>>>, )>, db: Db, update_sender: mpsc::Sender<UpdateMessage>, @@ -69,9 +66,9 @@ impl Read { supervisor_control: mpsc::Sender<SupervisorCommand>, write_handle: WriteHandle, tasks: JoinSet<()>, - pending_iqs: Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, Reason>>>>>, + pending_iqs: Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, ReadError>>>>>, ) -> Self { - let (send, recv) = oneshot::channel(); + let (_send, recv) = oneshot::channel(); Self { control_receiver, stream, @@ -162,7 +159,7 @@ impl Read { // when it aborts, must clear iq map no matter what let mut iqs = self.pending_iqs.lock().await; for (_id, sender) in iqs.drain() { - let _ = sender.send(Err(Reason::LostConnection)); + let _ = sender.send(Err(ReadError::LostConnection)); } } } @@ -178,7 +175,7 @@ async fn handle_stanza( db: Db, supervisor_control: mpsc::Sender<SupervisorCommand>, write_handle: WriteHandle, - pending_iqs: Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, Reason>>>>>, + pending_iqs: Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, ReadError>>>>>, ) { match stanza { Stanza::Message(stanza_message) => { @@ -207,7 +204,9 @@ async fn handle_stanza( if let Err(e) = result { tracing::error!("messagecreate"); let _ = update_sender - .send(UpdateMessage::Error(Error::CacheUpdate(e.into()))) + .send(UpdateMessage::Error(Error::MessageRecv( + MessageRecvError::MessageHistory(e.into()), + ))) .await; } let _ = update_sender @@ -215,8 +214,8 @@ async fn handle_stanza( .await; } else { let _ = update_sender - .send(UpdateMessage::Error(Error::RecvMessage( - RecvMessageError::MissingFrom, + .send(UpdateMessage::Error(Error::MessageRecv( + MessageRecvError::MissingFrom, ))) .await; } @@ -229,9 +228,16 @@ async fn handle_stanza( stanza::client::presence::PresenceType::Error => { // TODO: is there any other information that should go with the error? also MUST have an error, otherwise it's a different error. maybe it shoulnd't be an option. let _ = update_sender - .send(UpdateMessage::Error(Error::Presence(PresenceError::Error( - Reason::Stanza(presence.errors.first().cloned()), - )))) + .send(UpdateMessage::Error(Error::Presence( + // TODO: ughhhhhhhhhhhhh these stanza errors should probably just have an option, and custom display + PresenceError::StanzaError( + presence + .errors + .first() + .cloned() + .expect("error MUST have error"), + ), + ))) .await; } // should not happen (error to server) @@ -329,8 +335,8 @@ async fn handle_stanza( let contact: Contact = item.into(); if let Err(e) = db.upsert_contact(contact.clone()).await { let _ = update_sender - .send(UpdateMessage::Error(Error::CacheUpdate( - e.into(), + .send(UpdateMessage::Error(Error::Roster( + RosterError::Cache(e.into()), ))) .await; } @@ -381,7 +387,7 @@ pub enum ReadControl { JoinSet<()>, mpsc::Sender<SupervisorCommand>, WriteHandle, - Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, Reason>>>>>, + Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, ReadError>>>>>, )>, ), } @@ -414,13 +420,13 @@ impl ReadControlHandle { JoinSet<()>, mpsc::Sender<SupervisorCommand>, WriteHandle, - Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, Reason>>>>>, + Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, ReadError>>>>>, )>, db: Db, sender: mpsc::Sender<UpdateMessage>, supervisor_control: mpsc::Sender<SupervisorCommand>, jabber_write: WriteHandle, - pending_iqs: Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, Reason>>>>>, + pending_iqs: Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, ReadError>>>>>, ) -> Self { let (control_sender, control_receiver) = mpsc::channel(20); @@ -451,14 +457,14 @@ impl ReadControlHandle { JoinSet<()>, mpsc::Sender<SupervisorCommand>, WriteHandle, - Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, Reason>>>>>, + Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, ReadError>>>>>, )>, db: Db, sender: mpsc::Sender<UpdateMessage>, supervisor_control: mpsc::Sender<SupervisorCommand>, jabber_write: WriteHandle, tasks: JoinSet<()>, - pending_iqs: Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, Reason>>>>>, + pending_iqs: Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, ReadError>>>>>, ) -> Self { let (control_sender, control_receiver) = mpsc::channel(20); |