implement the new event system, things are still really messy
This commit is contained in:
parent
f3b9984ff2
commit
917b14b5d2
11 changed files with 403 additions and 156 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use plugin::{Plugin, PluginReturn, PluginProxy};
|
||||
use event::Event;
|
||||
use plugin::{PluginProxy};
|
||||
use event::{Event, EventHandler, ReceiveElement, Priority, Propagation};
|
||||
use minidom::Element;
|
||||
use error::Error;
|
||||
use jid::Jid;
|
||||
|
|
@ -36,12 +36,13 @@ impl MessagingPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
impl Plugin for MessagingPlugin {
|
||||
fn get_proxy(&mut self) -> &mut PluginProxy {
|
||||
&mut self.proxy
|
||||
}
|
||||
impl_plugin!(MessagingPlugin, proxy, [
|
||||
ReceiveElement => Priority::Default,
|
||||
]);
|
||||
|
||||
fn handle(&mut self, elem: &Element) -> PluginReturn {
|
||||
impl EventHandler<ReceiveElement> for MessagingPlugin {
|
||||
fn handle(&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) {
|
||||
self.proxy.dispatch(MessageEvent { // TODO: safety!!!
|
||||
|
|
@ -51,6 +52,6 @@ impl Plugin for MessagingPlugin {
|
|||
});
|
||||
}
|
||||
}
|
||||
PluginReturn::Continue
|
||||
Propagation::Continue
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use plugin::{Plugin, PluginReturn, PluginProxy};
|
||||
use event::Event;
|
||||
use plugin::PluginProxy;
|
||||
use event::{Event, EventHandler, Priority, Propagation, ReceiveElement};
|
||||
use minidom::Element;
|
||||
use error::Error;
|
||||
use jid::Jid;
|
||||
|
|
@ -45,12 +45,13 @@ impl PingPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
impl Plugin for PingPlugin {
|
||||
fn get_proxy(&mut self) -> &mut PluginProxy {
|
||||
&mut self.proxy
|
||||
}
|
||||
impl_plugin!(PingPlugin, proxy, [
|
||||
ReceiveElement => Priority::Default,
|
||||
]);
|
||||
|
||||
fn handle(&mut self, elem: &Element) -> PluginReturn {
|
||||
impl EventHandler<ReceiveElement> for PingPlugin {
|
||||
fn handle(&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) {
|
||||
self.proxy.dispatch(PingEvent { // TODO: safety!!!
|
||||
|
|
@ -60,6 +61,6 @@ impl Plugin for PingPlugin {
|
|||
});
|
||||
}
|
||||
}
|
||||
PluginReturn::Continue
|
||||
Propagation::Continue
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use error::Error;
|
||||
use plugin::{Plugin, PluginProxy, PluginReturn};
|
||||
use plugin::PluginProxy;
|
||||
|
||||
use minidom::Element;
|
||||
|
||||
|
|
@ -94,12 +94,4 @@ impl PresencePlugin {
|
|||
}
|
||||
}
|
||||
|
||||
impl Plugin for PresencePlugin {
|
||||
fn get_proxy(&mut self) -> &mut PluginProxy {
|
||||
&mut self.proxy
|
||||
}
|
||||
|
||||
fn handle(&mut self, _elem: &Element) -> PluginReturn {
|
||||
PluginReturn::Continue
|
||||
}
|
||||
}
|
||||
impl_plugin!(PresencePlugin, proxy, []);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::fmt::Debug;
|
||||
use std::any::Any;
|
||||
|
||||
use plugin::{Plugin, PluginReturn, PluginProxy};
|
||||
use event::Event;
|
||||
use plugin::PluginProxy;
|
||||
use event::{Event, EventHandler, ReceiveElement, Propagation, Priority};
|
||||
use minidom::Element;
|
||||
use jid::Jid;
|
||||
use ns;
|
||||
|
|
@ -52,12 +52,14 @@ impl StanzaPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
impl Plugin for StanzaPlugin {
|
||||
fn get_proxy(&mut self) -> &mut PluginProxy {
|
||||
&mut self.proxy
|
||||
}
|
||||
impl_plugin!(StanzaPlugin, proxy, [
|
||||
ReceiveElement => Priority::Default,
|
||||
]);
|
||||
|
||||
impl EventHandler<ReceiveElement> for StanzaPlugin {
|
||||
fn handle(&self, evt: &ReceiveElement) -> Propagation {
|
||||
let elem = &evt.0;
|
||||
|
||||
fn handle(&mut self, elem: &Element) -> PluginReturn {
|
||||
let from = match elem.attr("from") { Some(from) => Some(from.parse().unwrap()), None => None };
|
||||
let to = match elem.attr("to") { Some(to) => Some(to.parse().unwrap()), None => None };
|
||||
let id = match elem.attr("id") { Some(id) => Some(id.parse().unwrap()), None => None };
|
||||
|
|
@ -89,6 +91,7 @@ impl Plugin for StanzaPlugin {
|
|||
payloads: payloads,
|
||||
});
|
||||
}
|
||||
PluginReturn::Continue
|
||||
|
||||
Propagation::Continue
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue