From aafe341b258fb7817630e40b6caf9333d1954d66 Mon Sep 17 00:00:00 2001 From: xmppftw Date: Thu, 1 Jun 2023 11:44:49 +0200 Subject: [PATCH] Agent is now Send (closes #64) --- xmpp/ChangeLog | 5 +++++ xmpp/src/lib.rs | 13 ++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/xmpp/ChangeLog b/xmpp/ChangeLog index 4bf7ba98..9071140d 100644 --- a/xmpp/ChangeLog +++ b/xmpp/ChangeLog @@ -1,3 +1,8 @@ +Unreleased: +xxxxxxxxxx + * Improvements: + - Agent is now Send, by replacing Rc with Arc and RefCell with RwLock (#64) + Version 0.4.0: 2023-05-18 [ Maxime “pep” Buquet , Emmanuel Gil Peyrot ] * Breaking changes: diff --git a/xmpp/src/lib.rs b/xmpp/src/lib.rs index 21b5f0bc..ae2a7dce 100644 --- a/xmpp/src/lib.rs +++ b/xmpp/src/lib.rs @@ -10,10 +10,9 @@ use futures::stream::StreamExt; use reqwest::{ header::HeaderMap as ReqwestHeaderMap, Body as ReqwestBody, Client as ReqwestClient, }; -use std::cell::RefCell; use std::convert::TryFrom; use std::path::{Path, PathBuf}; -use std::rc::Rc; +use std::sync::{Arc, RwLock}; use tokio::fs::File; use tokio_util::codec::{BytesCodec, FramedRead}; use tokio_xmpp::{AsyncClient as TokioXmppClient, Event as TokioXmppEvent}; @@ -181,8 +180,8 @@ impl ClientBuilder<'_> { let agent = Agent { client, - default_nick: Rc::new(RefCell::new(self.default_nick)), - lang: Rc::new(self.lang), + default_nick: Arc::new(RwLock::new(self.default_nick)), + lang: Arc::new(self.lang), disco, node, uploads: Vec::new(), @@ -194,8 +193,8 @@ impl ClientBuilder<'_> { pub struct Agent { client: TokioXmppClient, - default_nick: Rc>, - lang: Rc>, + default_nick: Arc>, + lang: Arc>, disco: DiscoInfoResult, node: String, uploads: Vec<(String, Jid, PathBuf)>, @@ -219,7 +218,7 @@ impl Agent { muc = muc.with_password(password); } - let nick = nick.unwrap_or_else(|| self.default_nick.borrow().clone()); + let nick = nick.unwrap_or_else(|| self.default_nick.read().unwrap().clone()); let room_jid = room.with_resource(nick); let mut presence = Presence::new(PresenceType::None).with_to(Jid::Full(room_jid)); presence.add_payload(muc);