Skip to content

Commit

Permalink
feat(sdk): Expose Client::server_versions publicly
Browse files Browse the repository at this point in the history
Signed-off-by: Kévin Commaille <[email protected]>
  • Loading branch information
zecakeh committed Jan 12, 2025
1 parent e37ad11 commit c8d23ca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions crates/matrix-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 24 additions & 3 deletions crates/matrix-sdk/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1736,11 +1736,30 @@ impl Client {
Ok(f(&guard).unwrap())
}

pub(crate) async fn server_versions(&self) -> HttpResult<Box<[MatrixVersion]>> {
/// 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<Box<[MatrixVersion]>> {
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
///
Expand All @@ -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<BTreeMap<String, bool>> {
Expand Down

0 comments on commit c8d23ca

Please sign in to comment.