use alloc::sync::Arc;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use tokio::sync::RwLock;
use crate::{
event_loop,
jid::{BareJid, Jid},
message, muc,
parsers::disco::DiscoInfoResult,
upload, Error, Event, RoomNick,
};
use tokio_xmpp::Client as TokioXmppClient;
pub struct Agent {
pub(crate) client: TokioXmppClient,
pub(crate) default_nick: Arc<RwLock<RoomNick>>,
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, RoomNick>,
pub(crate) rooms_joining: HashMap<BareJid, RoomNick>,
pub(crate) rooms_leaving: HashMap<BareJid, RoomNick>,
}
impl Agent {
pub async fn disconnect(self) -> Result<(), Error> {
self.client.send_end().await
}
pub async fn join_room<'a>(&mut self, settings: muc::room::JoinRoomSettings<'a>) {
muc::room::join_room(self, settings).await
}
pub async fn leave_room<'a>(&mut self, settings: muc::room::LeaveRoomSettings<'a>) {
muc::room::leave_room(self, settings).await
}
pub async fn send_raw_message<'a>(&mut self, settings: message::send::RawMessageSettings<'a>) {
message::send::send_raw_message(self, settings).await
}
pub async fn send_message<'a>(&mut self, settings: message::send::MessageSettings<'a>) {
message::send::send_message(self, settings).await
}
pub async fn send_room_message<'a>(&mut self, settings: muc::room::RoomMessageSettings<'a>) {
muc::room::send_room_message(self, settings).await
}
pub async fn send_room_private_message<'a>(
&mut self,
settings: muc::private_message::RoomPrivateMessageSettings<'a>,
) {
muc::private_message::send_room_private_message(self, settings).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()
}
}