From e703284539384b461d204c73e7e14daead3f06d9 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Thu, 27 Mar 2025 14:26:27 +0000 Subject: feat: disco info from server --- stanza/src/client/error.rs | 38 ++++++++++++++++++++++++++++++++++++++ stanza/src/xep_0030/info.rs | 6 +++--- 2 files changed, 41 insertions(+), 3 deletions(-) (limited to 'stanza') diff --git a/stanza/src/client/error.rs b/stanza/src/client/error.rs index aa142bf..33bc85e 100644 --- a/stanza/src/client/error.rs +++ b/stanza/src/client/error.rs @@ -99,3 +99,41 @@ impl FromStr for ErrorType { } } } + +impl From for Error { + fn from(value: StanzaError) -> Self { + let error_type = match value { + StanzaError::BadRequest => ErrorType::Modify, + StanzaError::Conflict => ErrorType::Cancel, + // cancel or modify + StanzaError::FeatureNotImplemented => ErrorType::Cancel, + StanzaError::Forbidden => ErrorType::Auth, + StanzaError::Gone(_) => ErrorType::Cancel, + StanzaError::InternalServerError => ErrorType::Cancel, + StanzaError::ItemNotFound => ErrorType::Cancel, + StanzaError::JIDMalformed => ErrorType::Modify, + StanzaError::NotAcceptable => ErrorType::Modify, + StanzaError::NotAllowed => ErrorType::Cancel, + StanzaError::NotAuthorized => ErrorType::Auth, + // modify or wait + StanzaError::PolicyViolation => ErrorType::Modify, + StanzaError::RecipientUnavailable => ErrorType::Wait, + StanzaError::Redirect(_) => ErrorType::Modify, + StanzaError::RegistrationRequired => ErrorType::Auth, + StanzaError::RemoteServerNotFound => ErrorType::Cancel, + StanzaError::RemoteServerTimeout => ErrorType::Wait, + StanzaError::ResourceConstraint => ErrorType::Wait, + StanzaError::ServiceUnavailable => ErrorType::Cancel, + StanzaError::SubscriptionRequired => ErrorType::Auth, + StanzaError::UndefinedCondition => ErrorType::Cancel, + // wait or modify + StanzaError::UnexpectedRequest => ErrorType::Modify, + }; + Self { + by: None, + r#type: error_type, + error: value, + text: None, + } + } +} diff --git a/stanza/src/xep_0030/info.rs b/stanza/src/xep_0030/info.rs index cec2dcb..589fd08 100644 --- a/stanza/src/xep_0030/info.rs +++ b/stanza/src/xep_0030/info.rs @@ -7,9 +7,9 @@ pub const XMLNS: &str = "http://jabber.org/protocol/disco#info"; #[derive(Debug, Clone)] pub struct Query { - node: Option, - features: Vec, - identities: Vec, + pub node: Option, + pub features: Vec, + pub identities: Vec, } impl FromElement for Query { -- cgit