Serialize delay separately

This commit is contained in:
Mikhail 2024-05-24 11:33:45 +02:00
parent 8dff974df8
commit 6def71b581
1 changed files with 36 additions and 22 deletions

View File

@ -268,6 +268,33 @@ impl Delay {
}
}
impl ToXml for Delay {
fn serialize(&self, events: &mut Vec<Event>) {
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:
<message from="duqedadi@conference.oflor.me/misha" xml:lang="en" to="misha@oflor.me/tux" type="groupchat" id="7ca7cb14-b2af-49c9-bd90-05dabb1113a5">
<delay xmlns="urn:xmpp:delay" stamp="2024-05-17T16:05:28.440337Z" from="duqedadi@conference.oflor.me"/>
<body></body>
</message>
*/
#[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<Event<'static>>) {
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")));