From 83839f0ba620eb3121851535f470756b28b0f199 Mon Sep 17 00:00:00 2001 From: lumi Date: Mon, 27 Feb 2017 15:03:08 +0100 Subject: [PATCH] update messaging plugin to support sending messages, still not sure how i'm going to modify the plugin architecture, so stays very unstable for now --- src/plugins/messaging.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/plugins/messaging.rs b/src/plugins/messaging.rs index e06f6ba4f48926f73930ad242d67134d70820003..061e186f65764d9e2721283ccaea92c07cb6b8d1 100644 --- a/src/plugins/messaging.rs +++ b/src/plugins/messaging.rs @@ -1,14 +1,15 @@ use plugin::{Plugin, PluginReturn, PluginProxy}; use event::Event; use minidom::Element; +use error::Error; use jid::Jid; use ns; #[derive(Debug)] pub struct MessageEvent { - from: Jid, - to: Jid, - body: String, + pub from: Jid, + pub to: Jid, + pub body: String, } impl Event for MessageEvent {} @@ -23,6 +24,16 @@ impl MessagingPlugin { proxy: PluginProxy::new(), } } + + pub fn send_message(&self, to: &Jid, body: &str) -> Result<(), Error> { + let mut elem = Element::builder("message") + .attr("type", "chat") + .attr("to", to.to_string()) + .build(); + elem.append_child(Element::builder("body").text(body).build()); + self.proxy.send(elem); + Ok(()) + } } impl Plugin for MessagingPlugin {