diff options
Diffstat (limited to 'stanza/src/xep_0060')
| -rw-r--r-- | stanza/src/xep_0060/errors.rs | 13 | ||||
| -rw-r--r-- | stanza/src/xep_0060/event.rs | 93 | ||||
| -rw-r--r-- | stanza/src/xep_0060/mod.rs | 4 | ||||
| -rw-r--r-- | stanza/src/xep_0060/owner.rs | 57 | ||||
| -rw-r--r-- | stanza/src/xep_0060/pubsub.rs | 103 |
5 files changed, 157 insertions, 113 deletions
diff --git a/stanza/src/xep_0060/errors.rs b/stanza/src/xep_0060/errors.rs index e6817ac..a52ea85 100644 --- a/stanza/src/xep_0060/errors.rs +++ b/stanza/src/xep_0060/errors.rs @@ -1,9 +1,10 @@ +// SPDX-FileCopyrightText: 2025 cel <cel@bunny.garden> +// +// SPDX-License-Identifier: AGPL-3.0-or-later + use std::{fmt::Display, str::FromStr}; -use peanuts::{ - element::{FromElement, IntoElement}, - DeserializeError, Element, -}; +use peanuts::{DeserializeError, Element, FromElement, IntoElement}; use thiserror::Error; use crate::{client::error::ErrorType, stanza_error::Error as StanzaError}; @@ -121,7 +122,7 @@ impl Error { } impl FromElement for Error { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { match element.identify() { (Some(XMLNS), "closed-node") => Ok(Self::ClosedNode), (Some(XMLNS), "configuration-required") => Ok(Self::ConfigurationRequired), @@ -154,7 +155,7 @@ impl FromElement for Error { } impl IntoElement for Error { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { match self { Error::ClosedNode => Element::builder("closed-node", Some(XMLNS)), Error::ConfigurationRequired => Element::builder("configuration-required", Some(XMLNS)), diff --git a/stanza/src/xep_0060/event.rs b/stanza/src/xep_0060/event.rs index d2c150a..f3cae8b 100644 --- a/stanza/src/xep_0060/event.rs +++ b/stanza/src/xep_0060/event.rs @@ -1,13 +1,16 @@ +// SPDX-FileCopyrightText: 2025 cel <cel@bunny.garden> +// +// SPDX-License-Identifier: AGPL-3.0-or-later + use std::str::FromStr; use chrono::{DateTime, Utc}; use jid::JID; -use peanuts::{ - element::{FromElement, IntoElement}, - DeserializeError, Element, -}; +use peanuts::{DeserializeError, Element, FromElement, IntoElement}; use crate::xep_0004::X; +#[cfg(feature = "xep_0084")] +use crate::xep_0084; #[cfg(feature = "xep_0172")] use crate::xep_0172::{self, Nick}; @@ -24,7 +27,7 @@ pub enum Event { } impl FromElement for Event { - fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> { element.check_name("event")?; element.check_namespace(XMLNS)?; @@ -47,7 +50,7 @@ impl FromElement for Event { } impl IntoElement for Event { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { let builder = Element::builder("event", Some(XMLNS)); match self { @@ -68,7 +71,7 @@ pub struct Collection { } impl FromElement for Collection { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("node")?; element.check_namespace(XMLNS)?; @@ -80,7 +83,7 @@ impl FromElement for Collection { } impl IntoElement for Collection { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("collection", Some(XMLNS)) .push_attribute_opt("node", self.node.clone()) .push_child(self.r#type.clone()) @@ -94,7 +97,7 @@ pub enum CollectionType { } impl FromElement for CollectionType { - fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(element: Element) -> peanuts::DeserializeResult<Self> { match element.identify() { (Some(XMLNS), "associate") => { Ok(CollectionType::Associate(Associate::from_element(element)?)) @@ -108,7 +111,7 @@ impl FromElement for CollectionType { } impl IntoElement for CollectionType { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { match self { CollectionType::Associate(associate) => associate.builder(), CollectionType::Disassociate(disassociate) => disassociate.builder(), @@ -122,7 +125,7 @@ pub struct Associate { } impl FromElement for Associate { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("associate")?; element.check_namespace(XMLNS)?; @@ -133,7 +136,7 @@ impl FromElement for Associate { } impl IntoElement for Associate { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("associate", Some(XMLNS)).push_attribute("node", self.node.clone()) } } @@ -144,7 +147,7 @@ pub struct Disassociate { } impl FromElement for Disassociate { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("disassociate")?; element.check_namespace(XMLNS)?; @@ -155,7 +158,7 @@ impl FromElement for Disassociate { } impl IntoElement for Disassociate { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("disassociate", Some(XMLNS)).push_attribute("node", self.node.clone()) } } @@ -167,7 +170,7 @@ pub struct Configuration { } impl FromElement for Configuration { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("configuration")?; element.check_namespace(XMLNS)?; @@ -183,7 +186,7 @@ impl FromElement for Configuration { } impl IntoElement for Configuration { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("configuration", Some(XMLNS)) .push_attribute_opt("node", self.node.clone()) .push_child_opt(self.configuration.clone()) @@ -197,7 +200,7 @@ pub struct Delete { } impl FromElement for Delete { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("delete")?; element.check_namespace(XMLNS)?; @@ -210,7 +213,7 @@ impl FromElement for Delete { } impl IntoElement for Delete { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("delete", Some(XMLNS)) .push_attribute("node", self.node.clone()) .push_child_opt(self.redirect.clone()) @@ -219,12 +222,12 @@ impl IntoElement for Delete { #[derive(Clone, Debug)] pub struct Items { - node: String, - items: ItemsType, + pub node: String, + pub items: ItemsType, } impl FromElement for Items { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("items")?; element.check_namespace(XMLNS)?; @@ -241,7 +244,7 @@ impl FromElement for Items { } impl IntoElement for Items { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { let builder = Element::builder("items", Some(XMLNS)).push_attribute("node", self.node.clone()); @@ -260,13 +263,13 @@ pub enum ItemsType { #[derive(Clone, Debug)] 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 { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("item")?; element.check_namespace(XMLNS)?; @@ -284,7 +287,7 @@ impl FromElement for Item { } impl IntoElement for Item { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("item", Some(XMLNS)) .push_attribute_opt("id", self.id.clone()) .push_attribute_opt("publisher", self.publisher.clone()) @@ -296,24 +299,40 @@ impl IntoElement for Item { pub enum Content { #[cfg(feature = "xep_0172")] Nick(Nick), + #[cfg(feature = "xep_0084")] + AvatarData(xep_0084::Data), + #[cfg(feature = "xep_0084")] + AvatarMetadata(xep_0084::Metadata), Unknown(Element), } impl FromElement for Content { - fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(element: Element) -> peanuts::DeserializeResult<Self> { match element.identify() { #[cfg(feature = "xep_0172")] (Some(xep_0172::XMLNS), "nick") => Ok(Content::Nick(Nick::from_element(element)?)), + #[cfg(feature = "xep_0084")] + (Some(xep_0084::data::XMLNS), "data") => { + Ok(Content::AvatarData(xep_0084::Data::from_element(element)?)) + } + #[cfg(feature = "xep_0084")] + (Some(xep_0084::metadata::XMLNS), "metadata") => Ok(Content::AvatarMetadata( + xep_0084::Metadata::from_element(element)?, + )), _ => Ok(Self::Unknown(element)), } } } impl IntoElement for Content { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { match self { #[cfg(feature = "xep_0172")] Content::Nick(nick) => nick.builder(), + #[cfg(feature = "xep_0084")] + Content::AvatarData(data) => data.builder(), + #[cfg(feature = "xep_0084")] + Content::AvatarMetadata(metadata) => metadata.builder(), Content::Unknown(_e) => panic!("unknown content cannot be serialized"), } } @@ -325,7 +344,7 @@ pub struct Purge { } impl FromElement for Purge { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("purge")?; element.check_namespace(XMLNS)?; @@ -336,7 +355,7 @@ impl FromElement for Purge { } impl IntoElement for Purge { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("purge", Some(XMLNS)).push_attribute("node", self.node.clone()) } } @@ -347,7 +366,7 @@ pub struct Redirect { } impl FromElement for Redirect { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("redirect")?; element.check_namespace(XMLNS)?; @@ -358,7 +377,7 @@ impl FromElement for Redirect { } impl IntoElement for Redirect { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("redirect", Some(XMLNS)).push_attribute("uri", self.uri.clone()) } } @@ -369,7 +388,7 @@ pub struct Retract { } impl FromElement for Retract { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("retract")?; element.check_namespace(XMLNS)?; @@ -380,7 +399,7 @@ impl FromElement for Retract { } impl IntoElement for Retract { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("retract", Some(XMLNS)).push_attribute("id", self.id.clone()) } } @@ -395,7 +414,7 @@ pub struct Subscription { } impl FromElement for Subscription { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("subscription")?; element.check_namespace(XMLNS)?; @@ -416,7 +435,7 @@ impl FromElement for Subscription { } impl IntoElement for Subscription { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("subscription", Some(XMLNS)) .push_attribute_opt("expiry", self.expiry) .push_attribute("jid", self.jid.clone()) diff --git a/stanza/src/xep_0060/mod.rs b/stanza/src/xep_0060/mod.rs index 566310f..ac8a849 100644 --- a/stanza/src/xep_0060/mod.rs +++ b/stanza/src/xep_0060/mod.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 cel <cel@bunny.garden> +// +// SPDX-License-Identifier: AGPL-3.0-or-later + pub mod errors; pub mod event; pub mod owner; diff --git a/stanza/src/xep_0060/owner.rs b/stanza/src/xep_0060/owner.rs index 1fedc60..3b6c6f6 100644 --- a/stanza/src/xep_0060/owner.rs +++ b/stanza/src/xep_0060/owner.rs @@ -1,10 +1,11 @@ +// SPDX-FileCopyrightText: 2025 cel <cel@bunny.garden> +// +// SPDX-License-Identifier: AGPL-3.0-or-later + use std::str::FromStr; -use jid::JID; -use peanuts::{ - element::{FromElement, IntoElement}, - DeserializeError, Element, -}; +use jid::{BareJID, JID}; +use peanuts::{DeserializeError, Element, FromElement, IntoElement}; use crate::xep_0004::X; @@ -21,7 +22,7 @@ pub enum Pubsub { } impl FromElement for Pubsub { - fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> { element.check_name("pubsub")?; element.check_namespace(XMLNS)?; @@ -44,7 +45,7 @@ impl FromElement for Pubsub { } impl IntoElement for Pubsub { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { let builder = Element::builder("pubsub", Some(XMLNS)); match self { @@ -65,7 +66,7 @@ pub struct Affiliations { } impl FromElement for Affiliations { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("affiliations")?; element.check_namespace(XMLNS)?; @@ -78,7 +79,7 @@ impl FromElement for Affiliations { } impl IntoElement for Affiliations { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("affiliations", Some(XMLNS)) .push_attribute("node", self.node.clone()) .push_children(self.affiliations.clone()) @@ -88,11 +89,11 @@ impl IntoElement for Affiliations { #[derive(Clone, Debug)] pub struct Affiliation { affiliation: AffiliationType, - jid: JID, + jid: BareJID, } impl FromElement for Affiliation { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("affiliation")?; element.check_namespace(XMLNS)?; @@ -104,7 +105,7 @@ impl FromElement for Affiliation { } impl IntoElement for Affiliation { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("affiliation", Some(XMLNS)) .push_attribute("affiliation", self.affiliation.clone()) .push_attribute("jid", self.jid.clone()) @@ -158,7 +159,7 @@ pub struct Configure { } impl FromElement for Configure { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("configure")?; element.check_namespace(XMLNS)?; @@ -171,7 +172,7 @@ impl FromElement for Configure { } impl IntoElement for Configure { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("configure", Some(XMLNS)) .push_attribute_opt("node", self.node.clone()) .push_child_opt(self.configure.clone()) @@ -182,7 +183,7 @@ impl IntoElement for Configure { pub struct Default(Option<X>); impl FromElement for Default { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("default")?; element.check_namespace(XMLNS)?; @@ -191,19 +192,19 @@ impl FromElement for Default { } impl IntoElement for Default { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("default", Some(XMLNS)).push_child_opt(self.0.clone()) } } #[derive(Clone, Debug)] pub struct Delete { - node: String, - redirect: Option<Redirect>, + pub node: String, + pub redirect: Option<Redirect>, } impl FromElement for Delete { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("delete")?; element.check_namespace(XMLNS)?; @@ -216,7 +217,7 @@ impl FromElement for Delete { } impl IntoElement for Delete { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("delete", Some(XMLNS)) .push_attribute("node", self.node.clone()) .push_child_opt(self.redirect.clone()) @@ -229,7 +230,7 @@ pub struct Purge { } impl FromElement for Purge { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("purge")?; element.check_namespace(XMLNS)?; @@ -240,7 +241,7 @@ impl FromElement for Purge { } impl IntoElement for Purge { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("purge", Some(XMLNS)).push_attribute("node", self.node.clone()) } } @@ -251,7 +252,7 @@ pub struct Redirect { } impl FromElement for Redirect { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("redirect")?; element.check_namespace(XMLNS)?; @@ -262,7 +263,7 @@ impl FromElement for Redirect { } impl IntoElement for Redirect { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("redirect", Some(XMLNS)).push_attribute("uri", self.uri.clone()) } } @@ -274,7 +275,7 @@ pub struct Subscriptions { } impl FromElement for Subscriptions { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("subscriptions")?; element.check_namespace(XMLNS)?; @@ -290,7 +291,7 @@ impl FromElement for Subscriptions { } impl IntoElement for Subscriptions { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("subscriptions", Some(XMLNS)) .push_attribute("node", self.node.clone()) .push_children(self.subscriptions.clone()) @@ -304,7 +305,7 @@ pub struct Subscription { } impl FromElement for Subscription { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("subscription")?; element.check_namespace(XMLNS)?; @@ -316,7 +317,7 @@ impl FromElement for Subscription { } impl IntoElement for Subscription { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("subscription", Some(XMLNS)) .push_attribute("subscription", self.subscription.clone()) .push_attribute("jid", self.jid.clone()) diff --git a/stanza/src/xep_0060/pubsub.rs b/stanza/src/xep_0060/pubsub.rs index 25fc405..94277b9 100644 --- a/stanza/src/xep_0060/pubsub.rs +++ b/stanza/src/xep_0060/pubsub.rs @@ -1,12 +1,15 @@ +// SPDX-FileCopyrightText: 2025 cel <cel@bunny.garden> +// +// SPDX-License-Identifier: AGPL-3.0-or-later + use std::str::FromStr; use jid::JID; -use peanuts::{ - element::{FromElement, IntoElement}, - DeserializeError, Element, -}; +use peanuts::{DeserializeError, Element, FromElement, IntoElement}; use crate::xep_0004::X; +#[cfg(feature = "xep_0084")] +use crate::xep_0084; #[cfg(feature = "xep_0172")] use crate::xep_0172::{self, Nick}; @@ -28,7 +31,7 @@ pub enum Pubsub { } impl FromElement for Pubsub { - fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> { element.check_name("pubsub")?; element.check_namespace(XMLNS)?; @@ -79,7 +82,7 @@ impl FromElement for Pubsub { } impl IntoElement for Pubsub { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { let element = Element::builder("pubsub", Some(XMLNS)); match self { @@ -111,7 +114,7 @@ pub struct Affiliations { } impl FromElement for Affiliations { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("affiliations")?; element.check_namespace(XMLNS)?; @@ -124,7 +127,7 @@ impl FromElement for Affiliations { } impl IntoElement for Affiliations { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("affilations", Some(XMLNS)) .push_attribute_opt("node", self.node.clone()) .push_children(self.affiliations.clone()) @@ -139,7 +142,7 @@ pub struct Affiliation { } impl FromElement for Affiliation { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("affiliation")?; element.check_namespace(XMLNS)?; @@ -151,7 +154,7 @@ impl FromElement for Affiliation { } impl IntoElement for Affiliation { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("affiliation", Some(XMLNS)) .push_attribute("affiliation", self.affiliation.clone()) .push_attribute("node", self.node.clone()) @@ -202,7 +205,7 @@ impl ToString for AffiliationType { pub struct Configure(Option<X>); impl FromElement for Configure { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("configure")?; element.check_namespace(XMLNS)?; @@ -211,7 +214,7 @@ impl FromElement for Configure { } impl IntoElement for Configure { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("configure", Some(XMLNS)).push_child_opt(self.0.clone()) } } @@ -222,7 +225,7 @@ pub struct Create { } impl FromElement for Create { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("create")?; element.check_namespace(XMLNS)?; @@ -233,7 +236,7 @@ impl FromElement for Create { } impl IntoElement for Create { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("create", Some(XMLNS)).push_attribute_opt("node", self.node.clone()) } } @@ -247,7 +250,7 @@ pub struct Default { } impl FromElement for Default { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("default")?; element.check_namespace(XMLNS)?; @@ -265,7 +268,7 @@ impl FromElement for Default { } impl IntoElement for Default { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("default", Some(XMLNS)) .push_attribute_opt("node", self.node.clone()) .push_attribute_opt("type", self.r#type.clone()) @@ -310,7 +313,7 @@ pub struct Items { } impl FromElement for Items { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("items")?; element.check_namespace(XMLNS)?; @@ -330,7 +333,7 @@ impl FromElement for Items { } impl IntoElement for Items { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("items", Some(XMLNS)) .push_attribute_opt("max_items", self.max_items) .push_attribute("node", self.node.clone()) @@ -347,7 +350,7 @@ pub struct Item { } impl FromElement for Item { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("item")?; element.check_namespace(XMLNS)?; @@ -365,7 +368,7 @@ impl FromElement for Item { } impl IntoElement for Item { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("item", Some(XMLNS)) .push_attribute_opt("id", self.id.clone()) .push_attribute_opt("publisher", self.publisher.clone()) @@ -377,24 +380,40 @@ impl IntoElement for Item { pub enum Content { #[cfg(feature = "xep_0172")] Nick(Nick), + #[cfg(feature = "xep_0084")] + AvatarData(xep_0084::Data), + #[cfg(feature = "xep_0084")] + AvatarMetadata(xep_0084::Metadata), Unknown(Element), } impl FromElement for Content { - fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(element: Element) -> peanuts::DeserializeResult<Self> { match element.identify() { #[cfg(feature = "xep_0172")] (Some(xep_0172::XMLNS), "nick") => Ok(Content::Nick(Nick::from_element(element)?)), + #[cfg(feature = "xep_0084")] + (Some(xep_0084::data::XMLNS), "data") => { + Ok(Content::AvatarData(xep_0084::Data::from_element(element)?)) + } + #[cfg(feature = "xep_0084")] + (Some(xep_0084::metadata::XMLNS), "metadata") => Ok(Content::AvatarMetadata( + xep_0084::Metadata::from_element(element)?, + )), _ => Ok(Self::Unknown(element)), } } } impl IntoElement for Content { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { match self { #[cfg(feature = "xep_0172")] Content::Nick(nick) => nick.builder(), + #[cfg(feature = "xep_0084")] + Content::AvatarData(data) => data.builder(), + #[cfg(feature = "xep_0084")] + Content::AvatarMetadata(metadata) => metadata.builder(), Content::Unknown(_e) => panic!("unknown content cannot be serialized"), } } @@ -409,7 +428,7 @@ pub struct Options { } impl FromElement for Options { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("options")?; element.check_namespace(XMLNS)?; @@ -429,7 +448,7 @@ impl FromElement for Options { } impl IntoElement for Options { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("options", Some(XMLNS)) .push_attribute("jid", self.jid.clone()) .push_attribute_opt("node", self.node.clone()) @@ -445,7 +464,7 @@ pub struct Publish { } impl FromElement for Publish { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("publish")?; element.check_namespace(XMLNS)?; @@ -458,7 +477,7 @@ impl FromElement for Publish { } impl IntoElement for Publish { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("publish", Some(XMLNS)) .push_attribute("node", self.node.clone()) .push_children(self.items.clone()) @@ -469,7 +488,7 @@ impl IntoElement for Publish { pub struct PublishOptions(pub Option<X>); impl FromElement for PublishOptions { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("publish-options")?; element.check_namespace(XMLNS)?; @@ -478,7 +497,7 @@ impl FromElement for PublishOptions { } impl IntoElement for PublishOptions { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("publish-options", Some(XMLNS)).push_child_opt(self.0.clone()) } } @@ -492,7 +511,7 @@ pub struct Retract { } impl FromElement for Retract { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("retract")?; element.check_namespace(XMLNS)?; @@ -510,7 +529,7 @@ impl FromElement for Retract { } impl IntoElement for Retract { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("retract", Some(XMLNS)) .push_attribute("node", self.node.clone()) .push_attribute_opt("notify", self.notify) @@ -525,7 +544,7 @@ pub struct SubscribeOptions { } impl FromElement for SubscribeOptions { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("subscribe-options")?; element.check_namespace(XMLNS)?; @@ -541,7 +560,7 @@ impl FromElement for SubscribeOptions { } impl IntoElement for SubscribeOptions { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { let builder = Element::builder("subscribe-options", Some(XMLNS)); if self.required { @@ -555,7 +574,7 @@ impl IntoElement for SubscribeOptions { pub struct Required; impl FromElement for Required { - fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("required")?; element.check_namespace(XMLNS)?; @@ -564,7 +583,7 @@ impl FromElement for Required { } impl IntoElement for Required { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("required", Some(XMLNS)) } } @@ -576,7 +595,7 @@ pub struct Subscribe { } impl FromElement for Subscribe { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("subscribe")?; element.check_namespace(XMLNS)?; @@ -588,7 +607,7 @@ impl FromElement for Subscribe { } impl IntoElement for Subscribe { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("subscribe", Some(XMLNS)) .push_attribute("jid", self.jid.clone()) .push_attribute_opt("node", self.node.clone()) @@ -602,7 +621,7 @@ pub struct Subscriptions { } impl FromElement for Subscriptions { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("subscriptions")?; element.check_namespace(XMLNS)?; @@ -618,7 +637,7 @@ impl FromElement for Subscriptions { } impl IntoElement for Subscriptions { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("subscriptions", Some(XMLNS)) .push_attribute_opt("node", self.node.clone()) .push_children(self.subscriptions.clone()) @@ -635,7 +654,7 @@ pub struct Subscription { } impl FromElement for Subscription { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("subscription")?; element.check_namespace(XMLNS)?; @@ -657,7 +676,7 @@ impl FromElement for Subscription { } impl IntoElement for Subscription { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("subscription", Some(XMLNS)) .push_attribute("jid", self.jid.clone()) .push_attribute_opt("node", self.node.clone()) @@ -709,7 +728,7 @@ pub struct Unsubscribe { } impl FromElement for Unsubscribe { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("unsubscribe")?; element.check_namespace(XMLNS)?; @@ -722,7 +741,7 @@ impl FromElement for Unsubscribe { } impl IntoElement for Unsubscribe { - fn builder(&self) -> peanuts::element::ElementBuilder { + fn builder(&self) -> peanuts::ElementBuilder { Element::builder("unsubscribe", Some(XMLNS)) .push_attribute("jid", self.jid.clone()) .push_attribute_opt("node", self.node.clone()) |
