From 5ebe92c2605d53234afcb1abaa07f391270630f6 Mon Sep 17 00:00:00 2001 From: O01eg Date: Mon, 7 Jan 2019 16:49:33 +0300 Subject: [PATCH] Add ask attribute from RFC3921. Fixes #1 --- src/roster.rs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/roster.rs b/src/roster.rs index 40cc7a25..a64a4793 100644 --- a/src/roster.rs +++ b/src/roster.rs @@ -36,6 +36,14 @@ generate_attribute!( }, Default = None ); +generate_attribute!( + /// The sub-state of subscription with a contact. + Ask, "ask", { + /// Pending sub-state of the 'none' subscription state + Subscribe => "subscribe", + } +); + generate_element!( /// Contact from the user’s contact list. #[derive(PartialEq)] @@ -48,7 +56,10 @@ generate_element!( name: Option = "name" => optional_empty, /// Subscription status of this contact. - subscription: Subscription = "subscription" => default + subscription: Subscription = "subscription" => default, + + /// + ask: Option = "ask" => optional_empty ], children: [ @@ -144,23 +155,42 @@ mod tests { + + MyBuddies + "# .parse() .unwrap(); let roster = Roster::try_from(elem).unwrap(); assert_eq!(roster.ver, Some(String::from("ver11"))); - assert_eq!(roster.items.len(), 3); + assert_eq!(roster.items.len(), 4); assert_eq!( roster.items[0].jid, Jid::from_str("romeo@example.net").unwrap() ); assert_eq!(roster.items[0].name, Some(String::from("Romeo"))); assert_eq!(roster.items[0].subscription, Subscription::Both); + assert_eq!(roster.items[0].ask, None); assert_eq!( roster.items[0].groups, vec!(Group::from_str("Friends").unwrap()) ); + + assert_eq!( + roster.items[3].jid, + Jid::from_str("contact@example.org").unwrap() + ); + assert_eq!(roster.items[3].name, Some(String::from("MyContact"))); + assert_eq!(roster.items[3].subscription, Subscription::None); + assert_eq!(roster.items[3].ask, Some(Ask::Subscribe)); + assert_eq!( + roster.items[3].groups, + vec!(Group::from_str("MyBuddies").unwrap()) + ); } #[test]