From c8d23ca96ec431890c979f97dc94e1d6feb66946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Sun, 12 Jan 2025 20:32:58 +0100 Subject: [PATCH 1/2] feat(sdk): Expose Client::server_versions publicly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kévin Commaille --- crates/matrix-sdk/CHANGELOG.md | 2 ++ crates/matrix-sdk/src/client/mod.rs | 27 ++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/crates/matrix-sdk/CHANGELOG.md b/crates/matrix-sdk/CHANGELOG.md index c8f627b8b52..8ad98b41958 100644 --- a/crates/matrix-sdk/CHANGELOG.md +++ b/crates/matrix-sdk/CHANGELOG.md @@ -12,6 +12,8 @@ All notable changes to this project will be documented in this file. ([#4503](https://github.com/matrix-org/matrix-rust-sdk/pull/4503)) - Implement `Default` for `BaseImageInfo`, `BaseVideoInfo`, `BaseAudioInfo` and `BaseFileInfo`. ([#4503](https://github.com/matrix-org/matrix-rust-sdk/pull/4503)) +- Expose `Client::server_versions()` publicly to allow users of the library to + get the versions of Matrix supported by the homeserver. ### Refactor diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 033bb2ac69f..5c9396105e3 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -1736,11 +1736,30 @@ impl Client { Ok(f(&guard).unwrap()) } - pub(crate) async fn server_versions(&self) -> HttpResult> { + /// Get the Matrix versions supported by the homeserver by fetching them + /// from the server or the cache. + /// + /// # Examples + /// + /// ```no_run + /// use ruma::api::MatrixVersion; + /// # use matrix_sdk::{Client, config::SyncSettings}; + /// # use url::Url; + /// # async { + /// # let homeserver = Url::parse("http://localhost:8080")?; + /// # let mut client = Client::new(homeserver).await?; + /// + /// let server_versions = client.server_versions().await?; + /// let supports_1_1 = server_versions.contains(&MatrixVersion::V1_1); + /// println!("The homeserver supports Matrix 1.1: {supports_1_1:?}"); + /// # anyhow::Ok(()) }; + /// ``` + pub async fn server_versions(&self) -> HttpResult> { self.get_or_load_and_cache_server_capabilities(|caps| caps.server_versions.clone()).await } - /// Get unstable features from by fetching from the server or the cache. + /// Get the unstable features supported by the homeserver by fetching them + /// from the server or the cache. /// /// # Examples /// @@ -1751,7 +1770,9 @@ impl Client { /// # let homeserver = Url::parse("http://localhost:8080")?; /// # let mut client = Client::new(homeserver).await?; /// let unstable_features = client.unstable_features().await?; - /// let msc_x = unstable_features.get("msc_x").unwrap_or(&false); + /// let supports_msc_x = + /// unstable_features.get("msc_x").copied().unwrap_or(false); + /// println!("The homeserver supports msc X: {supports_msc_x:?}"); /// # anyhow::Ok(()) }; /// ``` pub async fn unstable_features(&self) -> HttpResult> { From 83f53a8f5db6f3ce91a89084c351acf00951f18c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Sun, 12 Jan 2025 20:43:14 +0100 Subject: [PATCH 2/2] Add PR link to changelog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kévin Commaille --- crates/matrix-sdk/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/matrix-sdk/CHANGELOG.md b/crates/matrix-sdk/CHANGELOG.md index 8ad98b41958..6673f1e2a9b 100644 --- a/crates/matrix-sdk/CHANGELOG.md +++ b/crates/matrix-sdk/CHANGELOG.md @@ -13,7 +13,8 @@ All notable changes to this project will be documented in this file. - Implement `Default` for `BaseImageInfo`, `BaseVideoInfo`, `BaseAudioInfo` and `BaseFileInfo`. ([#4503](https://github.com/matrix-org/matrix-rust-sdk/pull/4503)) - Expose `Client::server_versions()` publicly to allow users of the library to - get the versions of Matrix supported by the homeserver. + get the versions of Matrix supported by the homeserver. + ([#4519](https://github.com/matrix-org/matrix-rust-sdk/pull/4519)) ### Refactor