1use std::collections::BTreeMap;
2
3use error::Error;
4use plugin::PluginProxy;
5
6pub use xmpp_parsers::presence::{Presence, Type, Show};
7
8pub struct PresencePlugin {
9 proxy: PluginProxy,
10}
11
12impl PresencePlugin {
13 pub fn new() -> PresencePlugin {
14 PresencePlugin {
15 proxy: PluginProxy::new(),
16 }
17 }
18
19 pub fn set_presence(&self, type_: Type, show: Show, status: Option<String>) -> Result<(), Error> {
20 let presence = Presence {
21 from: None,
22 to: None,
23 id: Some(self.proxy.gen_id()),
24 type_: type_,
25 show: show,
26 priority: 0i8,
27 statuses: {
28 let mut statuses = BTreeMap::new();
29 if let Some(status) = status {
30 statuses.insert(String::new(), status);
31 }
32 statuses
33 },
34 payloads: vec!(),
35 };
36 self.proxy.send(presence.into());
37 Ok(())
38 }
39}
40
41impl_plugin!(PresencePlugin, proxy, []);