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

lumi created

Change summary

src/plugins/messaging.rs | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)

Detailed changes

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 {