forked from lavina/lavina
feat(xmpp): rewrite handling of output xml events
This commit is contained in:
parent
fb2cbf8a8c
commit
a2a0a8914d
|
@ -25,6 +25,7 @@ use crate::prelude::*;
|
|||
use crate::protos::xmpp;
|
||||
use crate::protos::xmpp::bind::{BindResponse, Jid, Name, Resource, Server};
|
||||
use crate::protos::xmpp::client::{Iq, Presence};
|
||||
use crate::protos::xmpp::disco::InfoQuery;
|
||||
use crate::protos::xmpp::roster::RosterQuery;
|
||||
use crate::protos::xmpp::session::Session;
|
||||
use crate::protos::xmpp::stream::*;
|
||||
|
@ -278,6 +279,7 @@ async fn socket_final(
|
|||
continue;
|
||||
}
|
||||
}
|
||||
let mut events = vec![];
|
||||
match parser.consume(ns, &event) {
|
||||
Continuation::Final(res) => {
|
||||
let res = res?;
|
||||
|
@ -285,7 +287,6 @@ async fn socket_final(
|
|||
match res {
|
||||
proto::ClientPacket::Iq(iq) => match iq.body {
|
||||
proto::IqClientBody::Bind(b) => {
|
||||
let mut events = vec![];
|
||||
let req = Iq {
|
||||
from: None,
|
||||
id: iq.id,
|
||||
|
@ -298,13 +299,8 @@ async fn socket_final(
|
|||
}),
|
||||
};
|
||||
req.serialize(&mut events);
|
||||
for i in events {
|
||||
xml_writer.write_event_async(i).await?;
|
||||
}
|
||||
xml_writer.get_mut().flush().await?;
|
||||
}
|
||||
proto::IqClientBody::Session(_) => {
|
||||
let mut events = vec![];
|
||||
let req = Iq {
|
||||
from: None,
|
||||
id: iq.id,
|
||||
|
@ -313,13 +309,8 @@ async fn socket_final(
|
|||
body: Session,
|
||||
};
|
||||
req.serialize(&mut events);
|
||||
for i in events {
|
||||
xml_writer.write_event_async(i).await?;
|
||||
}
|
||||
xml_writer.get_mut().flush().await?;
|
||||
}
|
||||
proto::IqClientBody::Roster(_) => {
|
||||
let mut events = vec![];
|
||||
let req = Iq {
|
||||
from: None,
|
||||
id: iq.id,
|
||||
|
@ -328,13 +319,8 @@ async fn socket_final(
|
|||
body: RosterQuery,
|
||||
};
|
||||
req.serialize(&mut events);
|
||||
for i in events {
|
||||
xml_writer.write_event_async(i).await?;
|
||||
}
|
||||
xml_writer.get_mut().flush().await?;
|
||||
}
|
||||
_ => {
|
||||
let mut events = vec![];
|
||||
let req = Iq {
|
||||
from: None,
|
||||
id: iq.id,
|
||||
|
@ -343,27 +329,23 @@ async fn socket_final(
|
|||
body: (),
|
||||
};
|
||||
req.serialize(&mut events);
|
||||
for i in events {
|
||||
xml_writer.write_event_async(i).await?;
|
||||
}
|
||||
xml_writer.get_mut().flush().await?;
|
||||
},
|
||||
}
|
||||
},
|
||||
proto::ClientPacket::Message(_) => todo!(),
|
||||
proto::ClientPacket::Presence(p) => {
|
||||
let mut events = vec![];
|
||||
let response = Presence::<()> {
|
||||
to: Some("darova@localhost/kek".to_string()),
|
||||
from: Some("darova@localhost/kek".to_string()),
|
||||
..Default::default()
|
||||
};
|
||||
response.serialize(&mut events);
|
||||
for i in events {
|
||||
xml_writer.write_event_async(i).await?;
|
||||
}
|
||||
xml_writer.get_mut().flush().await?;
|
||||
}
|
||||
}
|
||||
for i in &events {
|
||||
xml_writer.write_event_async(i).await?;
|
||||
}
|
||||
events.clear();
|
||||
xml_writer.get_mut().flush().await?;
|
||||
parser = proto::ClientPacket::parse();
|
||||
}
|
||||
Continuation::Continue(p) => parser = p,
|
||||
|
|
Loading…
Reference in New Issue