diff --git a/examples/client.rs b/examples/client.rs index 16fe4db..93c2bcc 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -28,6 +28,7 @@ fn main() { client.register_plugin(IbbPlugin::new()); client.register_plugin(PingPlugin::new()); client.plugin::().init(); + client.plugin::().init(); client.register_handler(Priority::Max, |e: &MessageEvent| { println!("{:?}", e); Propagation::Continue diff --git a/src/plugins/ibb.rs b/src/plugins/ibb.rs index 8000038..27646a0 100644 --- a/src/plugins/ibb.rs +++ b/src/plugins/ibb.rs @@ -8,9 +8,11 @@ use event::{Event, Priority, Propagation}; use jid::Jid; use plugins::stanza::Iq; +use plugins::disco::DiscoPlugin; use xmpp_parsers::iq::{IqType, IqPayload}; use xmpp_parsers::ibb::{IBB, Stanza}; use xmpp_parsers::stanza_error::{StanzaError, ErrorType, DefinedCondition}; +use xmpp_parsers::ns; #[derive(Debug, Clone)] pub struct Session { @@ -66,6 +68,24 @@ impl IbbPlugin { } } + // TODO: make that called automatically after plugins are created. + pub fn init(&self) { + if let Some(disco) = self.proxy.plugin::() { + disco.add_feature(ns::IBB); + } 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::() { + disco.remove_feature(ns::IBB); + } else { + panic!("Please handle dependencies in the correct order."); + } + } + fn handle_ibb(&self, from: Jid, ibb: IBB) -> Result<(), StanzaError> { let mut sessions = self.sessions.lock().unwrap(); match ibb {