diff --git a/parsers/ChangeLog b/parsers/ChangeLog index 2296fca05077bf3212a11b1f4ffe42d4250a77da..bbc8ab154c89eb6196fed0bb6b787b9791c1cb70 100644 --- a/parsers/ChangeLog +++ b/parsers/ChangeLog @@ -61,7 +61,6 @@ XXXX-YY-ZZ RELEASER Handshake::from_stream_id_and_password(), with the two parameters having been exchanged, and the stream_id is now a String instead of &str. - - Add a lang property in Presence, to avoid parser errors. - pubsub::Owner is now a wrapper for the pubsub::owner::Paylolad enum, and all its direct children have been merged into this enum (!532) - time::TimeResult has been ported to use xso. Use From/Into to convert @@ -84,6 +83,8 @@ XXXX-YY-ZZ RELEASER 3. the message::Thread type was converted from a single-element tuple-like struct to a struct with named fields to support the optional `parent` attribute. + - presence::Presence has been ported to use xso (!477). It also uses the + message::Lang newtype since !561. * New parsers/serialisers: - Stream Features (RFC 6120) (!400) - Spam Reporting (XEP-0377) (!506) diff --git a/parsers/src/presence.rs b/parsers/src/presence.rs index 9385f83bb09353182322e38ee1e862b1ad81edec..67634ddcdf03adb2f70f59544074934d4bf87b58 100644 --- a/parsers/src/presence.rs +++ b/parsers/src/presence.rs @@ -7,6 +7,7 @@ use xso::{error::Error, AsOptionalXmlText, AsXml, AsXmlText, FromXml, FromXmlText}; +use crate::message::Lang; use crate::ns; use alloc::{borrow::Cow, collections::BTreeMap}; use jid::Jid; @@ -56,7 +57,6 @@ impl AsXmlText for Show { } } -type Lang = String; type Status = String; /// Priority of this presence. This value can go from -128 to 127, defaults to @@ -139,7 +139,7 @@ impl AsOptionalXmlText for Type { /// The main structure representing the `` stanza. #[derive(FromXml, AsXml, Debug, Clone, PartialEq)] -#[xml(namespace = ns::DEFAULT_NS, name = "presence")] +#[xml(namespace = ns::DEFAULT_NS, name = "presence", discard(attribute = "xml:lang"))] pub struct Presence { /// The sender of this presence. #[xml(attribute(default))] @@ -157,18 +157,13 @@ pub struct Presence { #[xml(attribute(default, name = "type"))] pub type_: Type, - /// The xml:lang of this presence stanza. - // TODO: Remove that, it has no place here but helps parsing valid presences. - #[xml(attribute(default, name = "xml:lang"))] - pub lang: Option, - /// The availability of the sender of this presence. #[xml(extract(name = "show", default, fields(text(type_ = Show))))] pub show: Option, /// A localised list of statuses defined in this presence. #[xml(extract(n = .., name = "status", fields( - attribute(type_ = String, name = "xml:lang", default), + attribute(type_ = Lang, name = "xml:lang", default), text(type_ = String), )))] pub statuses: BTreeMap, @@ -191,7 +186,6 @@ impl Presence { to: None, id: None, type_, - lang: None, show: None, statuses: BTreeMap::new(), priority: Priority(0i8), @@ -305,7 +299,7 @@ mod tests { fn test_size() { assert_size!(Show, 1); assert_size!(Type, 1); - assert_size!(Presence, 84); + assert_size!(Presence, 72); } #[cfg(target_pointer_width = "64")] @@ -313,7 +307,7 @@ mod tests { fn test_size() { assert_size!(Show, 1); assert_size!(Type, 1); - assert_size!(Presence, 168); + assert_size!(Presence, 144); } #[test] @@ -588,7 +582,7 @@ mod tests { fn test_serialise_status() { let status = Status::from("Hello world!"); let mut presence = Presence::new(Type::Unavailable); - presence.statuses.insert(String::from(""), status); + presence.statuses.insert(Lang::from(""), status); let elem: Element = presence.into(); assert!(elem.is("presence", ns::DEFAULT_NS)); assert!(elem.children().next().unwrap().is("status", ns::DEFAULT_NS)); diff --git a/tokio-xmpp/examples/echo_bot.rs b/tokio-xmpp/examples/echo_bot.rs index 4be87a4e1c54b0fe5e659b1dadeb249346214c2a..1ea2bc4522cd1e659c0df2473dec243ea649cd13 100644 --- a/tokio-xmpp/examples/echo_bot.rs +++ b/tokio-xmpp/examples/echo_bot.rs @@ -64,7 +64,7 @@ fn make_presence() -> Presence { presence.show = Some(PresenceShow::Chat); presence .statuses - .insert(String::from("en"), String::from("Echoing messages.")); + .insert(Lang::from("en"), String::from("Echoing messages.")); presence } diff --git a/tokio-xmpp/examples/echo_component.rs b/tokio-xmpp/examples/echo_component.rs index de01d8f8213cb0aaf2f221f59a2bd9b3bf3b2329..fffa8fbe13f87abec4b8eb190a86ec2a09c1c5ef 100644 --- a/tokio-xmpp/examples/echo_component.rs +++ b/tokio-xmpp/examples/echo_component.rs @@ -73,7 +73,7 @@ fn make_presence(from: Jid, to: Jid) -> Presence { presence.show = Some(PresenceShow::Chat); presence .statuses - .insert(String::from("en"), String::from("Echoing messages.")); + .insert(Lang::from("en"), String::from("Echoing messages.")); presence }