diff options
Diffstat (limited to 'stanza/src/client/message.rs')
-rw-r--r-- | stanza/src/client/message.rs | 107 |
1 files changed, 95 insertions, 12 deletions
diff --git a/stanza/src/client/message.rs b/stanza/src/client/message.rs index 78258ca..3a7be9a 100644 --- a/stanza/src/client/message.rs +++ b/stanza/src/client/message.rs @@ -1,10 +1,7 @@ use std::str::FromStr; use jid::JID; -use peanuts::{ - element::{FromElement, IntoElement}, - DeserializeError, Element, XML_NS, -}; +use peanuts::{DeserializeError, Element, FromElement, IntoElement, XML_NS}; #[cfg(feature = "xep_0060")] use crate::xep_0060::event::Event; @@ -14,6 +11,12 @@ use crate::xep_0131::Headers; use crate::xep_0172::Nick; #[cfg(feature = "xep_0203")] use crate::xep_0203::Delay; +#[cfg(feature = "xep_0280")] +use crate::xep_0280::{Private, Received, Sent}; +#[cfg(feature = "xep_0297")] +use crate::xep_0297::Forwarded; +#[cfg(feature = "xep_0334")] +use crate::xep_0334::{NoCopy, NoPermanentStore, NoStore, Store}; use super::XMLNS; @@ -37,10 +40,26 @@ pub struct Message { pub nick: Option<Nick>, #[cfg(feature = "xep_0060")] pub event: Option<Event>, + #[cfg(feature = "xep_0297")] + pub forwarded: Option<Forwarded>, + #[cfg(feature = "xep_0280")] + pub sent: Option<Sent>, + #[cfg(feature = "xep_0280")] + pub received: Option<Received>, + #[cfg(feature = "xep_0280")] + pub private: Option<Private>, + #[cfg(feature = "xep_0334")] + pub no_permanent_store: Option<NoPermanentStore>, + #[cfg(feature = "xep_0334")] + pub no_store: Option<NoStore>, + #[cfg(feature = "xep_0334")] + pub no_copy: Option<NoCopy>, + #[cfg(feature = "xep_0334")] + pub store: Option<Store>, } impl FromElement for Message { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("message")?; element.check_namespace(XMLNS)?; @@ -66,6 +85,30 @@ impl FromElement for Message { #[cfg(feature = "xep_0060")] let event = element.child_opt()?; + #[cfg(feature = "xep_0297")] + let forwarded = element.child_opt()?; + + #[cfg(feature = "xep_0280")] + let sent = element.child_opt()?; + + #[cfg(feature = "xep_0280")] + let received = element.child_opt()?; + + #[cfg(feature = "xep_0280")] + let private = element.child_opt()?; + + #[cfg(feature = "xep_0334")] + let no_permanent_store = element.child_opt()?; + + #[cfg(feature = "xep_0334")] + let no_store = element.child_opt()?; + + #[cfg(feature = "xep_0334")] + let no_copy = element.child_opt()?; + + #[cfg(feature = "xep_0334")] + let store = element.child_opt()?; + Ok(Message { from, id, @@ -83,12 +126,28 @@ impl FromElement for Message { nick, #[cfg(feature = "xep_0060")] event, + #[cfg(feature = "xep_0297")] + forwarded, + #[cfg(feature = "xep_0280")] + sent, + #[cfg(feature = "xep_0280")] + received, + #[cfg(feature = "xep_0280")] + private, + #[cfg(feature = "xep_0334")] + no_permanent_store, + #[cfg(feature = "xep_0334")] + no_store, + #[cfg(feature = "xep_0334")] + no_copy, + #[cfg(feature = "xep_0334")] + store, }) } } impl IntoElement for Message { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { let builder = Element::builder("message", Some(XMLNS)) .push_attribute_opt("from", self.from.clone()) .push_attribute_opt("id", self.id.clone()) @@ -117,6 +176,30 @@ impl IntoElement for Message { #[cfg(feature = "xep_0060")] let builder = builder.push_child_opt(self.event.clone()); + #[cfg(feature = "xep_0297")] + let builder = builder.push_child_opt(self.forwarded.clone()); + + #[cfg(feature = "xep_0280")] + let builder = builder.push_child_opt(self.sent.clone()); + + #[cfg(feature = "xep_0280")] + let builder = builder.push_child_opt(self.received.clone()); + + #[cfg(feature = "xep_0280")] + let builder = builder.push_child_opt(self.private.clone()); + + #[cfg(feature = "xep_0334")] + let builder = builder.push_child_opt(self.no_permanent_store); + + #[cfg(feature = "xep_0334")] + let builder = builder.push_child_opt(self.no_store); + + #[cfg(feature = "xep_0334")] + let builder = builder.push_child_opt(self.no_copy); + + #[cfg(feature = "xep_0334")] + let builder = builder.push_child_opt(self.store); + builder } } @@ -166,7 +249,7 @@ pub struct Body { } impl FromElement for Body { - fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> { element.check_name("body")?; element.check_namespace(XMLNS)?; @@ -178,7 +261,7 @@ impl FromElement for Body { } impl IntoElement for Body { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("body", Some(XMLNS)) .push_attribute_opt_namespaced(XML_NS, "lang", self.lang.clone()) .push_text_opt(self.body.clone()) @@ -192,7 +275,7 @@ pub struct Subject { } impl FromElement for Subject { - fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> { element.check_name("subject")?; element.check_namespace(XMLNS)?; @@ -204,7 +287,7 @@ impl FromElement for Subject { } impl IntoElement for Subject { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("subject", Some(XMLNS)) .push_attribute_opt_namespaced(XML_NS, "lang", self.lang.clone()) .push_text_opt(self.subject.clone()) @@ -218,7 +301,7 @@ pub struct Thread { } impl FromElement for Thread { - fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> { element.check_name("thread")?; element.check_namespace(XMLNS)?; @@ -230,7 +313,7 @@ impl FromElement for Thread { } impl IntoElement for Thread { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("thread", Some(XMLNS)) .push_attribute_opt("parent", self.parent.clone()) .push_text_opt(self.thread.clone()) |