make IbbPlugin add its feature to DiscoPlugin

This commit is contained in:
Emmanuel Gil Peyrot 2017-05-27 22:38:35 +01:00
parent 4c937ccfc0
commit 4871ec668d
2 changed files with 21 additions and 0 deletions

View file

@ -28,6 +28,7 @@ fn main() {
client.register_plugin(IbbPlugin::new());
client.register_plugin(PingPlugin::new());
client.plugin::<PingPlugin>().init();
client.plugin::<IbbPlugin>().init();
client.register_handler(Priority::Max, |e: &MessageEvent| {
println!("{:?}", e);
Propagation::Continue

View file

@ -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::<DiscoPlugin>() {
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::<DiscoPlugin>() {
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 {