forked from lavina/lavina
Serialize delay separately
This commit is contained in:
parent
8dff974df8
commit
6def71b581
|
@ -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)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct XmppHistoryMessage {
|
pub struct XmppHistoryMessage {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
@ -279,40 +306,27 @@ pub struct XmppHistoryMessage {
|
||||||
|
|
||||||
impl ToXml for XmppHistoryMessage {
|
impl ToXml for XmppHistoryMessage {
|
||||||
fn serialize(&self, events: &mut Vec<Event<'static>>) {
|
fn serialize(&self, events: &mut Vec<Event<'static>>) {
|
||||||
let mut tag = BytesStart::new("message");
|
let mut message_tag = BytesStart::new("message");
|
||||||
tag.push_attribute(Attribute {
|
message_tag.push_attribute(Attribute {
|
||||||
key: QName(b"id"),
|
key: QName(b"id"),
|
||||||
value: self.id.as_str().as_bytes().into(),
|
value: self.id.as_str().as_bytes().into(),
|
||||||
});
|
});
|
||||||
tag.push_attribute(Attribute {
|
message_tag.push_attribute(Attribute {
|
||||||
key: QName(b"to"),
|
key: QName(b"to"),
|
||||||
value: self.to.to_string().into_bytes().into(),
|
value: self.to.to_string().into_bytes().into(),
|
||||||
});
|
});
|
||||||
tag.push_attribute(Attribute {
|
message_tag.push_attribute(Attribute {
|
||||||
key: QName(b"from"),
|
key: QName(b"from"),
|
||||||
value: self.from.to_string().into_bytes().into(),
|
value: self.from.to_string().into_bytes().into(),
|
||||||
});
|
});
|
||||||
tag.push_attribute(Attribute {
|
message_tag.push_attribute(Attribute {
|
||||||
key: QName(b"type"),
|
key: QName(b"type"),
|
||||||
value: b"groupchat".into(),
|
value: b"groupchat".into(),
|
||||||
});
|
});
|
||||||
events.push(Event::Start(tag));
|
events.push(Event::Start(message_tag));
|
||||||
let mut tag = BytesStart::new("delay");
|
self.delay.serialize(events);
|
||||||
tag.push_attribute(Attribute {
|
let body_tag = BytesStart::new("body");
|
||||||
key: QName(b"xmlns"),
|
events.push(Event::Start(body_tag));
|
||||||
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::Text(BytesText::new(self.body.to_string().as_str()).into_owned()));
|
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("body")));
|
||||||
events.push(Event::End(BytesEnd::new("message")));
|
events.push(Event::End(BytesEnd::new("message")));
|
||||||
|
|
Loading…
Reference in New Issue