use std::collections::HashMap;
use std::io;
use futures::stream::StreamExt;
use tokio::{
sync::mpsc::{UnboundedReceiver, UnboundedSender},
sync::oneshot,
};
use tokio_xmpp::parsers::{
iq::IqType, message::Message, minidom::Element, presence::Presence, stanza_error::StanzaError,
};
use tokio_xmpp::{connect::ServerConnector, AsyncClient as TokioXmppClient};
use crate::jid::Jid;
#[derive(Debug)]
pub enum IqRequestType {
Get(Element),
Set(Element),
}
#[derive(Debug)]
pub struct IqRequest {
pub to: Jid,
pub data: IqRequestType,
}
#[derive(Debug)]
pub enum IqResponseType {
Result(Option<Element>),
Error(StanzaError),
}
#[derive(Debug)]
pub struct IqResponse {
pub from: Option<Jid>,
pub to: Option<Jid>,
pub data: IqResponseType,
}
impl From<IqRequestType> for IqType {
fn from(other: IqRequestType) -> IqType {
match other {
IqRequestType::Get(e) => IqType::Get(e),
IqRequestType::Set(e) => IqType::Set(e),
}
}
}
impl From<IqResponseType> for IqType {
fn from(other: IqResponseType) -> IqType {
match other {
IqResponseType::Result(e) => IqType::Result(e),
IqResponseType::Error(e) => IqType::Error(e),
}
}
}
#[derive(Debug)]
pub enum Request {
SendMessage {
message: Message,
response: oneshot::Sender<io::Result<()>>,
},
SendPresence {
presence: Presence,
response: oneshot::Sender<io::Result<()>>,
},
SendIq {
to: Jid,
data: IqRequestType,
response: oneshot::Sender<io::Result<IqResponse>>,
},
Disconnect {
response: oneshot::Sender<io::Result<()>>,
},
}
#[derive(Debug)]
pub enum NonTransactional {
Presence(Presence),
Message(Message),
}
pub(crate) async fn xml_stream_worker<C: ServerConnector>(
mut client: TokioXmppClient<C>,
mut _local_rx: UnboundedReceiver<Request>,
mut _misc_tx: UnboundedSender<NonTransactional>,
) {
println!("BAR0");
let _pending_iqs: HashMap<(String, Option<String>), oneshot::Sender<io::Result<()>>> =
HashMap::new();
println!("BAR1");
println!("BAR2, {:?}", client);
println!("BAR3: {:?}", client.next().await);
loop {
while let Some(event) = client.next().await {
println!("BAR4, {:?}", event);
}
}
}