forked from lavina/lavina
Describe response with count 0
This commit is contained in:
parent
45bd3f3819
commit
99a49feff9
|
@ -1,19 +1,20 @@
|
||||||
//! 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};
|
||||||
use proto_xmpp::client::{Iq, IqError, IqErrorType, IqType, Message, MessageType};
|
use proto_xmpp::client::{Iq, IqError, IqErrorType, IqType, Message, MessageType};
|
||||||
use proto_xmpp::disco::{Feature, Identity, InfoQuery, Item, ItemQuery};
|
use proto_xmpp::disco::{Feature, Identity, InfoQuery, Item, ItemQuery};
|
||||||
|
use proto_xmpp::mam::{Fin, Set};
|
||||||
use proto_xmpp::roster::RosterQuery;
|
use proto_xmpp::roster::RosterQuery;
|
||||||
use proto_xmpp::session::Session;
|
use proto_xmpp::session::Session;
|
||||||
|
use proto_xmpp::xml::ToXml;
|
||||||
|
|
||||||
use crate::proto::IqClientBody;
|
use crate::proto::IqClientBody;
|
||||||
use crate::XmppConnection;
|
use crate::XmppConnection;
|
||||||
|
|
||||||
use proto_xmpp::xml::{Ignore, ToXml};
|
|
||||||
|
|
||||||
impl<'a> XmppConnection<'a> {
|
impl<'a> XmppConnection<'a> {
|
||||||
pub async fn handle_iq(&self, output: &mut Vec<Event<'static>>, iq: Iq<IqClientBody>) {
|
pub async fn handle_iq(&self, output: &mut Vec<Event<'static>>, iq: Iq<IqClientBody>) {
|
||||||
match iq.body {
|
match iq.body {
|
||||||
|
@ -88,14 +89,16 @@ impl<'a> XmppConnection<'a> {
|
||||||
req.serialize(output);
|
req.serialize(output);
|
||||||
}
|
}
|
||||||
IqClientBody::MessageArchiveRequest(request) => {
|
IqClientBody::MessageArchiveRequest(request) => {
|
||||||
let response = self.mam().await;
|
// let response = self.mam().await;
|
||||||
// let req = Iq {
|
let response = Iq {
|
||||||
// from: iq.to,
|
from: iq.to,
|
||||||
// id: iq.id,
|
id: iq.id,
|
||||||
// to: None,
|
to: None,
|
||||||
// r#type: IqType::Result,
|
r#type: IqType::Result,
|
||||||
// body: response,
|
body: Fin {
|
||||||
// };
|
set: Set { count: Some(0) },
|
||||||
|
},
|
||||||
|
};
|
||||||
response.serialize(output);
|
response.serialize(output);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use quick_xml::events::Event;
|
use quick_xml::events::{BytesStart, Event};
|
||||||
use quick_xml::name::{Namespace, ResolveResult};
|
use quick_xml::name::{Namespace, ResolveResult};
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ use crate::xml::*;
|
||||||
|
|
||||||
pub const MAM_XMLNS: &'static str = "urn:xmpp:mam:2";
|
pub const MAM_XMLNS: &'static str = "urn:xmpp:mam:2";
|
||||||
pub const DATA_XMLNS: &'static str = "jabber:x:data";
|
pub const DATA_XMLNS: &'static str = "jabber:x:data";
|
||||||
|
pub const RESULT_SET_XMLNS: &'static str = "http://jabber.org/protocol/rsm";
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||||
pub struct MessageArchiveRequest {
|
pub struct MessageArchiveRequest {
|
||||||
|
@ -23,6 +24,55 @@ pub struct Field {
|
||||||
pub values: Vec<String>,
|
pub values: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Message archive response styled as a result set.
|
||||||
|
pub struct Fin {
|
||||||
|
pub set: Set,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Set {
|
||||||
|
pub count: Option<i32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromXml for Set {
|
||||||
|
type P = impl Parser<Output = Result<Self>>;
|
||||||
|
|
||||||
|
fn parse() -> Self::P {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromXmlTag for Set {
|
||||||
|
const NAME: &'static str = "set";
|
||||||
|
const NS: &'static str = "http://jabber.org/protocol/rsm";
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromXml for Fin {
|
||||||
|
type P = impl Parser<Output = Result<Self>>;
|
||||||
|
|
||||||
|
fn parse() -> Self::P {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromXmlTag for Fin {
|
||||||
|
const NAME: &'static str = "fin";
|
||||||
|
const NS: &'static str = RESULT_SET_XMLNS;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToXml for Fin {
|
||||||
|
fn serialize(&self, events: &mut Vec<Event<'static>>) {
|
||||||
|
events.push(Event::Start(format!(r#"fin xmlns="{}" complete=True"#, Fin::NS)));
|
||||||
|
events.push(Event::Start(format!(r#"set xmlns="{}""#, Set::NS)));
|
||||||
|
if let Some(count) = &self.set.count {
|
||||||
|
events.push(Event::Start("count".into()));
|
||||||
|
events.push(Event::Text("0".into()));
|
||||||
|
events.push(Event::End("count".into()));
|
||||||
|
}
|
||||||
|
events.push(Event::End("set".into()));
|
||||||
|
events.push(Event::End("fin".into()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl FromXmlTag for X {
|
impl FromXmlTag for X {
|
||||||
const NAME: &'static str = "x";
|
const NAME: &'static str = "x";
|
||||||
const NS: &'static str = DATA_XMLNS;
|
const NS: &'static str = DATA_XMLNS;
|
||||||
|
@ -140,7 +190,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_archive_query() {
|
fn test_parse_archive_query() {
|
||||||
let input = r#"<iq to='pubsub.shakespeare.lit' type='set' id='juliet1'><query xmlns='urn:xmpp:mam:2' queryid='f28'/></iq>"#;
|
let input = r#"<iq to='pubsub.shakespeare.lit' type='set' id='juliet1'><query xmlns='urn:xmpp:mam:2' queryid='f28'/></iq>";
|
||||||
|
|
||||||
let result: Iq<MessageArchiveRequest> = parse(input).unwrap();
|
let result: Iq<MessageArchiveRequest> = parse(input).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -161,7 +211,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_query_messages_from_jid() {
|
fn test_parse_query_messages_from_jid() {
|
||||||
let input = r#"<iq type='set' id='juliet1'><query xmlns='urn:xmpp:mam:2'><x xmlns='jabber:x:data' type='submit'><field var='FORM_TYPE' type='hidden'><value>value1</value></field><field var='with'><value>juliet@capulet.lit</value></field></x></query></iq>"#;
|
let input = r#"<iq type='set' id='juliet1'><query xmlns='urn:xmpp:mam:2'><x xmlns='jabber:x:data' type='submit'><field var='FORM_TYPE' type='hidden'><value>value1</value></field><field var='with'><value>juliet@capulet.lit</value></field></x></query></iq>"#;
|
||||||
|
|
||||||
let result: Iq<MessageArchiveRequest> = parse(input).unwrap();
|
let result: Iq<MessageArchiveRequest> = parse(input).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Reference in New Issue