Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions bindings/matrix-sdk-ffi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2100,10 +2100,9 @@ impl Client {
fn session_inner(client: matrix_sdk::Client) -> Result<Session, ClientError> {
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(
Expand Down Expand Up @@ -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<String>,
Expand All @@ -2407,7 +2404,6 @@ pub struct Session {
impl Session {
fn new(
auth_api: AuthApi,
homeserver_url: String,
sliding_sync_version: SlidingSyncVersion,
) -> Result<Session, ClientError> {
match auth_api {
Expand All @@ -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,
})
Expand All @@ -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,
})
Expand All @@ -2465,7 +2459,6 @@ impl TryFrom<Session> for AuthSession {
refresh_token,
user_id,
device_id,
homeserver_url: _,
oidc_data,
sliding_sync_version: _,
} = value;
Expand Down
36 changes: 36 additions & 0 deletions bindings/matrix-sdk-ffi/src/client_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self>, server_name: String) -> Arc<Self> {
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<Self>, url: String) -> Arc<Self> {
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<Self>, server_name_or_url: String) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.homeserver_cfg = Some(HomeserverConfig::ServerNameOrUrl(server_name_or_url));
Expand Down
16 changes: 16 additions & 0 deletions crates/matrix-sdk/src/client/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<str>) -> Self {
self.homeserver_cfg = Some(HomeserverConfig::HomeserverUrl(url.as_ref().to_owned()));
self
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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<str>) -> Self {
self.homeserver_cfg = Some(HomeserverConfig::ServerNameOrHomeserverUrl(
server_name_or_url.as_ref().to_owned(),
Expand Down
Loading