From 16391e8b5af741193cb21c93dbee15bd77785536 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 28 May 2018 18:45:29 +0200 Subject: [PATCH] muc: Add forgotten handling. --- src/muc/muc.rs | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/muc/muc.rs b/src/muc/muc.rs index 355b089f..27c22d91 100644 --- a/src/muc/muc.rs +++ b/src/muc/muc.rs @@ -5,9 +5,22 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. +use date::DateTime; + +generate_element!( + History, "history", MUC, + attributes: [ + maxchars: Option = "maxchars" => optional, + maxstanzas: Option = "maxstanzas" => optional, + seconds: Option = "seconds" => optional, + since: Option = "since" => optional, + ] +); + generate_element!( Muc, "x", MUC, children: [ - password: Option = ("password", MUC) => String + password: Option = ("password", MUC) => String, + history: Option = ("history", MUC) => History ] ); @@ -17,6 +30,7 @@ mod tests { use try_from::TryFrom; use minidom::Element; use error::Error; + use std::str::FromStr; use compare_elements::NamespaceAwareCompare; #[test] @@ -41,6 +55,7 @@ mod tests { let elem: Element = "".parse().unwrap(); let muc = Muc { password: None, + history: None, }; let elem2 = muc.into(); assert_eq!(elem, elem2); @@ -71,4 +86,27 @@ mod tests { let elem2 = Element::from(muc); assert!(elem1.compare_to(&elem2)); } + + #[test] + fn history() { + let elem: Element = " + + + " + .parse().unwrap(); + let muc = Muc::try_from(elem).unwrap(); + let history = muc.history.unwrap(); + assert_eq!(history.maxstanzas, Some(0)); + assert_eq!(history.maxchars, None); + assert_eq!(history.seconds, None); + assert_eq!(history.since, None); + + let elem: Element = " + + + " + .parse().unwrap(); + let muc = Muc::try_from(elem).unwrap(); + assert_eq!(muc.history.unwrap().since.unwrap(), DateTime::from_str("1970-01-01T00:00:00+00:00").unwrap()); + } }