From 6def71b581e829dcf33ce4820b63db5e1df2313b Mon Sep 17 00:00:00 2001 From: Mikhail Date: Fri, 24 May 2024 11:33:45 +0200 Subject: [PATCH] Serialize delay separately --- crates/proto-xmpp/src/muc/mod.rs | 58 ++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/crates/proto-xmpp/src/muc/mod.rs b/crates/proto-xmpp/src/muc/mod.rs index 0f54ee2..2105c4c 100644 --- a/crates/proto-xmpp/src/muc/mod.rs +++ b/crates/proto-xmpp/src/muc/mod.rs @@ -268,6 +268,33 @@ impl Delay { } } +impl ToXml for Delay { + fn serialize(&self, events: &mut Vec) { + let mut tag = BytesStart::new("delay"); + tag.push_attribute(Attribute { + key: QName(b"xmlns"), + value: self.xmlns.as_bytes().into(), + }); + tag.push_attribute(Attribute { + key: QName(b"from"), + value: self.from.to_string().into_bytes().into(), + }); + tag.push_attribute(Attribute { + key: QName(b"stamp"), + value: self.stamp.as_bytes().into(), + }); + events.push(Event::Empty(tag)); + } +} + +/* + Example of an XMPP message with history stanza: + + + + + +*/ #[derive(Debug, PartialEq, Eq)] pub struct XmppHistoryMessage { pub id: String, @@ -279,40 +306,27 @@ pub struct XmppHistoryMessage { impl ToXml for XmppHistoryMessage { fn serialize(&self, events: &mut Vec>) { - let mut tag = BytesStart::new("message"); - tag.push_attribute(Attribute { + let mut message_tag = BytesStart::new("message"); + message_tag.push_attribute(Attribute { key: QName(b"id"), value: self.id.as_str().as_bytes().into(), }); - tag.push_attribute(Attribute { + message_tag.push_attribute(Attribute { key: QName(b"to"), value: self.to.to_string().into_bytes().into(), }); - tag.push_attribute(Attribute { + message_tag.push_attribute(Attribute { key: QName(b"from"), value: self.from.to_string().into_bytes().into(), }); - tag.push_attribute(Attribute { + message_tag.push_attribute(Attribute { key: QName(b"type"), value: b"groupchat".into(), }); - events.push(Event::Start(tag)); - let mut tag = BytesStart::new("delay"); - tag.push_attribute(Attribute { - key: QName(b"xmlns"), - value: self.delay.xmlns.as_bytes().into(), - }); - tag.push_attribute(Attribute { - key: QName(b"from"), - value: self.delay.from.to_string().into_bytes().into(), - }); - tag.push_attribute(Attribute { - key: QName(b"stamp"), - value: self.delay.stamp.as_bytes().into(), - }); - events.push(Event::Empty(tag)); - let mut tag = BytesStart::new("body"); - events.push(Event::Start(tag)); + events.push(Event::Start(message_tag)); + self.delay.serialize(events); + let body_tag = BytesStart::new("body"); + events.push(Event::Start(body_tag)); events.push(Event::Text(BytesText::new(self.body.to_string().as_str()).into_owned())); events.push(Event::End(BytesEnd::new("body"))); events.push(Event::End(BytesEnd::new("message")));