From 235efaa85c7964161b70763392c3387fd3bf8bde Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 13 Jun 2023 00:12:41 +0200 Subject: [PATCH] fix(ffi): Do not overwrite `Client`'s `sliding_sync_proxy` everytime. The comment explains the fix correctly. --- bindings/matrix-sdk-ffi/src/client_builder.rs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/client_builder.rs b/bindings/matrix-sdk-ffi/src/client_builder.rs index e3682cc2a..3eb1005d7 100644 --- a/bindings/matrix-sdk-ffi/src/client_builder.rs +++ b/bindings/matrix-sdk-ffi/src/client_builder.rs @@ -130,9 +130,23 @@ impl ClientBuilder { } let sdk_client = RUNTIME.block_on(async move { inner_builder.build().await })?; - sdk_client.set_sliding_sync_proxy( - builder.sliding_sync_proxy.map(|url| Url::parse(&url)).transpose()?, - ); + + // At this point, `sdk_client` might contain a `sliding_sync_proxy` that has + // been configured by the homeserver (if it's a `ServerName` and the + // `.well-known` file is filled as expected). + // + // If `builder.sliding_sync_proxy` contains `Some(_)`, it means one wants to + // overwrite this value. It would be an error to call + // `sdk_client.set_sliding_sync_proxy()` with `None`, as it would erase the + // `sliding_sync_proxy` if any, and it's not the intented behavior. + // + // So let's call `sdk_client.set_sliding_sync_proxy()` if and only if there is + // `Some(_)` value in `builder.sliding_sync_proxy`. That's really important: It + // might not break an existing app session, but it is likely to break a new + // session, which not immediate to detect if there is no test. + if let Some(sliding_sync_proxy) = builder.sliding_sync_proxy { + sdk_client.set_sliding_sync_proxy(Some(Url::parse(&sliding_sync_proxy)?)); + } let client = Client::new(sdk_client);