From 4871ec668d5b4c313979fffac218936389d5f23b Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 27 May 2017 22:38:35 +0100 Subject: [PATCH] make IbbPlugin add its feature to DiscoPlugin --- examples/client.rs | 1 + src/plugins/ibb.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/examples/client.rs b/examples/client.rs index 16fe4db8..93c2bcc3 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 80000387..27646a0f 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 {