use tokio_xmpp::{
jid::Jid,
minidom::Element,
parsers::{
disco::DiscoInfoQuery,
iq::Iq,
ns,
stanza_error::{DefinedCondition, ErrorType, StanzaError},
},
};
use crate::{Agent, Event};
pub async fn handle_iq_get(
agent: &mut Agent,
_events: &mut Vec<Event>,
from: Jid,
_to: Option<Jid>,
id: String,
payload: Element,
) {
if payload.is("query", ns::DISCO_INFO) {
let query = DiscoInfoQuery::try_from(payload);
match query {
Ok(query) => {
let mut disco_info = agent.disco.clone();
disco_info.node = query.node;
let iq = Iq::from_result(id, Some(disco_info)).with_to(from).into();
let _ = agent.client.send_stanza(iq).await;
}
Err(err) => {
let error = StanzaError::new(
ErrorType::Modify,
DefinedCondition::BadRequest,
"en",
&format!("{}", err),
);
let iq = Iq::from_error(id, error).with_to(from).into();
let _ = agent.client.send_stanza(iq).await;
}
}
} else {
let error = StanzaError::new(
ErrorType::Cancel,
DefinedCondition::ServiceUnavailable,
"en",
"No handler defined for this kind of iq.",
);
let iq = Iq::from_error(id, error).with_to(from).into();
let _ = agent.client.send_stanza(iq).await;
}
}