mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-04 14:04:40 -04:00
ffi: Only ever call ClientDelegate methods in a blocking task
… and clean up a few unnecessary Arc's.
This commit is contained in:
committed by
Jonas Platte
parent
5630851062
commit
06a19f016e
@@ -134,16 +134,16 @@ impl From<matrix_sdk::TransmissionProgress> for TransmissionProgress {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, uniffi::Object)]
|
||||
#[derive(uniffi::Object)]
|
||||
pub struct Client {
|
||||
pub(crate) inner: MatrixClient,
|
||||
delegate: Arc<RwLock<Option<Box<dyn ClientDelegate>>>>,
|
||||
delegate: RwLock<Option<Arc<dyn ClientDelegate>>>,
|
||||
session_verification_controller:
|
||||
Arc<tokio::sync::RwLock<Option<SessionVerificationController>>>,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
pub fn new(sdk_client: MatrixClient) -> Self {
|
||||
pub fn new(sdk_client: MatrixClient) -> Arc<Self> {
|
||||
let session_verification_controller: Arc<
|
||||
tokio::sync::RwLock<Option<SessionVerificationController>>,
|
||||
> = Default::default();
|
||||
@@ -160,11 +160,11 @@ impl Client {
|
||||
}
|
||||
});
|
||||
|
||||
let client = Client {
|
||||
let client = Arc::new(Client {
|
||||
inner: sdk_client,
|
||||
delegate: Arc::new(RwLock::new(None)),
|
||||
delegate: RwLock::new(None),
|
||||
session_verification_controller,
|
||||
};
|
||||
});
|
||||
|
||||
let mut session_change_receiver = client.inner.subscribe_to_session_changes();
|
||||
let client_clone = client.clone();
|
||||
@@ -356,7 +356,7 @@ impl Client {
|
||||
#[uniffi::export]
|
||||
impl Client {
|
||||
pub fn set_delegate(&self, delegate: Option<Box<dyn ClientDelegate>>) {
|
||||
*self.delegate.write().unwrap() = delegate;
|
||||
*self.delegate.write().unwrap() = delegate.map(Arc::from);
|
||||
}
|
||||
|
||||
pub fn session(&self) -> Result<Session, ClientError> {
|
||||
@@ -763,15 +763,15 @@ impl From<&search_users::v3::User> for UserProfile {
|
||||
|
||||
impl Client {
|
||||
fn process_session_change(&self, session_change: SessionChange) {
|
||||
if let Some(delegate) = &*self.delegate.read().unwrap() {
|
||||
match session_change {
|
||||
if let Some(delegate) = self.delegate.read().unwrap().clone() {
|
||||
RUNTIME.spawn_blocking(move || match session_change {
|
||||
SessionChange::UnknownToken { soft_logout } => {
|
||||
delegate.did_receive_auth_error(soft_logout);
|
||||
}
|
||||
SessionChange::TokensRefreshed => {
|
||||
delegate.did_refresh_tokens();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,9 +200,7 @@ impl ClientBuilder {
|
||||
sdk_client.set_sliding_sync_proxy(Some(Url::parse(&sliding_sync_proxy)?));
|
||||
}
|
||||
|
||||
let client = Client::new(sdk_client);
|
||||
|
||||
Ok(Arc::new(client))
|
||||
Ok(Client::new(sdk_client))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user