feat(xmpp): rewrite handling of output xml events

This commit is contained in:
Nikita Vilunov 2023-03-29 00:36:12 +02:00
parent fb2cbf8a8c
commit a2a0a8914d
1 changed files with 8 additions and 26 deletions

View File

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