Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk): Expose Client::server_versions publicly #4519

Merged
merged 2 commits into from
Jan 13, 2025
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
3 changes: 3 additions & 0 deletions crates/matrix-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ 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.
([#4519](https://github.com/matrix-org/matrix-rust-sdk/pull/4519))

### 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
Loading