mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
Merge branch 'get_own_jid' into 'master'
Add a get_own_jid method to plugins See merge request !17
This commit is contained in:
commit
6421899c29
3 changed files with 16 additions and 5 deletions
|
@ -81,9 +81,9 @@ impl ClientBuilder {
|
||||||
let transport = Arc::new(Mutex::new(transport));
|
let transport = Arc::new(Mutex::new(transport));
|
||||||
let plugin_container = Arc::new(PluginContainer::new());
|
let plugin_container = Arc::new(PluginContainer::new());
|
||||||
let mut client = Client {
|
let mut client = Client {
|
||||||
jid: self.jid,
|
jid: self.jid.clone(),
|
||||||
transport: transport.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,
|
plugin_container: plugin_container,
|
||||||
dispatcher: dispatcher,
|
dispatcher: dispatcher,
|
||||||
};
|
};
|
||||||
|
|
|
@ -61,9 +61,9 @@ impl ComponentBuilder {
|
||||||
let transport = Arc::new(Mutex::new(transport));
|
let transport = Arc::new(Mutex::new(transport));
|
||||||
let plugin_container = Arc::new(PluginContainer::new());
|
let plugin_container = Arc::new(PluginContainer::new());
|
||||||
let mut component = Component {
|
let mut component = Component {
|
||||||
jid: self.jid,
|
jid: self.jid.clone(),
|
||||||
transport: transport.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,
|
plugin_container: plugin_container,
|
||||||
dispatcher: dispatcher,
|
dispatcher: dispatcher,
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,6 +18,8 @@ use std::mem;
|
||||||
|
|
||||||
use minidom::Element;
|
use minidom::Element;
|
||||||
|
|
||||||
|
use jid::Jid;
|
||||||
|
|
||||||
pub struct PluginContainer {
|
pub struct PluginContainer {
|
||||||
plugins: RwLock<HashMap<TypeId, Arc<Plugin>>>,
|
plugins: RwLock<HashMap<TypeId, Arc<Plugin>>>,
|
||||||
}
|
}
|
||||||
|
@ -70,13 +72,15 @@ impl<P: Plugin> AsRef<P> for PluginRef<P> {
|
||||||
pub struct PluginProxyBinding {
|
pub struct PluginProxyBinding {
|
||||||
dispatcher: Arc<Dispatcher>,
|
dispatcher: Arc<Dispatcher>,
|
||||||
plugin_container: Arc<PluginContainer>,
|
plugin_container: Arc<PluginContainer>,
|
||||||
|
jid: Jid,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PluginProxyBinding {
|
impl PluginProxyBinding {
|
||||||
pub fn new(dispatcher: Arc<Dispatcher>, plugin_container: Arc<PluginContainer>) -> PluginProxyBinding {
|
pub fn new(dispatcher: Arc<Dispatcher>, plugin_container: Arc<PluginContainer>, jid: Jid) -> PluginProxyBinding {
|
||||||
PluginProxyBinding {
|
PluginProxyBinding {
|
||||||
dispatcher: dispatcher,
|
dispatcher: dispatcher,
|
||||||
plugin_container: plugin_container,
|
plugin_container: plugin_container,
|
||||||
|
jid: jid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,6 +145,13 @@ impl PluginProxy {
|
||||||
pub fn send(&self, elem: Element) {
|
pub fn send(&self, elem: Element) {
|
||||||
self.dispatch(SendElement(elem));
|
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.
|
/// A trait whch all plugins should implement.
|
||||||
|
|
Loading…
Reference in a new issue