fix up the event system, no more unsafe!

This commit is contained in:
lumi 2017-05-27 16:56:44 +02:00
commit c326d5b07e
8 changed files with 110 additions and 150 deletions

View file

@ -1,5 +1,5 @@
use plugin::{PluginProxy};
use event::{Event, EventHandler, ReceiveElement, Priority, Propagation};
use plugin::PluginProxy;
use event::{Event, ReceiveElement, Priority, Propagation};
use minidom::Element;
use error::Error;
use jid::Jid;
@ -34,14 +34,8 @@ impl MessagingPlugin {
self.proxy.send(elem);
Ok(())
}
}
impl_plugin!(MessagingPlugin, proxy, [
ReceiveElement => Priority::Default,
]);
impl EventHandler<ReceiveElement> for MessagingPlugin {
fn handle(&self, evt: &ReceiveElement) -> Propagation {
fn handle_receive_element(&self, evt: &ReceiveElement) -> Propagation {
let elem = &evt.0;
if elem.is("message", ns::CLIENT) && elem.attr("type") == Some("chat") {
if let Some(body) = elem.get_child("body", ns::CLIENT) {
@ -55,3 +49,7 @@ impl EventHandler<ReceiveElement> for MessagingPlugin {
Propagation::Continue
}
}
impl_plugin!(MessagingPlugin, proxy, [
(ReceiveElement, Priority::Default) => handle_receive_element,
]);

View file

@ -1,5 +1,5 @@
use plugin::PluginProxy;
use event::{Event, EventHandler, Priority, Propagation, ReceiveElement};
use event::{Event, Priority, Propagation, ReceiveElement};
use minidom::Element;
use error::Error;
use jid::Jid;
@ -43,14 +43,8 @@ impl PingPlugin {
.build();
self.proxy.send(reply);
}
}
impl_plugin!(PingPlugin, proxy, [
ReceiveElement => Priority::Default,
]);
impl EventHandler<ReceiveElement> for PingPlugin {
fn handle(&self, evt: &ReceiveElement) -> Propagation {
fn handle_receive_element(&self, evt: &ReceiveElement) -> Propagation {
let elem = &evt.0;
if elem.is("iq", ns::CLIENT) && elem.attr("type") == Some("get") {
if elem.has_child("ping", ns::PING) {
@ -64,3 +58,7 @@ impl EventHandler<ReceiveElement> for PingPlugin {
Propagation::Continue
}
}
impl_plugin!(PingPlugin, proxy, [
(ReceiveElement, Priority::Default) => handle_receive_element,
]);

View file

@ -1,7 +1,7 @@
use std::convert::TryFrom;
use plugin::PluginProxy;
use event::{Event, EventHandler, ReceiveElement, Propagation, Priority};
use event::{Event, ReceiveElement, Propagation, Priority};
use ns;
pub use xmpp_parsers::message::Message;
@ -22,14 +22,8 @@ impl StanzaPlugin {
proxy: PluginProxy::new(),
}
}
}
impl_plugin!(StanzaPlugin, proxy, [
ReceiveElement => Priority::Default,
]);
impl EventHandler<ReceiveElement> for StanzaPlugin {
fn handle(&self, evt: &ReceiveElement) -> Propagation {
fn handle_receive_element(&self, evt: &ReceiveElement) -> Propagation {
let elem = &evt.0;
// TODO: make the handle take an Element instead of a reference.
@ -49,3 +43,7 @@ impl EventHandler<ReceiveElement> for StanzaPlugin {
Propagation::Continue
}
}
impl_plugin!(StanzaPlugin, proxy, [
(ReceiveElement, Priority::Default) => handle_receive_element,
]);