diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index e67ee6b79b3..78a69c5bc17 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -2100,10 +2100,9 @@ impl Client { fn session_inner(client: matrix_sdk::Client) -> Result { let auth_api = client.auth_api().context("Missing authentication API")?; - let homeserver_url = client.homeserver().into(); let sliding_sync_version = client.sliding_sync_version(); - Session::new(auth_api, homeserver_url, sliding_sync_version.into()) + Session::new(auth_api, sliding_sync_version.into()) } fn save_session( @@ -2395,8 +2394,6 @@ pub struct Session { pub device_id: String, // FFI-only fields (for now) - /// The URL for the homeserver used for this session. - pub homeserver_url: String, /// Additional data for this session if OpenID Connect was used for /// authentication. pub oidc_data: Option, @@ -2407,7 +2404,6 @@ pub struct Session { impl Session { fn new( auth_api: AuthApi, - homeserver_url: String, sliding_sync_version: SlidingSyncVersion, ) -> Result { match auth_api { @@ -2423,7 +2419,6 @@ impl Session { refresh_token, user_id: user_id.to_string(), device_id: device_id.to_string(), - homeserver_url, oidc_data: None, sliding_sync_version, }) @@ -2443,7 +2438,6 @@ impl Session { refresh_token, user_id: user_id.to_string(), device_id: device_id.to_string(), - homeserver_url, oidc_data, sliding_sync_version, }) @@ -2465,7 +2459,6 @@ impl TryFrom for AuthSession { refresh_token, user_id, device_id, - homeserver_url: _, oidc_data, sliding_sync_version: _, } = value; diff --git a/bindings/matrix-sdk-ffi/src/client_builder.rs b/bindings/matrix-sdk-ffi/src/client_builder.rs index 8249c8775a6..2bdcfac7b2a 100644 --- a/bindings/matrix-sdk-ffi/src/client_builder.rs +++ b/bindings/matrix-sdk-ffi/src/client_builder.rs @@ -221,18 +221,54 @@ impl ClientBuilder { Arc::new(builder) } + /// Set the server name to discover the homeserver from. + /// + /// We assume we can connect in HTTPS to that server. + /// + /// The following methods are mutually exclusive: [`Self::homeserver_url`], + /// [`Self::server_name`], + /// [`Self::server_name_or_homeserver_url`]. + /// If you set more than one, then whatever was set last will be used. + /// + /// **IMPORTANT:** this method should only be called for the initial + /// authentication. Calls to this method when restoring a previously + /// created session may end up with conflicting data. pub fn server_name(self: Arc, server_name: String) -> Arc { let mut builder = unwrap_or_clone_arc(self); builder.homeserver_cfg = Some(HomeserverConfig::ServerName(server_name)); Arc::new(builder) } + /// Set the homeserver URL to use. + /// + /// The following methods are mutually exclusive: [`Self::homeserver_url`], + /// [`Self::server_name`], + /// [`Self::server_name_or_homeserver_url`]. + /// If you set more than one, then whatever was set last will be used. + /// + /// **IMPORTANT:** this method should only be called for the initial + /// authentication. Calls to this method when restoring a previously + /// created session may end up with conflicting data. pub fn homeserver_url(self: Arc, url: String) -> Arc { let mut builder = unwrap_or_clone_arc(self); builder.homeserver_cfg = Some(HomeserverConfig::Url(url)); Arc::new(builder) } + /// Set the server name to discover the homeserver from, falling back to + /// using it as a homeserver URL if discovery fails. When falling back to a + /// homeserver URL, a check is made to ensure that the server exists (unlike + /// [`Self::homeserver_url`], so you can guarantee that the client is ready + /// to use. + /// + /// The following methods are mutually exclusive: [`Self::homeserver_url`], + /// [`Self::server_name`], + /// [`Self::server_name_or_homeserver_url`]. + /// If you set more than one, then whatever was set last will be used. + /// + /// **IMPORTANT:** this method should only be called for the initial + /// authentication. Calls to this method when restoring a previously + /// created session may end up with conflicting data. pub fn server_name_or_homeserver_url(self: Arc, server_name_or_url: String) -> Arc { let mut builder = unwrap_or_clone_arc(self); builder.homeserver_cfg = Some(HomeserverConfig::ServerNameOrUrl(server_name_or_url)); diff --git a/crates/matrix-sdk/src/client/builder/mod.rs b/crates/matrix-sdk/src/client/builder/mod.rs index 9933af32678..65eba7b2cbd 100644 --- a/crates/matrix-sdk/src/client/builder/mod.rs +++ b/crates/matrix-sdk/src/client/builder/mod.rs @@ -166,6 +166,10 @@ impl ClientBuilder { /// [`Self::server_name`] [`Self::insecure_server_name_no_tls`], /// [`Self::server_name_or_homeserver_url`]. /// If you set more than one, then whatever was set last will be used. + /// + /// **IMPORTANT:** this method should only be called for the initial + /// authentication. Calls to this method when restoring a previously + /// created session may end up with conflicting data. pub fn homeserver_url(mut self, url: impl AsRef) -> Self { self.homeserver_cfg = Some(HomeserverConfig::HomeserverUrl(url.as_ref().to_owned())); self @@ -180,6 +184,10 @@ impl ClientBuilder { /// [`Self::server_name`] [`Self::insecure_server_name_no_tls`], /// [`Self::server_name_or_homeserver_url`]. /// If you set more than one, then whatever was set last will be used. + /// + /// **IMPORTANT:** this method should only be called for the initial + /// authentication. Calls to this method when restoring a previously + /// created session may end up with conflicting data. pub fn server_name(mut self, server_name: &ServerName) -> Self { self.homeserver_cfg = Some(HomeserverConfig::ServerName { server: server_name.to_owned(), @@ -197,6 +205,10 @@ impl ClientBuilder { /// [`Self::server_name`] [`Self::insecure_server_name_no_tls`], /// [`Self::server_name_or_homeserver_url`]. /// If you set more than one, then whatever was set last will be used. + /// + /// **IMPORTANT:** this method should only be called for the initial + /// authentication. Calls to this method when restoring a previously + /// created session may end up with conflicting data. pub fn insecure_server_name_no_tls(mut self, server_name: &ServerName) -> Self { self.homeserver_cfg = Some(HomeserverConfig::ServerName { server: server_name.to_owned(), @@ -215,6 +227,10 @@ impl ClientBuilder { /// [`Self::server_name`] [`Self::insecure_server_name_no_tls`], /// [`Self::server_name_or_homeserver_url`]. /// If you set more than one, then whatever was set last will be used. + /// + /// **IMPORTANT:** this method should only be called for the initial + /// authentication. Calls to this method when restoring a previously + /// created session may end up with conflicting data. pub fn server_name_or_homeserver_url(mut self, server_name_or_url: impl AsRef) -> Self { self.homeserver_cfg = Some(HomeserverConfig::ServerNameOrHomeserverUrl( server_name_or_url.as_ref().to_owned(),