mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
add a disco result event to the disco plugin
This commit is contained in:
parent
51616ae1a5
commit
1b21ebc6b0
1 changed files with 20 additions and 4 deletions
|
@ -6,7 +6,7 @@ use event::{Event, Priority, Propagation};
|
||||||
use jid::Jid;
|
use jid::Jid;
|
||||||
|
|
||||||
use plugins::stanza::Iq;
|
use plugins::stanza::Iq;
|
||||||
use xmpp_parsers::iq::{IqType, IqPayload};
|
use xmpp_parsers::iq::IqType;
|
||||||
use xmpp_parsers::disco::{Disco, Identity, Feature};
|
use xmpp_parsers::disco::{Disco, Identity, Feature};
|
||||||
use xmpp_parsers::data_forms::DataForm;
|
use xmpp_parsers::data_forms::DataForm;
|
||||||
use xmpp_parsers::ns;
|
use xmpp_parsers::ns;
|
||||||
|
@ -18,7 +18,15 @@ pub struct DiscoInfoRequest {
|
||||||
pub node: Option<String>,
|
pub node: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct DiscoInfoResult {
|
||||||
|
pub from: Jid,
|
||||||
|
pub id: String,
|
||||||
|
pub disco: Disco,
|
||||||
|
}
|
||||||
|
|
||||||
impl Event for DiscoInfoRequest {}
|
impl Event for DiscoInfoRequest {}
|
||||||
|
impl Event for DiscoInfoResult {}
|
||||||
|
|
||||||
pub struct DiscoPlugin {
|
pub struct DiscoPlugin {
|
||||||
proxy: PluginProxy,
|
proxy: PluginProxy,
|
||||||
|
@ -88,15 +96,23 @@ impl DiscoPlugin {
|
||||||
fn handle_iq(&self, iq: &Iq) -> Propagation {
|
fn handle_iq(&self, iq: &Iq) -> Propagation {
|
||||||
let iq = iq.clone();
|
let iq = iq.clone();
|
||||||
if let IqType::Get(payload) = iq.payload {
|
if let IqType::Get(payload) = iq.payload {
|
||||||
// TODO: use an intermediate plugin to parse this payload.
|
if let Ok(disco) = Disco::try_from(payload) {
|
||||||
if let Ok(IqPayload::Disco(disco)) = IqPayload::try_from(payload) {
|
self.proxy.dispatch(DiscoInfoRequest {
|
||||||
self.proxy.dispatch(DiscoInfoRequest { // TODO: safety!!!
|
|
||||||
from: iq.from.unwrap(),
|
from: iq.from.unwrap(),
|
||||||
id: iq.id.unwrap(),
|
id: iq.id.unwrap(),
|
||||||
node: disco.node,
|
node: disco.node,
|
||||||
});
|
});
|
||||||
return Propagation::Stop;
|
return Propagation::Stop;
|
||||||
}
|
}
|
||||||
|
} else if let IqType::Result(Some(payload)) = iq.payload {
|
||||||
|
if let Ok(disco) = Disco::try_from(payload) {
|
||||||
|
self.proxy.dispatch(DiscoInfoResult {
|
||||||
|
from: iq.from.unwrap(),
|
||||||
|
id: iq.id.unwrap(),
|
||||||
|
disco: disco,
|
||||||
|
});
|
||||||
|
return Propagation::Stop;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Propagation::Continue
|
Propagation::Continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue