xmpp: new Agent::new method

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2025-03-27 00:43:13 +01:00 committed by pep
commit 4780f89604
3 changed files with 23 additions and 15 deletions

View file

@ -21,6 +21,7 @@ XXXX-YY-ZZ [ RELEASER <admin@localhost> ]
- Event::ChatMessageCorrection, Event::RoomMessageCorrection, and
Event::RoomPrivateMessageCorrection signal XEP-0308 message corrections; they're
not checked how old the corrected entry is, which has security concerns (!496)
- Agent::new helper method.
* Fixes:
- Use tokio::sync::RwLock not std::sync::RwLock (!432)
- Agent::wait_for_events now return Vec<Event> and sets inner tokio_xmpp Client

View file

@ -33,6 +33,27 @@ pub struct Agent {
}
impl Agent {
pub fn new(
client: TokioXmppClient,
default_nick: RoomNick,
lang: Vec<String>,
disco: DiscoInfoResult,
node: String,
) -> Agent {
Agent {
client,
default_nick: Arc::new(RwLock::new(default_nick)),
lang: Arc::new(lang),
disco,
node,
uploads: Vec::new(),
awaiting_disco_bookmarks_type: false,
rooms_joined: HashMap::new(),
rooms_joining: HashMap::new(),
rooms_leaving: HashMap::new(),
}
}
pub async fn disconnect(self) -> Result<(), Error> {
self.client.send_end().await
}

View file

@ -6,10 +6,7 @@
#[cfg(any(feature = "starttls-rust", feature = "starttls-native"))]
use crate::tokio_xmpp::connect::{DnsConfig, StartTlsServerConnector};
use alloc::sync::Arc;
use core::str::FromStr;
use std::collections::HashMap;
use tokio::sync::RwLock;
use crate::{
jid::{BareJid, Jid, ResourceRef},
@ -172,17 +169,6 @@ impl<C: ServerConnector> ClientBuilder<'_, C> {
let disco = self.make_disco();
let node = self.website;
Agent {
client,
default_nick: Arc::new(RwLock::new(self.default_nick)),
lang: Arc::new(self.lang),
disco,
node,
uploads: Vec::new(),
awaiting_disco_bookmarks_type: false,
rooms_joined: HashMap::new(),
rooms_joining: HashMap::new(),
rooms_leaving: HashMap::new(),
}
Agent::new(client, self.default_nick, self.lang, disco, node)
}
}