mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
presence: Simplify constructors.
This commit is contained in:
parent
d3157c77f0
commit
cdf80c8979
2 changed files with 36 additions and 6 deletions
|
@ -2,6 +2,8 @@ Version NEXT:
|
||||||
DATE Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
DATE Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
||||||
* New parsers/serialisers:
|
* New parsers/serialisers:
|
||||||
- OpenPGP for XMPP (XEP-0373)
|
- OpenPGP for XMPP (XEP-0373)
|
||||||
|
* Breaking changes:
|
||||||
|
- Presence constructors now take Into<Jid> and assume Some.
|
||||||
|
|
||||||
Version 0.15.0:
|
Version 0.15.0:
|
||||||
2019-09-06 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
2019-09-06 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
||||||
|
|
|
@ -194,21 +194,21 @@ impl Presence {
|
||||||
/// Set the emitter of this presence, this should only be useful for
|
/// Set the emitter of this presence, this should only be useful for
|
||||||
/// servers and components, as clients can only send presences from their
|
/// servers and components, as clients can only send presences from their
|
||||||
/// own resource (which is implicit).
|
/// own resource (which is implicit).
|
||||||
pub fn with_from(mut self, from: Option<Jid>) -> Presence {
|
pub fn with_from<J: Into<Jid>>(mut self, from: J) -> Presence {
|
||||||
self.from = from;
|
self.from = Some(from.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the recipient of this presence, this is only useful for directed
|
/// Set the recipient of this presence, this is only useful for directed
|
||||||
/// presences.
|
/// presences.
|
||||||
pub fn with_to(mut self, to: Option<Jid>) -> Presence {
|
pub fn with_to<J: Into<Jid>>(mut self, to: J) -> Presence {
|
||||||
self.to = to;
|
self.to = Some(to.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the identifier for this presence.
|
/// Set the identifier for this presence.
|
||||||
pub fn with_id(mut self, id: Option<String>) -> Presence {
|
pub fn with_id(mut self, id: String) -> Presence {
|
||||||
self.id = id;
|
self.id = Some(id);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,6 +345,7 @@ impl From<Presence> for Element {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::util::compare_elements::NamespaceAwareCompare;
|
use crate::util::compare_elements::NamespaceAwareCompare;
|
||||||
|
use jid::{BareJid, FullJid};
|
||||||
|
|
||||||
#[cfg(target_pointer_width = "32")]
|
#[cfg(target_pointer_width = "32")]
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -634,4 +635,31 @@ mod tests {
|
||||||
assert!(priority.is("priority", ns::DEFAULT_NS));
|
assert!(priority.is("priority", ns::DEFAULT_NS));
|
||||||
assert_eq!(priority.text(), "42");
|
assert_eq!(priority.text(), "42");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn presence_with_to() {
|
||||||
|
let presence = Presence::new(Type::None);
|
||||||
|
let elem: Element = presence.into();
|
||||||
|
assert_eq!(elem.attr("to"), None);
|
||||||
|
|
||||||
|
let presence = Presence::new(Type::None)
|
||||||
|
.with_to(Jid::Bare(BareJid::domain("localhost")));
|
||||||
|
let elem: Element = presence.into();
|
||||||
|
assert_eq!(elem.attr("to"), Some("localhost"));
|
||||||
|
|
||||||
|
let presence = Presence::new(Type::None)
|
||||||
|
.with_to(BareJid::domain("localhost"));
|
||||||
|
let elem: Element = presence.into();
|
||||||
|
assert_eq!(elem.attr("to"), Some("localhost"));
|
||||||
|
|
||||||
|
let presence = Presence::new(Type::None)
|
||||||
|
.with_to(Jid::Full(FullJid::new("test", "localhost", "coucou")));
|
||||||
|
let elem: Element = presence.into();
|
||||||
|
assert_eq!(elem.attr("to"), Some("test@localhost/coucou"));
|
||||||
|
|
||||||
|
let presence = Presence::new(Type::None)
|
||||||
|
.with_to(FullJid::new("test", "localhost", "coucou"));
|
||||||
|
let elem: Element = presence.into();
|
||||||
|
assert_eq!(elem.attr("to"), Some("test@localhost/coucou"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue