make PingPlugin add its feature to DiscoPlugin
This commit is contained in:
parent
990519f7b6
commit
4c937ccfc0
2 changed files with 21 additions and 0 deletions
|
@ -27,6 +27,7 @@ fn main() {
|
||||||
client.register_plugin(DiscoPlugin::new("client", "bot", "en", "xmpp-rs"));
|
client.register_plugin(DiscoPlugin::new("client", "bot", "en", "xmpp-rs"));
|
||||||
client.register_plugin(IbbPlugin::new());
|
client.register_plugin(IbbPlugin::new());
|
||||||
client.register_plugin(PingPlugin::new());
|
client.register_plugin(PingPlugin::new());
|
||||||
|
client.plugin::<PingPlugin>().init();
|
||||||
client.register_handler(Priority::Max, |e: &MessageEvent| {
|
client.register_handler(Priority::Max, |e: &MessageEvent| {
|
||||||
println!("{:?}", e);
|
println!("{:?}", e);
|
||||||
Propagation::Continue
|
Propagation::Continue
|
||||||
|
|
|
@ -6,8 +6,10 @@ use error::Error;
|
||||||
use jid::Jid;
|
use jid::Jid;
|
||||||
|
|
||||||
use plugins::stanza::Iq;
|
use plugins::stanza::Iq;
|
||||||
|
use plugins::disco::DiscoPlugin;
|
||||||
use xmpp_parsers::iq::{IqType, IqPayload};
|
use xmpp_parsers::iq::{IqType, IqPayload};
|
||||||
use xmpp_parsers::ping::Ping;
|
use xmpp_parsers::ping::Ping;
|
||||||
|
use xmpp_parsers::ns;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PingEvent {
|
pub struct PingEvent {
|
||||||
|
@ -28,6 +30,24 @@ impl PingPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: make that called automatically after plugins are created.
|
||||||
|
pub fn init(&self) {
|
||||||
|
if let Some(disco) = self.proxy.plugin::<DiscoPlugin>() {
|
||||||
|
disco.add_feature(ns::PING);
|
||||||
|
} else {
|
||||||
|
panic!("Please handle dependencies in the correct order.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: make that called automatically before removal.
|
||||||
|
pub fn deinit(&self) {
|
||||||
|
if let Some(disco) = self.proxy.plugin::<DiscoPlugin>() {
|
||||||
|
disco.remove_feature(ns::PING);
|
||||||
|
} else {
|
||||||
|
panic!("Please handle dependencies in the correct order.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn send_ping(&self, to: &Jid) -> Result<(), Error> {
|
pub fn send_ping(&self, to: &Jid) -> Result<(), Error> {
|
||||||
let to = to.clone();
|
let to = to.clone();
|
||||||
self.proxy.send(Iq {
|
self.proxy.send(Iq {
|
||||||
|
|
Loading…
Reference in a new issue