From c67d5afaf48ccb8cd1fd414c8feb5649b729dd61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Tue, 15 Feb 2022 17:42:12 +0100 Subject: [PATCH] feat(sdk): Add method to get homeserver capabilities --- crates/matrix-sdk/src/client.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/crates/matrix-sdk/src/client.rs b/crates/matrix-sdk/src/client.rs index c529dc002..07fa7891c 100644 --- a/crates/matrix-sdk/src/client.rs +++ b/crates/matrix-sdk/src/client.rs @@ -43,6 +43,7 @@ use ruma::{ client::{ r0::{ account::{register, whoami}, + capabilities::{get_capabilities, Capabilities}, device::{delete_devices, get_devices}, directory::{get_public_rooms, get_public_rooms_filtered}, filter::{create_filter::Request as FilterUploadRequest, FilterDefinition}, @@ -346,6 +347,33 @@ impl Client { .await } + /// Get the capabilities of the homeserver. + /// + /// This method should be used to check what features are supported by the + /// homeserver. + /// + /// # Example + /// ```no_run + /// # use futures::executor::block_on; + /// # use matrix_sdk::Client; + /// # use url::Url; + /// # block_on(async { + /// # let homeserver = Url::parse("http://example.com")?; + /// let client = Client::new(homeserver).await?; + /// + /// let capabilities = client.get_capabilities().await?; + /// + /// if capabilities.change_password.enabled { + /// // Change password + /// } + /// + /// # Result::<_, anyhow::Error>::Ok(()) }); + /// ``` + pub async fn get_capabilities(&self) -> HttpResult { + let res = self.send(get_capabilities::Request::new(), None).await?; + Ok(res.capabilities) + } + /// Process a [transaction] received from the homeserver /// /// # Arguments