diff --git a/parsers/src/disco.rs b/parsers/src/disco.rs index dc23b62..90d85d4 100644 --- a/parsers/src/disco.rs +++ b/parsers/src/disco.rs @@ -161,13 +161,6 @@ impl TryFrom for DiscoInfoResult { "There must be at least one feature in disco#info.", )); } - if !result.features.contains(&Feature { - var: ns::DISCO_INFO.to_owned(), - }) { - return Err(Error::ParseError( - "disco#info feature not present in disco#info.", - )); - } Ok(result) } @@ -400,14 +393,6 @@ mod tests { _ => panic!(), }; assert_eq!(message, "There must be at least one feature in disco#info."); - - let elem: Element = "".parse().unwrap(); - let error = DiscoInfoResult::try_from(elem).unwrap_err(); - let message = match error { - Error::ParseError(string) => string, - _ => panic!(), - }; - assert_eq!(message, "disco#info feature not present in disco#info."); } #[test] diff --git a/xmpp/src/disco/mod.rs b/xmpp/src/disco/mod.rs index eee104a..3c76498 100644 --- a/xmpp/src/disco/mod.rs +++ b/xmpp/src/disco/mod.rs @@ -8,58 +8,17 @@ use tokio_xmpp::connect::ServerConnector; use tokio_xmpp::{ parsers::{ bookmarks, - disco::{DiscoInfoResult, Feature}, + disco::DiscoInfoResult, iq::Iq, ns, private::Query as PrivateXMLQuery, pubsub::pubsub::{Items, PubSub}, - Error as ParsersError, }, - Element, Jid, + Jid, }; use crate::Agent; -// This method is a workaround due to prosody bug https://issues.prosody.im/1664 -// FIXME: To be removed in the future -// The server doesn't return disco#info feature when querying the account -// so we add it manually because we know it's true -pub async fn handle_disco_info_result_payload( - agent: &mut Agent, - payload: Element, - from: Jid, -) { - match DiscoInfoResult::try_from(payload.clone()) { - Ok(disco) => { - handle_disco_info_result(agent, disco, from).await; - } - Err(e) => match e { - ParsersError::ParseError(reason) => { - if reason == "disco#info feature not present in disco#info." { - let mut payload = payload.clone(); - let disco_feature = - Feature::new("http://jabber.org/protocol/disco#info").into(); - payload.append_child(disco_feature); - match DiscoInfoResult::try_from(payload) { - Ok(disco) => { - handle_disco_info_result(agent, disco, from).await; - } - Err(e) => { - panic!("Wrong disco#info format after workaround: {}", e) - } - } - } else { - panic!( - "Wrong disco#info format (reason cannot be worked around): {}", - e - ) - } - } - _ => panic!("Wrong disco#info format: {}", e), - }, - } -} - pub async fn handle_disco_info_result( agent: &mut Agent, disco: DiscoInfoResult, diff --git a/xmpp/src/iq/result.rs b/xmpp/src/iq/result.rs index da88960..26d2ce5 100644 --- a/xmpp/src/iq/result.rs +++ b/xmpp/src/iq/result.rs @@ -6,7 +6,7 @@ use tokio_xmpp::connect::ServerConnector; use tokio_xmpp::{ - parsers::{ns, private::Query as PrivateXMLQuery, roster::Roster}, + parsers::{disco::DiscoInfoResult, ns, private::Query as PrivateXMLQuery, roster::Roster}, Element, Jid, }; @@ -46,6 +46,13 @@ pub async fn handle_iq_result( } } } else if payload.is("query", ns::DISCO_INFO) { - disco::handle_disco_info_result_payload(agent, payload, from).await; + match DiscoInfoResult::try_from(payload.clone()) { + Ok(disco) => { + disco::handle_disco_info_result(agent, disco, from).await; + } + Err(e) => match e { + _ => panic!("Wrong disco#info format: {}", e), + }, + } } }