diff options
Diffstat (limited to 'stanza/src/xep_0060')
| -rw-r--r-- | stanza/src/xep_0060/event.rs | 21 | ||||
| -rw-r--r-- | stanza/src/xep_0060/pubsub.rs | 41 | 
2 files changed, 42 insertions, 20 deletions
| diff --git a/stanza/src/xep_0060/event.rs b/stanza/src/xep_0060/event.rs index bdd8b53..d2c150a 100644 --- a/stanza/src/xep_0060/event.rs +++ b/stanza/src/xep_0060/event.rs @@ -8,6 +8,8 @@ use peanuts::{  };  use crate::xep_0004::X; +#[cfg(feature = "xep_0172")] +use crate::xep_0172::{self, Nick};  pub const XMLNS: &str = "http://jabber.org/protocol/pubsub#event"; @@ -292,19 +294,28 @@ impl IntoElement for Item {  #[derive(Clone, Debug)]  pub enum Content { -    Unknown, +    #[cfg(feature = "xep_0172")] +    Nick(Nick), +    Unknown(Element),  }  impl FromElement for Content { -    fn from_element(_element: Element) -> peanuts::element::DeserializeResult<Self> { -        // TODO: types -        return Ok(Self::Unknown); +    fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> { +        match element.identify() { +            #[cfg(feature = "xep_0172")] +            (Some(xep_0172::XMLNS), "nick") => Ok(Content::Nick(Nick::from_element(element)?)), +            _ => Ok(Self::Unknown(element)), +        }      }  }  impl IntoElement for Content {      fn builder(&self) -> peanuts::element::ElementBuilder { -        panic!("unknown content cannot be serialized") +        match self { +            #[cfg(feature = "xep_0172")] +            Content::Nick(nick) => nick.builder(), +            Content::Unknown(_e) => panic!("unknown content cannot be serialized"), +        }      }  } diff --git a/stanza/src/xep_0060/pubsub.rs b/stanza/src/xep_0060/pubsub.rs index 3a15a59..25fc405 100644 --- a/stanza/src/xep_0060/pubsub.rs +++ b/stanza/src/xep_0060/pubsub.rs @@ -7,6 +7,8 @@ use peanuts::{  };  use crate::xep_0004::X; +#[cfg(feature = "xep_0172")] +use crate::xep_0172::{self, Nick};  pub const XMLNS: &str = "http://jabber.org/protocol/pubsub"; @@ -301,10 +303,10 @@ impl ToString for DefaultType {  #[derive(Clone, Debug)]  pub struct Items { -    max_items: Option<usize>, -    node: String, -    subid: Option<String>, -    items: Vec<Item>, +    pub max_items: Option<usize>, +    pub node: String, +    pub subid: Option<String>, +    pub items: Vec<Item>,  }  impl FromElement for Items { @@ -337,11 +339,11 @@ impl IntoElement for Items {      }  } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)]  pub struct Item { -    id: Option<String>, -    publisher: Option<String>, -    item: Option<Content>, +    pub id: Option<String>, +    pub publisher: Option<String>, +    pub item: Option<Content>,  }  impl FromElement for Item { @@ -373,19 +375,28 @@ impl IntoElement for Item {  #[derive(Clone, Debug)]  pub enum Content { -    Unknown, +    #[cfg(feature = "xep_0172")] +    Nick(Nick), +    Unknown(Element),  }  impl FromElement for Content { -    fn from_element(_element: Element) -> peanuts::element::DeserializeResult<Self> { -        // TODO: types -        return Ok(Self::Unknown); +    fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> { +        match element.identify() { +            #[cfg(feature = "xep_0172")] +            (Some(xep_0172::XMLNS), "nick") => Ok(Content::Nick(Nick::from_element(element)?)), +            _ => Ok(Self::Unknown(element)), +        }      }  }  impl IntoElement for Content {      fn builder(&self) -> peanuts::element::ElementBuilder { -        panic!("unknown content cannot be serialized") +        match self { +            #[cfg(feature = "xep_0172")] +            Content::Nick(nick) => nick.builder(), +            Content::Unknown(_e) => panic!("unknown content cannot be serialized"), +        }      }  } @@ -429,8 +440,8 @@ impl IntoElement for Options {  #[derive(Clone, Debug)]  pub struct Publish { -    node: String, -    items: Vec<Item>, +    pub node: String, +    pub items: Vec<Item>,  }  impl FromElement for Publish { | 
