Agent is now Send (closes #64)

This commit is contained in:
xmppftw 2023-06-01 11:44:49 +02:00
parent 1870a83424
commit aafe341b25
2 changed files with 11 additions and 7 deletions

View file

@ -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: Version 0.4.0:
2023-05-18 [ Maxime “pep” Buquet <pep@bouah.net>, Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> ] 2023-05-18 [ Maxime “pep” Buquet <pep@bouah.net>, Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> ]
* Breaking changes: * Breaking changes:

View file

@ -10,10 +10,9 @@ use futures::stream::StreamExt;
use reqwest::{ use reqwest::{
header::HeaderMap as ReqwestHeaderMap, Body as ReqwestBody, Client as ReqwestClient, header::HeaderMap as ReqwestHeaderMap, Body as ReqwestBody, Client as ReqwestClient,
}; };
use std::cell::RefCell;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::rc::Rc; use std::sync::{Arc, RwLock};
use tokio::fs::File; use tokio::fs::File;
use tokio_util::codec::{BytesCodec, FramedRead}; use tokio_util::codec::{BytesCodec, FramedRead};
use tokio_xmpp::{AsyncClient as TokioXmppClient, Event as TokioXmppEvent}; use tokio_xmpp::{AsyncClient as TokioXmppClient, Event as TokioXmppEvent};
@ -181,8 +180,8 @@ impl ClientBuilder<'_> {
let agent = Agent { let agent = Agent {
client, client,
default_nick: Rc::new(RefCell::new(self.default_nick)), default_nick: Arc::new(RwLock::new(self.default_nick)),
lang: Rc::new(self.lang), lang: Arc::new(self.lang),
disco, disco,
node, node,
uploads: Vec::new(), uploads: Vec::new(),
@ -194,8 +193,8 @@ impl ClientBuilder<'_> {
pub struct Agent { pub struct Agent {
client: TokioXmppClient, client: TokioXmppClient,
default_nick: Rc<RefCell<String>>, default_nick: Arc<RwLock<String>>,
lang: Rc<Vec<String>>, lang: Arc<Vec<String>>,
disco: DiscoInfoResult, disco: DiscoInfoResult,
node: String, node: String,
uploads: Vec<(String, Jid, PathBuf)>, uploads: Vec<(String, Jid, PathBuf)>,
@ -219,7 +218,7 @@ impl Agent {
muc = muc.with_password(password); 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 room_jid = room.with_resource(nick);
let mut presence = Presence::new(PresenceType::None).with_to(Jid::Full(room_jid)); let mut presence = Presence::new(PresenceType::None).with_to(Jid::Full(room_jid));
presence.add_payload(muc); presence.add_payload(muc);