use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use tokio::sync::RwLock;
use tokio_xmpp::connect::ServerConnector;
pub use tokio_xmpp::parsers;
use tokio_xmpp::parsers::{disco::DiscoInfoResult, message::MessageType};
pub use tokio_xmpp::{
jid::{BareJid, FullJid, Jid},
minidom::Element,
Client as TokioXmppClient,
};
use crate::{event_loop, message, muc, upload, Error, Event, RoomNick};
pub struct Agent<C: ServerConnector> {
pub(crate) client: TokioXmppClient<C>,
pub(crate) default_nick: Arc<RwLock<String>>,
pub(crate) lang: Arc<Vec<String>>,
pub(crate) disco: DiscoInfoResult,
pub(crate) node: String,
pub(crate) uploads: Vec<(String, Jid, PathBuf)>,
pub(crate) awaiting_disco_bookmarks_type: bool,
pub(crate) rooms_joined: HashMap<BareJid, String>,
pub(crate) rooms_joining: HashMap<BareJid, String>,
pub(crate) rooms_leaving: HashMap<BareJid, String>,
}
impl<C: ServerConnector> Agent<C> {
pub async fn disconnect(&mut self) -> Result<(), Error> {
self.client.send_end().await
}
pub async fn join_room(
&mut self,
room: BareJid,
nick: Option<String>,
password: Option<String>,
lang: &str,
status: &str,
) {
muc::room::join_room(self, room, nick, password, lang, status).await
}
pub async fn leave_room(
&mut self,
room_jid: BareJid,
lang: impl Into<String>,
status: impl Into<String>,
) {
muc::room::leave_room(self, room_jid, lang, status).await
}
pub async fn send_message(
&mut self,
recipient: Jid,
type_: MessageType,
lang: &str,
text: &str,
) {
message::send::send_message(self, recipient, type_, lang, text).await
}
pub async fn send_room_private_message(
&mut self,
room: BareJid,
recipient: RoomNick,
lang: &str,
text: &str,
) {
muc::private_message::send_room_private_message(self, room, recipient, lang, text).await
}
pub async fn wait_for_events(&mut self) -> Vec<Event> {
event_loop::wait_for_events(self).await
}
pub async fn upload_file_with(&mut self, service: &str, path: &Path) {
upload::send::upload_file_with(self, service, path).await
}
pub fn bound_jid(&self) -> Option<&Jid> {
self.client.bound_jid()
}
}