xmpp: new Agent::new method

Maxime “pep” Buquet created

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>

Change summary

xmpp/ChangeLog      |  1 +
xmpp/src/agent.rs   | 21 +++++++++++++++++++++
xmpp/src/builder.rs | 16 +---------------
3 files changed, 23 insertions(+), 15 deletions(-)

Detailed changes

xmpp/ChangeLog 🔗

@@ -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

xmpp/src/agent.rs 🔗

@@ -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
     }

xmpp/src/builder.rs 🔗

@@ -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)
     }
 }