From 3724465c7279bdf2472088e21365ff75423eb7bc Mon Sep 17 00:00:00 2001 From: Mikhail Date: Wed, 15 May 2024 13:05:24 +0200 Subject: [PATCH] Sketch x tag internals --- crates/proto-xmpp/src/client.rs | 12 ++++++++++++ crates/proto-xmpp/src/muc/mod.rs | 20 ++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/crates/proto-xmpp/src/client.rs b/crates/proto-xmpp/src/client.rs index 7b96507..c9fa8db 100644 --- a/crates/proto-xmpp/src/client.rs +++ b/crates/proto-xmpp/src/client.rs @@ -487,6 +487,7 @@ impl ToXml for Iq { #[derive(PartialEq, Eq, Debug)] pub struct Presence { + pub id: Option, pub to: Option, pub from: Option, pub priority: Option, @@ -499,6 +500,7 @@ pub struct Presence { impl Default for Presence { fn default() -> Self { Self { + id: Default::default(), to: Default::default(), from: Default::default(), priority: Default::default(), @@ -573,6 +575,10 @@ impl FromXml for Presence { let s = std::str::from_utf8(&attr.value)?; p.r#type = Some(s.into()); } + b"id" => { + let s = std::str::from_utf8(&attr.value)?; + p.r#type = Option::from(s.to_string()); + } _ => {} } } @@ -660,6 +666,12 @@ impl ToXml for Presence { value: from.to_string().as_bytes().into(), }]); } + if let Some(ref id) = self.id { + start.extend_attributes([Attribute { + key: QName(b"id"), + value: id.to_string().as_bytes().into(), + }]); + } events.push(Event::Start(start)); if let Some(ref priority) = self.priority { let s = priority.0.to_string(); diff --git a/crates/proto-xmpp/src/muc/mod.rs b/crates/proto-xmpp/src/muc/mod.rs index 61cf933..8ae70d5 100644 --- a/crates/proto-xmpp/src/muc/mod.rs +++ b/crates/proto-xmpp/src/muc/mod.rs @@ -1,6 +1,6 @@ #![allow(unused_variables)] -use quick_xml::events::{BytesStart, Event}; +use quick_xml::events::{BytesEnd, BytesStart, Event}; use quick_xml::name::ResolveResult; use crate::xml::*; @@ -150,7 +150,23 @@ impl ToXml for XUser { fn serialize(&self, output: &mut Vec>) { let mut tag = BytesStart::new("x"); tag.push_attribute(("xmlns", XMLNS_USER)); - output.push(Event::Empty(tag)); + output.push(Event::Start(tag)); + + let mut meg = BytesStart::new("item"); + meg.push_attribute(("affiliation", "owner")); + meg.push_attribute(("role", "moderator")); + meg.push_attribute(("jid", "sauer@localhost")); + output.push(Event::Empty(meg)); + + let mut veg = BytesStart::new("status"); + veg.push_attribute(("code", "100")); + output.push(Event::Empty(veg)); + + let mut veg = BytesStart::new("status"); + veg.push_attribute(("code", "110")); + output.push(Event::Empty(veg)); + + output.push(Event::End(BytesEnd::new("x"))); } }