forked from lavina/lavina
Test empty mam response
This commit is contained in:
parent
99a49feff9
commit
e26715eb20
|
@ -1,7 +1,6 @@
|
||||||
//! Handling of all client2server iq stanzas
|
//! Handling of all client2server iq stanzas
|
||||||
|
|
||||||
use quick_xml::events::Event;
|
use quick_xml::events::Event;
|
||||||
use serde::de::Unexpected::Option;
|
|
||||||
|
|
||||||
use lavina_core::room::{RoomId, RoomRegistry};
|
use lavina_core::room::{RoomId, RoomRegistry};
|
||||||
use proto_xmpp::bind::{BindResponse, Jid, Name, Server};
|
use proto_xmpp::bind::{BindResponse, Jid, Name, Server};
|
||||||
|
|
|
@ -449,8 +449,21 @@ async fn test_message_archive_request() -> Result<()> {
|
||||||
|
|
||||||
s.send(r#"<iq type='get' id='juliet1'><query xmlns='urn:xmpp:mam:2' queryid='f27'/></iq>"#).await?;
|
s.send(r#"<iq type='get' id='juliet1'><query xmlns='urn:xmpp:mam:2' queryid='f27'/></iq>"#).await?;
|
||||||
assert_matches!(s.next_xml_event().await?, Event::Start(b) => {
|
assert_matches!(s.next_xml_event().await?, Event::Start(b) => {
|
||||||
assert_eq!(element_name(&b.local_name()), "message")
|
assert_eq!(element_name(&b.local_name()), "iq")
|
||||||
});
|
});
|
||||||
|
assert_matches!(s.next_xml_event().await?, Event::Start(b) => {
|
||||||
|
assert_eq!(element_name(&b.local_name()), "fin")
|
||||||
|
});
|
||||||
|
assert_matches!(s.next_xml_event().await?, Event::Start(b) => {
|
||||||
|
assert_eq!(element_name(&b.local_name()), "set")
|
||||||
|
});
|
||||||
|
assert_matches!(s.next_xml_event().await?, Event::Start(b) => {
|
||||||
|
assert_eq!(element_name(&b.local_name()), "count")
|
||||||
|
});
|
||||||
|
assert_matches!(s.next_xml_event().await?, Event::Text(b) => {
|
||||||
|
assert_eq!(&*b, b"0")
|
||||||
|
});
|
||||||
|
|
||||||
s.send(r#"<presence xmlns="jabber:client" type="unavailable"><status>Logged out</status></presence>"#).await?;
|
s.send(r#"<presence xmlns="jabber:client" type="unavailable"><status>Logged out</status></presence>"#).await?;
|
||||||
|
|
||||||
stream.shutdown().await?;
|
stream.shutdown().await?;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use quick_xml::events::{BytesStart, Event};
|
use quick_xml::events::{BytesEnd, BytesStart, BytesText, Event};
|
||||||
use quick_xml::name::{Namespace, ResolveResult};
|
use quick_xml::name::{Namespace, ResolveResult};
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
|
@ -25,10 +25,12 @@ pub struct Field {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Message archive response styled as a result set.
|
// Message archive response styled as a result set.
|
||||||
|
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||||
pub struct Fin {
|
pub struct Fin {
|
||||||
pub set: Set,
|
pub set: Set,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||||
pub struct Set {
|
pub struct Set {
|
||||||
pub count: Option<i32>,
|
pub count: Option<i32>,
|
||||||
}
|
}
|
||||||
|
@ -37,7 +39,10 @@ impl FromXml for Set {
|
||||||
type P = impl Parser<Output = Result<Self>>;
|
type P = impl Parser<Output = Result<Self>>;
|
||||||
|
|
||||||
fn parse() -> Self::P {
|
fn parse() -> Self::P {
|
||||||
todo!()
|
|(mut namespace, mut event): (ResolveResult<'static>, &'static Event<'static>)| -> Result<Self> {
|
||||||
|
(namespace, event) = yield;
|
||||||
|
Ok(Set { count: Some(0) })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +55,12 @@ impl FromXml for Fin {
|
||||||
type P = impl Parser<Output = Result<Self>>;
|
type P = impl Parser<Output = Result<Self>>;
|
||||||
|
|
||||||
fn parse() -> Self::P {
|
fn parse() -> Self::P {
|
||||||
todo!()
|
|(mut namespace, mut event): (ResolveResult<'static>, &'static Event<'static>)| -> Result<Self> {
|
||||||
|
(namespace, event) = yield;
|
||||||
|
Ok(Fin {
|
||||||
|
set: Set { count: Some(0) },
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,15 +71,18 @@ impl FromXmlTag for Fin {
|
||||||
|
|
||||||
impl ToXml for Fin {
|
impl ToXml for Fin {
|
||||||
fn serialize(&self, events: &mut Vec<Event<'static>>) {
|
fn serialize(&self, events: &mut Vec<Event<'static>>) {
|
||||||
events.push(Event::Start(format!(r#"fin xmlns="{}" complete=True"#, Fin::NS)));
|
let mut fin_bytes = BytesStart::new(format!(r#"fin xmlns="{}" complete=True"#, Fin::NS));
|
||||||
events.push(Event::Start(format!(r#"set xmlns="{}""#, Set::NS)));
|
let mut set_bytes = BytesStart::new(format!(r#"set xmlns="{}""#, Set::NS));
|
||||||
|
events.push(Event::Start(fin_bytes));
|
||||||
|
events.push(Event::Start(set_bytes));
|
||||||
|
|
||||||
if let Some(count) = &self.set.count {
|
if let Some(count) = &self.set.count {
|
||||||
events.push(Event::Start("count".into()));
|
events.push(Event::Start(BytesStart::new("count")));
|
||||||
events.push(Event::Text("0".into()));
|
events.push(Event::Text(BytesText::new("0")));
|
||||||
events.push(Event::End("count".into()));
|
events.push(Event::End(BytesEnd::new("count")));
|
||||||
}
|
}
|
||||||
events.push(Event::End("set".into()));
|
events.push(Event::End(BytesEnd::new("set")));
|
||||||
events.push(Event::End("fin".into()));
|
events.push(Event::End(BytesEnd::new("fin")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue