diff options
| author | 2025-04-11 05:53:06 +0100 | |
|---|---|---|
| committer | 2025-04-11 05:53:06 +0100 | |
| commit | e49b4e5ea59079fdf047d3d2eb63ddb895c3b0eb (patch) | |
| tree | 31f2d1c5efc0ba7a373f2909f0cb1e6a7e1e718a /filamento/src | |
| parent | d4afee032d5b4e491e5873cab4ed78c80fafe164 (diff) | |
| download | luz-e49b4e5ea59079fdf047d3d2eb63ddb895c3b0eb.tar.gz luz-e49b4e5ea59079fdf047d3d2eb63ddb895c3b0eb.tar.bz2 luz-e49b4e5ea59079fdf047d3d2eb63ddb895c3b0eb.zip | |
feat(filamento): return `User` with `Contact` on roster push
Diffstat (limited to '')
| -rw-r--r-- | filamento/src/error.rs | 10 | ||||
| -rw-r--r-- | filamento/src/lib.rs | 5 | ||||
| -rw-r--r-- | filamento/src/logic/process_stanza.rs | 69 | 
3 files changed, 65 insertions, 19 deletions
| diff --git a/filamento/src/error.rs b/filamento/src/error.rs index 76509f6..f2bf6ef 100644 --- a/filamento/src/error.rs +++ b/filamento/src/error.rs @@ -21,7 +21,7 @@ pub enum Error<Fs: FileStore> {      // TODO: include content      // UnrecognizedContent(peanuts::element::Content),      #[error("iq receive error: {0}")] -    Iq(#[from] IqError), +    Iq(#[from] IqProcessError),      // TODO: change to Connecting(ConnectingError)      #[error("connecting: {0}")]      Connecting(#[from] ConnectionJobError), @@ -192,6 +192,14 @@ pub enum IqError {  }  #[derive(Debug, Error, Clone)] +pub enum IqProcessError { +    #[error("iq error")] +    Iq(#[from] IqError), +    #[error("roster push")] +    Roster(#[from] RosterError), +} + +#[derive(Debug, Error, Clone)]  pub enum DatabaseOpenError {      #[error("error: {0}")]      Error(Arc<sqlx::Error>), diff --git a/filamento/src/lib.rs b/filamento/src/lib.rs index 7bcf593..974901c 100644 --- a/filamento/src/lib.rs +++ b/filamento/src/lib.rs @@ -154,11 +154,8 @@ pub enum Command<Fs: FileStore> {  pub enum UpdateMessage {      Online(Online, Vec<(Contact, User)>),      Offline(Offline), -    /// received roster from jabber server (replace full app roster state with this) -    /// is this needed? -    FullRoster(Vec<Contact>),      /// (only update app roster state, don't replace) -    RosterUpdate(Contact), +    RosterUpdate(Contact, User),      RosterDelete(JID),      /// presences should be stored with users in the ui, not contacts, as presences can be received from anyone      Presence { diff --git a/filamento/src/logic/process_stanza.rs b/filamento/src/logic/process_stanza.rs index 9c49b04..51e20a4 100644 --- a/filamento/src/logic/process_stanza.rs +++ b/filamento/src/logic/process_stanza.rs @@ -20,8 +20,8 @@ use crate::{      UpdateMessage, caps,      chat::{Body, Message},      error::{ -        AvatarUpdateError, DatabaseError, Error, IqError, MessageRecvError, PresenceError, -        RosterError, +        AvatarUpdateError, DatabaseError, Error, IqError, IqProcessError, MessageRecvError, +        PresenceError, RosterError,      },      files::FileStore,      presence::{Offline, Online, Presence, PresenceType, Show}, @@ -541,11 +541,11 @@ pub async fn recv_iq<Fs: FileStore + Clone>(      logic: ClientLogic<Fs>,      connection: Connected,      iq: Iq, -) -> Result<Option<UpdateMessage>, IqError> { +) -> Result<Option<UpdateMessage>, IqProcessError> {      if let Some(to) = &iq.to {          if *to == *connection.jid() {          } else { -            return Err(IqError::IncorrectAddressee(to.clone())); +            return Err(IqProcessError::Iq(IqError::IncorrectAddressee(to.clone())));          }      }      match iq.r#type { @@ -556,7 +556,11 @@ pub async fn recv_iq<Fs: FileStore + Clone>(                  .unwrap_or_else(|| connection.server().clone());              let id = iq.id.clone();              debug!("received iq result with id `{}` from {}", id, from); -            logic.pending().respond(Stanza::Iq(iq), id).await?; +            logic +                .pending() +                .respond(Stanza::Iq(iq), id) +                .await +                .map_err(|e| Into::<IqError>::into(e))?;              Ok(None)          }          stanza::client::iq::IqType::Get => { @@ -596,7 +600,11 @@ pub async fn recv_iq<Fs: FileStore + Clone>(                                                  errors: vec![StanzaError::ItemNotFound.into()],                                              };                                              // TODO: log error -                                            connection.write_handle().write(Stanza::Iq(iq)).await?; +                                            connection +                                                .write_handle() +                                                .write(Stanza::Iq(iq)) +                                                .await +                                                .map_err(|e| Into::<IqError>::into(e))?;                                              info!("replied to disco#info request from {}", from);                                              return Ok(None);                                          } @@ -612,7 +620,11 @@ pub async fn recv_iq<Fs: FileStore + Clone>(                                              errors: vec![StanzaError::ItemNotFound.into()],                                          };                                          // TODO: log error -                                        connection.write_handle().write(Stanza::Iq(iq)).await?; +                                        connection +                                            .write_handle() +                                            .write(Stanza::Iq(iq)) +                                            .await +                                            .map_err(|e| Into::<IqError>::into(e))?;                                          info!("replied to disco#info request from {}", from);                                          return Ok(None);                                      } @@ -627,7 +639,11 @@ pub async fn recv_iq<Fs: FileStore + Clone>(                              query: Some(iq::Query::DiscoInfo(disco)),                              errors: vec![],                          }; -                        connection.write_handle().write(Stanza::Iq(iq)).await?; +                        connection +                            .write_handle() +                            .write(Stanza::Iq(iq)) +                            .await +                            .map_err(|e| Into::<IqError>::into(e))?;                          info!("replied to disco#info request from {}", from);                          Ok(None)                      } @@ -642,7 +658,11 @@ pub async fn recv_iq<Fs: FileStore + Clone>(                              query: None,                              errors: vec![StanzaError::ServiceUnavailable.into()],                          }; -                        connection.write_handle().write(Stanza::Iq(iq)).await?; +                        connection +                            .write_handle() +                            .write(Stanza::Iq(iq)) +                            .await +                            .map_err(|e| Into::<IqError>::into(e))?;                          warn!("replied to unsupported iq get from {}", from);                          Ok(None)                      } // stanza::client::iq::Query::Bind(bind) => todo!(), @@ -662,7 +682,11 @@ pub async fn recv_iq<Fs: FileStore + Clone>(                      query: None,                      errors: vec![StanzaError::BadRequest.into()],                  }; -                connection.write_handle().write(Stanza::Iq(iq)).await?; +                connection +                    .write_handle() +                    .write(Stanza::Iq(iq)) +                    .await +                    .map_err(|e| Into::<IqError>::into(e))?;                  info!("replied to malformed iq query from {}", from);                  Ok(None)              } @@ -713,7 +737,12 @@ pub async fn recv_iq<Fs: FileStore + Clone>(                                              .handle_error(RosterError::PushReply(e.into()).into())                                              .await;                                      } -                                    Ok(Some(UpdateMessage::RosterUpdate(contact))) +                                    let user = logic +                                        .db() +                                        .read_user(contact.user_jid.clone()) +                                        .await +                                        .map_err(|e| Into::<RosterError>::into(e))?; +                                    Ok(Some(UpdateMessage::RosterUpdate(contact, user)))                                  }                              }                          } else { @@ -727,7 +756,11 @@ pub async fn recv_iq<Fs: FileStore + Clone>(                                  query: None,                                  errors: vec![StanzaError::NotAcceptable.into()],                              }; -                            connection.write_handle().write(Stanza::Iq(iq)).await?; +                            connection +                                .write_handle() +                                .write(Stanza::Iq(iq)) +                                .await +                                .map_err(|e| Into::<IqError>::into(e))?;                              Ok(None)                          }                      } @@ -743,7 +776,11 @@ pub async fn recv_iq<Fs: FileStore + Clone>(                              query: None,                              errors: vec![StanzaError::ServiceUnavailable.into()],                          }; -                        connection.write_handle().write(Stanza::Iq(iq)).await?; +                        connection +                            .write_handle() +                            .write(Stanza::Iq(iq)) +                            .await +                            .map_err(|e| Into::<IqError>::into(e))?;                          warn!("replied to unsupported iq set from {}", from);                          Ok(None)                      } @@ -759,7 +796,11 @@ pub async fn recv_iq<Fs: FileStore + Clone>(                      query: None,                      errors: vec![StanzaError::NotAcceptable.into()],                  }; -                connection.write_handle().write(Stanza::Iq(iq)).await?; +                connection +                    .write_handle() +                    .write(Stanza::Iq(iq)) +                    .await +                    .map_err(|e| Into::<IqError>::into(e))?;                  Ok(None)              }          } | 
