diff --git a/bindings/matrix-sdk-ffi/src/authentication_service.rs b/bindings/matrix-sdk-ffi/src/authentication_service.rs index b8d39bc63..79650704d 100644 --- a/bindings/matrix-sdk-ffi/src/authentication_service.rs +++ b/bindings/matrix-sdk-ffi/src/authentication_service.rs @@ -17,7 +17,6 @@ pub struct AuthenticationService { passphrase: Option, client: RwLock>>, homeserver_details: RwLock>>, - custom_sliding_sync_proxy: RwLock>, } impl Drop for AuthenticationService { @@ -83,17 +82,12 @@ impl HomeserverLoginDetails { impl AuthenticationService { /// Creates a new service to authenticate a user with. #[uniffi::constructor] - pub fn new( - base_path: String, - passphrase: Option, - custom_sliding_sync_proxy: Option, - ) -> Arc { + pub fn new(base_path: String, passphrase: Option) -> Arc { Arc::new(AuthenticationService { base_path, passphrase, client: RwLock::new(None), homeserver_details: RwLock::new(None), - custom_sliding_sync_proxy: RwLock::new(custom_sliding_sync_proxy), }) } @@ -142,9 +136,7 @@ impl AuthenticationService { // Now we've verified that it's a valid homeserver, make sure // there's a sliding sync proxy available one way or another. - if self.custom_sliding_sync_proxy.read().unwrap().is_none() - && client.discovered_sliding_sync_proxy().is_none() - { + if client.discovered_sliding_sync_proxy().is_none() { return Err(AuthenticationError::SlidingSyncNotAvailable); } @@ -177,20 +169,10 @@ impl AuthenticationService { let homeserver_url = client.homeserver(); let session = client.inner.session().ok_or(AuthenticationError::SessionMissing)?; - let sliding_sync_proxy: Option; - if let Some(custom_proxy) = self.custom_sliding_sync_proxy.read().unwrap().clone() { - sliding_sync_proxy = Some(custom_proxy); - } else if let Some(discovered_proxy) = client.discovered_sliding_sync_proxy() { - sliding_sync_proxy = Some(discovered_proxy); - } else { - sliding_sync_proxy = None; - } - let client = ClientBuilder::new() .base_path(self.base_path.clone()) .passphrase(self.passphrase.clone()) .homeserver_url(homeserver_url) - .sliding_sync_proxy(sliding_sync_proxy) .username(whoami.user_id.to_string()) .build_inner()?; diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index 96964c131..0e0880ffe 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -112,10 +112,6 @@ pub struct Client { notification_delegate: Arc>>>, session_verification_controller: Arc>>, - /// The sliding sync proxy that the client is configured to use by default. - /// If this value is `Some`, it will be automatically added to the builder - /// when calling `sliding_sync()`. - pub(crate) sliding_sync_proxy: Arc>>, pub(crate) sliding_sync_reset_broadcast_tx: Arc>, } @@ -142,7 +138,6 @@ impl Client { delegate: Arc::new(RwLock::new(None)), notification_delegate: Arc::new(RwLock::new(None)), session_verification_controller, - sliding_sync_proxy: Arc::new(RwLock::new(None)), sliding_sync_reset_broadcast_tx: Default::default(), }; @@ -217,16 +212,8 @@ impl Client { /// Restores the client from a `Session`. pub fn restore_session(&self, session: Session) -> Result<(), ClientError> { - let Session { - access_token, - refresh_token, - user_id, - device_id, - homeserver_url: _, - sliding_sync_proxy, - } = session; - - *self.sliding_sync_proxy.write().unwrap() = sliding_sync_proxy; + let Session { access_token, refresh_token, user_id, device_id, homeserver_url: _ } = + session; let session = matrix_sdk::Session { access_token, @@ -265,10 +252,6 @@ impl Client { }) } - pub(crate) fn set_sliding_sync_proxy(&self, sliding_sync_proxy: Option) { - *self.sliding_sync_proxy.write().unwrap() = sliding_sync_proxy; - } - /// Whether or not the client's homeserver supports the password login flow. pub(crate) async fn supports_password_login(&self) -> anyhow::Result { let login_types = self.inner.get_login_types().await?; @@ -297,7 +280,6 @@ impl Client { let matrix_sdk::Session { access_token, refresh_token, user_id, device_id } = self.inner.session().context("Missing session")?; let homeserver_url = self.inner.homeserver().await.into(); - let sliding_sync_proxy = self.sliding_sync_proxy.read().unwrap().clone(); Ok(Session { access_token, @@ -305,7 +287,6 @@ impl Client { user_id: user_id.to_string(), device_id: device_id.to_string(), homeserver_url, - sliding_sync_proxy, }) }) } @@ -763,7 +744,6 @@ pub struct Session { // FFI-only fields (for now) pub homeserver_url: String, - pub sliding_sync_proxy: Option, } #[uniffi::export] diff --git a/bindings/matrix-sdk-ffi/src/client_builder.rs b/bindings/matrix-sdk-ffi/src/client_builder.rs index 0b2077c7d..bcaccba9f 100644 --- a/bindings/matrix-sdk-ffi/src/client_builder.rs +++ b/bindings/matrix-sdk-ffi/src/client_builder.rs @@ -23,7 +23,6 @@ pub struct ClientBuilder { server_versions: Option>, passphrase: Zeroizing>, user_agent: Option, - sliding_sync_proxy: Option, inner: MatrixClientBuilder, } @@ -76,12 +75,6 @@ impl ClientBuilder { Arc::new(builder) } - pub fn sliding_sync_proxy(self: Arc, sliding_sync_proxy: Option) -> Arc { - let mut builder = unwrap_or_clone_arc(self); - builder.sliding_sync_proxy = sliding_sync_proxy; - Arc::new(builder) - } - pub fn build(self: Arc) -> Result, ClientError> { Ok(self.build_inner()?) } @@ -128,12 +121,7 @@ impl ClientBuilder { ); } - RUNTIME.block_on(async move { - let client = inner_builder.build().await?; - let c = Client::new(client); - c.set_sliding_sync_proxy(builder.sliding_sync_proxy); - Ok(Arc::new(c)) - }) + RUNTIME.block_on(async move { Ok(Arc::new(Client::new(inner_builder.build().await?))) }) } } @@ -147,7 +135,6 @@ impl Default for ClientBuilder { server_versions: None, passphrase: Zeroizing::new(None), user_agent: None, - sliding_sync_proxy: None, inner: MatrixClient::builder(), } } diff --git a/bindings/matrix-sdk-ffi/src/sliding_sync.rs b/bindings/matrix-sdk-ffi/src/sliding_sync.rs index 9a6e518ab..26a84399d 100644 --- a/bindings/matrix-sdk-ffi/src/sliding_sync.rs +++ b/bindings/matrix-sdk-ffi/src/sliding_sync.rs @@ -20,7 +20,6 @@ use matrix_sdk::{ }; use matrix_sdk_ui::timeline::SlidingSyncRoomExt; use tracing::{error, warn}; -use url::Url; use crate::{ error::ClientError, helpers::unwrap_or_clone_arc, room::TimelineLock, Client, @@ -867,15 +866,13 @@ impl Client { /// Note: the identifier must be less than 16 chars long. pub fn sliding_sync(&self, id: String) -> Result, ClientError> { let mut inner = self.inner.sliding_sync(id)?; - if let Some(sliding_sync_proxy) = self - .sliding_sync_proxy - .read() - .unwrap() - .clone() - .and_then(|p| Url::parse(p.as_str()).ok()) + + if let Some(sliding_sync_proxy) = + RUNTIME.block_on(async { self.inner.sliding_sync_proxy().await }) { inner = inner.sliding_sync_proxy(sliding_sync_proxy); } + Ok(Arc::new(SlidingSyncBuilder { inner, client: self.clone() })) } }