diff --git a/src/client.rs b/src/client.rs index e47616f..bfab174 100644 --- a/src/client.rs +++ b/src/client.rs @@ -81,9 +81,9 @@ impl ClientBuilder { let transport = Arc::new(Mutex::new(transport)); let plugin_container = Arc::new(PluginContainer::new()); let mut client = Client { - jid: self.jid, + jid: self.jid.clone(), transport: transport.clone(), - binding: PluginProxyBinding::new(dispatcher.clone(), plugin_container.clone()), + binding: PluginProxyBinding::new(dispatcher.clone(), plugin_container.clone(), self.jid), plugin_container: plugin_container, dispatcher: dispatcher, }; diff --git a/src/component.rs b/src/component.rs index 63125ba..00592ed 100644 --- a/src/component.rs +++ b/src/component.rs @@ -61,9 +61,9 @@ impl ComponentBuilder { let transport = Arc::new(Mutex::new(transport)); let plugin_container = Arc::new(PluginContainer::new()); let mut component = Component { - jid: self.jid, + jid: self.jid.clone(), transport: transport.clone(), - binding: PluginProxyBinding::new(dispatcher.clone(), plugin_container.clone()), + binding: PluginProxyBinding::new(dispatcher.clone(), plugin_container.clone(), self.jid), plugin_container: plugin_container, dispatcher: dispatcher, }; diff --git a/src/plugin.rs b/src/plugin.rs index e91544e..b41ab2c 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -18,6 +18,8 @@ use std::mem; use minidom::Element; +use jid::Jid; + pub struct PluginContainer { plugins: RwLock>>, } @@ -70,13 +72,15 @@ impl AsRef

for PluginRef

{ pub struct PluginProxyBinding { dispatcher: Arc, plugin_container: Arc, + jid: Jid, } impl PluginProxyBinding { - pub fn new(dispatcher: Arc, plugin_container: Arc) -> PluginProxyBinding { + pub fn new(dispatcher: Arc, plugin_container: Arc, jid: Jid) -> PluginProxyBinding { PluginProxyBinding { dispatcher: dispatcher, plugin_container: plugin_container, + jid: jid, } } } @@ -141,6 +145,13 @@ impl PluginProxy { pub fn send(&self, elem: Element) { self.dispatch(SendElement(elem)); } + + /// Get our own JID. + pub fn get_own_jid(&self) -> Jid { + self.with_binding(|binding| { + binding.jid.clone() + }) + } } /// A trait whch all plugins should implement.