Skip to content

Commit 95d8ba9

Browse files
committed
doc: Add warnings about overriding the server URL
This may be dangerous when done while restoring an existing session.
1 parent ca43601 commit 95d8ba9

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

bindings/matrix-sdk-ffi/src/client_builder.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,54 @@ impl ClientBuilder {
221221
Arc::new(builder)
222222
}
223223

224+
/// Set the server name to discover the homeserver from.
225+
///
226+
/// We assume we can connect in HTTPS to that server.
227+
///
228+
/// The following methods are mutually exclusive: [`Self::homeserver_url`],
229+
/// [`Self::server_name`],
230+
/// [`Self::server_name_or_homeserver_url`].
231+
/// If you set more than one, then whatever was set last will be used.
232+
///
233+
/// **IMPORTANT:** this method should only be called for the initial
234+
/// authentication. Calls to this method when restoring a previously
235+
/// created session may end up with conflicting data.
224236
pub fn server_name(self: Arc<Self>, server_name: String) -> Arc<Self> {
225237
let mut builder = unwrap_or_clone_arc(self);
226238
builder.homeserver_cfg = Some(HomeserverConfig::ServerName(server_name));
227239
Arc::new(builder)
228240
}
229241

242+
/// Set the homeserver URL to use.
243+
///
244+
/// The following methods are mutually exclusive: [`Self::homeserver_url`],
245+
/// [`Self::server_name`],
246+
/// [`Self::server_name_or_homeserver_url`].
247+
/// If you set more than one, then whatever was set last will be used.
248+
///
249+
/// **IMPORTANT:** this method should only be called for the initial
250+
/// authentication. Calls to this method when restoring a previously
251+
/// created session may end up with conflicting data.
230252
pub fn homeserver_url(self: Arc<Self>, url: String) -> Arc<Self> {
231253
let mut builder = unwrap_or_clone_arc(self);
232254
builder.homeserver_cfg = Some(HomeserverConfig::Url(url));
233255
Arc::new(builder)
234256
}
235257

258+
/// Set the server name to discover the homeserver from, falling back to
259+
/// using it as a homeserver URL if discovery fails. When falling back to a
260+
/// homeserver URL, a check is made to ensure that the server exists (unlike
261+
/// [`Self::homeserver_url`], so you can guarantee that the client is ready
262+
/// to use.
263+
///
264+
/// The following methods are mutually exclusive: [`Self::homeserver_url`],
265+
/// [`Self::server_name`],
266+
/// [`Self::server_name_or_homeserver_url`].
267+
/// If you set more than one, then whatever was set last will be used.
268+
///
269+
/// **IMPORTANT:** this method should only be called for the initial
270+
/// authentication. Calls to this method when restoring a previously
271+
/// created session may end up with conflicting data.
236272
pub fn server_name_or_homeserver_url(self: Arc<Self>, server_name_or_url: String) -> Arc<Self> {
237273
let mut builder = unwrap_or_clone_arc(self);
238274
builder.homeserver_cfg = Some(HomeserverConfig::ServerNameOrUrl(server_name_or_url));

crates/matrix-sdk/src/client/builder/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ impl ClientBuilder {
166166
/// [`Self::server_name`] [`Self::insecure_server_name_no_tls`],
167167
/// [`Self::server_name_or_homeserver_url`].
168168
/// If you set more than one, then whatever was set last will be used.
169+
///
170+
/// **IMPORTANT:** this method should only be called for the initial
171+
/// authentication. Calls to this method when restoring a previously
172+
/// created session may end up with conflicting data.
169173
pub fn homeserver_url(mut self, url: impl AsRef<str>) -> Self {
170174
self.homeserver_cfg = Some(HomeserverConfig::HomeserverUrl(url.as_ref().to_owned()));
171175
self
@@ -180,6 +184,10 @@ impl ClientBuilder {
180184
/// [`Self::server_name`] [`Self::insecure_server_name_no_tls`],
181185
/// [`Self::server_name_or_homeserver_url`].
182186
/// If you set more than one, then whatever was set last will be used.
187+
///
188+
/// **IMPORTANT:** this method should only be called for the initial
189+
/// authentication. Calls to this method when restoring a previously
190+
/// created session may end up with conflicting data.
183191
pub fn server_name(mut self, server_name: &ServerName) -> Self {
184192
self.homeserver_cfg = Some(HomeserverConfig::ServerName {
185193
server: server_name.to_owned(),
@@ -197,6 +205,10 @@ impl ClientBuilder {
197205
/// [`Self::server_name`] [`Self::insecure_server_name_no_tls`],
198206
/// [`Self::server_name_or_homeserver_url`].
199207
/// If you set more than one, then whatever was set last will be used.
208+
///
209+
/// **IMPORTANT:** this method should only be called for the initial
210+
/// authentication. Calls to this method when restoring a previously
211+
/// created session may end up with conflicting data.
200212
pub fn insecure_server_name_no_tls(mut self, server_name: &ServerName) -> Self {
201213
self.homeserver_cfg = Some(HomeserverConfig::ServerName {
202214
server: server_name.to_owned(),
@@ -215,6 +227,10 @@ impl ClientBuilder {
215227
/// [`Self::server_name`] [`Self::insecure_server_name_no_tls`],
216228
/// [`Self::server_name_or_homeserver_url`].
217229
/// If you set more than one, then whatever was set last will be used.
230+
///
231+
/// **IMPORTANT:** this method should only be called for the initial
232+
/// authentication. Calls to this method when restoring a previously
233+
/// created session may end up with conflicting data.
218234
pub fn server_name_or_homeserver_url(mut self, server_name_or_url: impl AsRef<str>) -> Self {
219235
self.homeserver_cfg = Some(HomeserverConfig::ServerNameOrHomeserverUrl(
220236
server_name_or_url.as_ref().to_owned(),

0 commit comments

Comments
 (0)