From 91f1994af940085d5d475a97820900ebbf0eb553 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Thu, 3 Apr 2025 03:41:38 +0100 Subject: feat: better message handling, pep publish, xep_0172: nick --- stanza/src/xep_0060/pubsub.rs | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'stanza/src/xep_0060/pubsub.rs') 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, - node: String, - subid: Option, - items: Vec, + pub max_items: Option, + pub node: String, + pub subid: Option, + pub items: Vec, } impl FromElement for Items { @@ -337,11 +339,11 @@ impl IntoElement for Items { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct Item { - id: Option, - publisher: Option, - item: Option, + pub id: Option, + pub publisher: Option, + pub item: Option, } 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 { - // TODO: types - return Ok(Self::Unknown); + fn from_element(element: Element) -> peanuts::element::DeserializeResult { + 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, + pub node: String, + pub items: Vec, } impl FromElement for Publish { -- cgit