diff --git a/crates/projection-xmpp/src/iq.rs b/crates/projection-xmpp/src/iq.rs index d9351bf..a4cfdcc 100644 --- a/crates/projection-xmpp/src/iq.rs +++ b/crates/projection-xmpp/src/iq.rs @@ -5,7 +5,7 @@ use quick_xml::events::Event; use lavina_core::room::RoomId; use lavina_core::LavinaCore; use proto_xmpp::bind::{BindRequest, BindResponse, Jid, Name, Server}; -use proto_xmpp::client::{Iq, IqError, IqErrorType, IqType}; +use proto_xmpp::client::{Iq, IqError, IqErrorCondition, IqErrorType, IqType}; use proto_xmpp::disco::{Feature, Identity, InfoQuery, Item, ItemQuery}; use proto_xmpp::mam::{Fin, Set}; use proto_xmpp::roster::RosterQuery; @@ -104,6 +104,7 @@ impl<'a> XmppConnection<'a> { r#type: IqType::Error, body: IqError { r#type: IqErrorType::Cancel, + condition: None, }, }; req.serialize(output); @@ -172,6 +173,7 @@ impl<'a> XmppConnection<'a> { // return Err(IqError { r#type: IqErrorType::Cancel, + condition: Some(IqErrorCondition::ItemNotFound), }); }; identity = vec![Identity { diff --git a/crates/proto-xmpp/src/client.rs b/crates/proto-xmpp/src/client.rs index 08d203a..c515e63 100644 --- a/crates/proto-xmpp/src/client.rs +++ b/crates/proto-xmpp/src/client.rs @@ -260,6 +260,18 @@ impl MessageType { /// https://xmpp.org/rfcs/rfc6120.html#stanzas-error pub struct IqError { pub r#type: IqErrorType, + pub condition: Option, +} + +pub enum IqErrorCondition { + ItemNotFound, +} +impl IqErrorCondition { + pub fn as_str(&self) -> &'static str { + match self { + IqErrorCondition::ItemNotFound => "item-not-found", + } + } } pub enum IqErrorType { @@ -289,7 +301,18 @@ impl IqErrorType { impl ToXml for IqError { fn serialize(&self, events: &mut Vec>) { let bytes = BytesStart::new(format!(r#"error xmlns="{}" type="{}""#, XMLNS, self.r#type.as_str())); - events.push(Event::Empty(bytes)); + match self.condition { + None => { + events.push(Event::Empty(bytes)); + } + Some(IqErrorCondition::ItemNotFound) => { + events.push(Event::Start(bytes)); + let bytes2 = BytesStart::new(r#"item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas""#); + events.push(Event::Empty(bytes2)); + let bytes = BytesEnd::new("error"); + events.push(Event::End(bytes)); + } + } } }