From 31c0d8ff668cc9b96e39873da8dc41ce83badc07 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 12 Aug 2025 09:15:08 +0000 Subject: [PATCH 01/10] Initial plan From 2929ffa669c8524cffbc1168afecdf60e77ec06f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 12 Aug 2025 09:45:28 +0000 Subject: [PATCH 02/10] Implement server_version method for matrix-sdk Client Co-authored-by: pixlwave <6060466+pixlwave@users.noreply.github.com> --- Cargo.lock | 18 ++++++++++++ crates/matrix-sdk/Cargo.toml | 1 + crates/matrix-sdk/src/client/mod.rs | 44 +++++++++++++++++++++++++++++ crates/matrix-sdk/src/lib.rs | 3 +- 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 96e302c8b95..f1f1890c494 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4651,6 +4651,7 @@ dependencies = [ "ruma-events", "ruma-federation-api", "ruma-html", + "ruma-signatures", "web-time", ] @@ -4744,7 +4745,9 @@ dependencies = [ "headers", "http", "http-auth", + "httparse", "js_int", + "memchr", "mime", "ruma-common", "ruma-events", @@ -4789,6 +4792,21 @@ dependencies = [ "toml 0.8.15", ] +[[package]] +name = "ruma-signatures" +version = "0.17.1" +source = "git+https://github.com/ruma/ruma?rev=e73f302e4df7f5f0511fca1aa43853d4cf8416c8#e73f302e4df7f5f0511fca1aa43853d4cf8416c8" +dependencies = [ + "base64", + "ed25519-dalek", + "pkcs8", + "rand", + "ruma-common", + "serde_json", + "sha2", + "thiserror 2.0.11", +] + [[package]] name = "rusqlite" version = "0.35.0" diff --git a/crates/matrix-sdk/Cargo.toml b/crates/matrix-sdk/Cargo.toml index b1077fac54a..e991ff41f18 100644 --- a/crates/matrix-sdk/Cargo.toml +++ b/crates/matrix-sdk/Cargo.toml @@ -101,6 +101,7 @@ pin-project-lite.workspace = true rand = { workspace = true, optional = true } ruma = { workspace = true, features = [ "rand", + "federation-api-c", "unstable-msc2448", "unstable-msc4191", "unstable-msc3930", diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 73d41274dd4..5c69b452610 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -62,6 +62,7 @@ use ruma::{ uiaa, user_directory::search_users, }, + federation::discovery::get_server_version, error::FromHttpResponseError, FeatureFlag, MatrixVersion, OutgoingRequest, SupportedVersions, }, @@ -151,6 +152,15 @@ pub enum SessionChange { TokensRefreshed, } +/// Information about the server version obtained from the federation API. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ServerVersionInfo { + /// The server name. + pub server_name: OwnedServerName, + /// The server version. + pub version: String, +} + /// An async/await enabled Matrix client. /// /// All of the state is held in an `Arc` so the `Client` can be cloned freely. @@ -521,6 +531,40 @@ impl Client { Ok(res.capabilities) } + /// Get the server version information from the federation API. + /// + /// This method calls the `/_matrix/federation/v1/version` endpoint to get + /// both the server name and version. + /// + /// # Examples + /// + /// ```no_run + /// # use matrix_sdk::Client; + /// # use url::Url; + /// # async { + /// # let homeserver = Url::parse("http://example.com")?; + /// let client = Client::new(homeserver).await?; + /// + /// let server_info = client.server_version().await?; + /// println!("Server: {}, Version: {}", server_info.server_name, server_info.version); + /// # anyhow::Ok(()) }; + /// ``` + pub async fn server_version(&self) -> HttpResult { + let res = self.send(get_server_version::v1::Request::new()).await?; + + // Extract server info, using defaults if fields are missing + let server = res.server.unwrap_or_default(); + let server_name_str = server.name.unwrap_or_else(|| "unknown".to_string()); + let version = server.version.unwrap_or_else(|| "unknown".to_string()); + + // Try to parse the server name, fallback to a safe default if parsing fails + let server_name = server_name_str + .try_into() + .unwrap_or_else(|_| "unknown.server".try_into().unwrap()); + + Ok(ServerVersionInfo { server_name, version }) + } + /// Get a copy of the default request config. /// /// The default request config is what's used when sending requests if no diff --git a/crates/matrix-sdk/src/lib.rs b/crates/matrix-sdk/src/lib.rs index 2680d4cb1e3..349bc0dcecf 100644 --- a/crates/matrix-sdk/src/lib.rs +++ b/crates/matrix-sdk/src/lib.rs @@ -68,7 +68,8 @@ pub mod widget; pub use account::Account; pub use authentication::{AuthApi, AuthSession, SessionTokens}; pub use client::{ - sanitize_server_name, Client, ClientBuildError, ClientBuilder, LoopCtrl, SessionChange, + sanitize_server_name, Client, ClientBuildError, ClientBuilder, LoopCtrl, ServerVersionInfo, + SessionChange, }; pub use error::{ Error, HttpError, HttpResult, NotificationSettingsError, RefreshTokenError, Result, From 7bed5ea5d0ce77cae49806c6adca252ab385982d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 12 Aug 2025 09:57:23 +0000 Subject: [PATCH 03/10] Add tests for server_version method Co-authored-by: pixlwave <6060466+pixlwave@users.noreply.github.com> --- crates/matrix-sdk/tests/integration/client.rs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/crates/matrix-sdk/tests/integration/client.rs b/crates/matrix-sdk/tests/integration/client.rs index 8005dcb6f25..ca7523af34d 100644 --- a/crates/matrix-sdk/tests/integration/client.rs +++ b/crates/matrix-sdk/tests/integration/client.rs @@ -1490,3 +1490,53 @@ async fn test_room_sync_state_after() { let member = room.get_member_no_sync(user_id!("@invited:localhost")).await.unwrap().unwrap(); assert_eq!(*member.membership(), MembershipState::Leave); } + +#[async_test] +async fn test_server_version() { + use matrix_sdk::test_utils::mocks::MatrixMockServer; + use serde_json::json; + use wiremock::{matchers::{method, path}, Mock, ResponseTemplate}; + + let server = MatrixMockServer::new().await; + let client = server.client_builder().build().await; + + // Mock the federation version endpoint + Mock::given(method("GET")) + .and(path("/_matrix/federation/v1/version")) + .respond_with(ResponseTemplate::new(200).set_body_json(json!({ + "server": { + "name": "Synapse", + "version": "1.70.0" + } + }))) + .mount(server.server()) + .await; + + let server_info = client.server_version().await.unwrap(); + + assert_eq!(server_info.server_name.as_str(), "Synapse"); + assert_eq!(server_info.version, "1.70.0"); +} + +#[async_test] +async fn test_server_version_with_missing_fields() { + use matrix_sdk::test_utils::mocks::MatrixMockServer; + use serde_json::json; + use wiremock::{matchers::{method, path}, Mock, ResponseTemplate}; + + let server = MatrixMockServer::new().await; + let client = server.client_builder().build().await; + + // Mock the federation version endpoint with missing fields + Mock::given(method("GET")) + .and(path("/_matrix/federation/v1/version")) + .respond_with(ResponseTemplate::new(200).set_body_json(json!({}))) + .mount(server.server()) + .await; + + let server_info = client.server_version().await.unwrap(); + + // Should use defaults for missing fields + assert_eq!(server_info.server_name.as_str(), "unknown"); + assert_eq!(server_info.version, "unknown"); +} From 80d868b119b082f0ae665c7476cd229d501c9b65 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 12 Aug 2025 10:05:41 +0000 Subject: [PATCH 04/10] Implement server_version method for matrix-sdk-ffi Client Co-authored-by: pixlwave <6060466+pixlwave@users.noreply.github.com> --- bindings/matrix-sdk-ffi/src/client.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index 3ec0e70db36..7ef29ded864 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -1608,6 +1608,15 @@ impl Client { Ok(self.inner.server_versions().await?.contains(&ruma::api::MatrixVersion::V1_13)) } + /// Get the server version information from the federation API. + /// + /// This method calls the `/_matrix/federation/v1/version` endpoint to get + /// both the server name and version. + pub async fn server_version(&self) -> Result { + let server_info = self.inner.server_version().await?; + Ok(server_info.into()) + } + /// Checks if the server supports the LiveKit RTC focus for placing calls. pub async fn is_livekit_rtc_supported(&self) -> Result { Ok(self @@ -1797,6 +1806,23 @@ impl From for SearchUsersResults { } } +#[derive(uniffi::Record)] +pub struct ServerVersionInfo { + /// The server name. + pub server_name: String, + /// The server version. + pub version: String, +} + +impl From for ServerVersionInfo { + fn from(value: matrix_sdk::ServerVersionInfo) -> Self { + Self { + server_name: value.server_name.to_string(), + version: value.version, + } + } +} + #[derive(uniffi::Record)] pub struct UserProfile { pub user_id: String, From 9a157755009d460f936076f4ad69b90af29b368f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 12 Aug 2025 10:17:06 +0000 Subject: [PATCH 05/10] Change server_name field to String type and simplify implementation Co-authored-by: bnjbvr <1180019+bnjbvr@users.noreply.github.com> --- bindings/matrix-sdk-ffi/src/client.rs | 2 +- crates/matrix-sdk/src/client/mod.rs | 9 ++------- crates/matrix-sdk/tests/integration/client.rs | 4 ++-- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index 7ef29ded864..18b5a500eb2 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -1817,7 +1817,7 @@ pub struct ServerVersionInfo { impl From for ServerVersionInfo { fn from(value: matrix_sdk::ServerVersionInfo) -> Self { Self { - server_name: value.server_name.to_string(), + server_name: value.server_name, version: value.version, } } diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 5c69b452610..949384c65e0 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -156,7 +156,7 @@ pub enum SessionChange { #[derive(Debug, Clone, PartialEq, Eq)] pub struct ServerVersionInfo { /// The server name. - pub server_name: OwnedServerName, + pub server_name: String, /// The server version. pub version: String, } @@ -557,12 +557,7 @@ impl Client { let server_name_str = server.name.unwrap_or_else(|| "unknown".to_string()); let version = server.version.unwrap_or_else(|| "unknown".to_string()); - // Try to parse the server name, fallback to a safe default if parsing fails - let server_name = server_name_str - .try_into() - .unwrap_or_else(|_| "unknown.server".try_into().unwrap()); - - Ok(ServerVersionInfo { server_name, version }) + Ok(ServerVersionInfo { server_name: server_name_str, version }) } /// Get a copy of the default request config. diff --git a/crates/matrix-sdk/tests/integration/client.rs b/crates/matrix-sdk/tests/integration/client.rs index ca7523af34d..46809b96300 100644 --- a/crates/matrix-sdk/tests/integration/client.rs +++ b/crates/matrix-sdk/tests/integration/client.rs @@ -1514,7 +1514,7 @@ async fn test_server_version() { let server_info = client.server_version().await.unwrap(); - assert_eq!(server_info.server_name.as_str(), "Synapse"); + assert_eq!(server_info.server_name, "Synapse"); assert_eq!(server_info.version, "1.70.0"); } @@ -1537,6 +1537,6 @@ async fn test_server_version_with_missing_fields() { let server_info = client.server_version().await.unwrap(); // Should use defaults for missing fields - assert_eq!(server_info.server_name.as_str(), "unknown"); + assert_eq!(server_info.server_name, "unknown"); assert_eq!(server_info.version, "unknown"); } From f5669ce3b8deeeadbcbb6f830daf8fb874eb8c33 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 12 Aug 2025 11:13:06 +0000 Subject: [PATCH 06/10] feat(sdk): Add federation version mock endpoint and log server version in FFI Co-authored-by: pixlwave <6060466+pixlwave@users.noreply.github.com> --- bindings/matrix-sdk-ffi/src/client.rs | 26 ----------------- bindings/matrix-sdk-ffi/src/client_builder.rs | 11 ++++++++ crates/matrix-sdk/src/test_utils/mocks/mod.rs | 28 +++++++++++++++++++ crates/matrix-sdk/tests/integration/client.rs | 25 ++++++----------- 4 files changed, 47 insertions(+), 43 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index 18b5a500eb2..3ec0e70db36 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -1608,15 +1608,6 @@ impl Client { Ok(self.inner.server_versions().await?.contains(&ruma::api::MatrixVersion::V1_13)) } - /// Get the server version information from the federation API. - /// - /// This method calls the `/_matrix/federation/v1/version` endpoint to get - /// both the server name and version. - pub async fn server_version(&self) -> Result { - let server_info = self.inner.server_version().await?; - Ok(server_info.into()) - } - /// Checks if the server supports the LiveKit RTC focus for placing calls. pub async fn is_livekit_rtc_supported(&self) -> Result { Ok(self @@ -1806,23 +1797,6 @@ impl From for SearchUsersResults { } } -#[derive(uniffi::Record)] -pub struct ServerVersionInfo { - /// The server name. - pub server_name: String, - /// The server version. - pub version: String, -} - -impl From for ServerVersionInfo { - fn from(value: matrix_sdk::ServerVersionInfo) -> Self { - Self { - server_name: value.server_name, - version: value.version, - } - } -} - #[derive(uniffi::Record)] pub struct UserProfile { pub user_id: String, diff --git a/bindings/matrix-sdk-ffi/src/client_builder.rs b/bindings/matrix-sdk-ffi/src/client_builder.rs index e730fd8d96e..00889b12319 100644 --- a/bindings/matrix-sdk-ffi/src/client_builder.rs +++ b/bindings/matrix-sdk-ffi/src/client_builder.rs @@ -574,6 +574,17 @@ impl ClientBuilder { let sdk_client = inner_builder.build().await?; + // Log server version information at info level + if let Ok(server_info) = sdk_client.server_version().await { + tracing::info!( + server_name = %server_info.server_name, + version = %server_info.version, + "Connected to Matrix server" + ); + } else { + tracing::debug!("Could not retrieve server version information"); + } + Ok(Arc::new( Client::new( sdk_client, diff --git a/crates/matrix-sdk/src/test_utils/mocks/mod.rs b/crates/matrix-sdk/src/test_utils/mocks/mod.rs index 5d5d851ef63..eacb17a85cd 100644 --- a/crates/matrix-sdk/src/test_utils/mocks/mod.rs +++ b/crates/matrix-sdk/src/test_utils/mocks/mod.rs @@ -1377,6 +1377,12 @@ impl MatrixMockServer { ))); self.mock_endpoint(mock, EnablePushRuleEndpoint).expect_default_access_token() } + + /// Create a prebuilt mock for the federation version endpoint. + pub fn mock_federation_version(&self) -> MockEndpoint<'_, FederationVersionEndpoint> { + let mock = Mock::given(method("GET")).and(path("/_matrix/federation/v1/version")); + self.mock_endpoint(mock, FederationVersionEndpoint) + } } /// Parameter to [`MatrixMockServer::sync_room`]. @@ -3955,3 +3961,25 @@ impl<'a> MockEndpoint<'a, EnablePushRuleEndpoint> { self.ok_empty_json() } } + +/// A prebuilt mock for the federation version endpoint. +pub struct FederationVersionEndpoint; + +impl<'a> MockEndpoint<'a, FederationVersionEndpoint> { + /// Returns a successful response with the given server name and version. + pub fn ok(self, server_name: &str, version: &str) -> MatrixMock<'a> { + let response_body = json!({ + "server": { + "name": server_name, + "version": version + } + }); + self.respond_with(ResponseTemplate::new(200).set_body_json(response_body)) + } + + /// Returns a successful response with empty/missing server information. + pub fn ok_empty(self) -> MatrixMock<'a> { + let response_body = json!({}); + self.respond_with(ResponseTemplate::new(200).set_body_json(response_body)) + } +} diff --git a/crates/matrix-sdk/tests/integration/client.rs b/crates/matrix-sdk/tests/integration/client.rs index 46809b96300..27390aa59ca 100644 --- a/crates/matrix-sdk/tests/integration/client.rs +++ b/crates/matrix-sdk/tests/integration/client.rs @@ -1494,22 +1494,15 @@ async fn test_room_sync_state_after() { #[async_test] async fn test_server_version() { use matrix_sdk::test_utils::mocks::MatrixMockServer; - use serde_json::json; - use wiremock::{matchers::{method, path}, Mock, ResponseTemplate}; let server = MatrixMockServer::new().await; let client = server.client_builder().build().await; // Mock the federation version endpoint - Mock::given(method("GET")) - .and(path("/_matrix/federation/v1/version")) - .respond_with(ResponseTemplate::new(200).set_body_json(json!({ - "server": { - "name": "Synapse", - "version": "1.70.0" - } - }))) - .mount(server.server()) + server + .mock_federation_version() + .ok("Synapse", "1.70.0") + .mount() .await; let server_info = client.server_version().await.unwrap(); @@ -1521,17 +1514,15 @@ async fn test_server_version() { #[async_test] async fn test_server_version_with_missing_fields() { use matrix_sdk::test_utils::mocks::MatrixMockServer; - use serde_json::json; - use wiremock::{matchers::{method, path}, Mock, ResponseTemplate}; let server = MatrixMockServer::new().await; let client = server.client_builder().build().await; // Mock the federation version endpoint with missing fields - Mock::given(method("GET")) - .and(path("/_matrix/federation/v1/version")) - .respond_with(ResponseTemplate::new(200).set_body_json(json!({}))) - .mount(server.server()) + server + .mock_federation_version() + .ok_empty() + .mount() .await; let server_info = client.server_version().await.unwrap(); From c89a9ccdc47fb3b0fcf1af5a9eb6133c145ccf6e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 Aug 2025 08:41:51 +0000 Subject: [PATCH 07/10] refactor(sdk,ffi): Rename server_version to server_vendor_info and reinstate FFI method - Rename ServerVersionInfo to ServerVendorInfo with conditional uniffi derive - Rename server_version method to server_vendor_info in SDK - Update log level from debug to warn for server version retrieval failures - Reinstate server_vendor_info method in FFI bindings - Update tests and exports to use new naming Co-authored-by: bnjbvr <1180019+bnjbvr@users.noreply.github.com> --- bindings/matrix-sdk-ffi/src/client.rs | 8 ++++++++ bindings/matrix-sdk-ffi/src/client_builder.rs | 4 ++-- crates/matrix-sdk/src/client/mod.rs | 13 +++++++------ crates/matrix-sdk/src/lib.rs | 2 +- crates/matrix-sdk/tests/integration/client.rs | 8 ++++---- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index 3ec0e70db36..9b8589e0377 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -1618,6 +1618,14 @@ impl Client { .any(|focus| matches!(focus, RtcFocusInfo::LiveKit(_)))) } + /// Get server vendor information from the federation API. + /// + /// This method retrieves information about the server's name and version + /// by calling the `/_matrix/federation/v1/version` endpoint. + pub async fn server_vendor_info(&self) -> Result { + Ok(self.inner.server_vendor_info().await?) + } + /// Subscribe to changes in the media preview configuration. pub async fn subscribe_to_media_preview_config( &self, diff --git a/bindings/matrix-sdk-ffi/src/client_builder.rs b/bindings/matrix-sdk-ffi/src/client_builder.rs index 00889b12319..1de916f867c 100644 --- a/bindings/matrix-sdk-ffi/src/client_builder.rs +++ b/bindings/matrix-sdk-ffi/src/client_builder.rs @@ -575,14 +575,14 @@ impl ClientBuilder { let sdk_client = inner_builder.build().await?; // Log server version information at info level - if let Ok(server_info) = sdk_client.server_version().await { + if let Ok(server_info) = sdk_client.server_vendor_info().await { tracing::info!( server_name = %server_info.server_name, version = %server_info.version, "Connected to Matrix server" ); } else { - tracing::debug!("Could not retrieve server version information"); + tracing::warn!("Could not retrieve server version information"); } Ok(Arc::new( diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 949384c65e0..68c8bcd3f6e 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -152,9 +152,10 @@ pub enum SessionChange { TokensRefreshed, } -/// Information about the server version obtained from the federation API. +/// Information about the server vendor obtained from the federation API. #[derive(Debug, Clone, PartialEq, Eq)] -pub struct ServerVersionInfo { +#[cfg_attr(feature = "uniffi", derive(uniffi::Record))] +pub struct ServerVendorInfo { /// The server name. pub server_name: String, /// The server version. @@ -531,7 +532,7 @@ impl Client { Ok(res.capabilities) } - /// Get the server version information from the federation API. + /// Get the server vendor information from the federation API. /// /// This method calls the `/_matrix/federation/v1/version` endpoint to get /// both the server name and version. @@ -545,11 +546,11 @@ impl Client { /// # let homeserver = Url::parse("http://example.com")?; /// let client = Client::new(homeserver).await?; /// - /// let server_info = client.server_version().await?; + /// let server_info = client.server_vendor_info().await?; /// println!("Server: {}, Version: {}", server_info.server_name, server_info.version); /// # anyhow::Ok(()) }; /// ``` - pub async fn server_version(&self) -> HttpResult { + pub async fn server_vendor_info(&self) -> HttpResult { let res = self.send(get_server_version::v1::Request::new()).await?; // Extract server info, using defaults if fields are missing @@ -557,7 +558,7 @@ impl Client { let server_name_str = server.name.unwrap_or_else(|| "unknown".to_string()); let version = server.version.unwrap_or_else(|| "unknown".to_string()); - Ok(ServerVersionInfo { server_name: server_name_str, version }) + Ok(ServerVendorInfo { server_name: server_name_str, version }) } /// Get a copy of the default request config. diff --git a/crates/matrix-sdk/src/lib.rs b/crates/matrix-sdk/src/lib.rs index 349bc0dcecf..af050d5fe74 100644 --- a/crates/matrix-sdk/src/lib.rs +++ b/crates/matrix-sdk/src/lib.rs @@ -68,7 +68,7 @@ pub mod widget; pub use account::Account; pub use authentication::{AuthApi, AuthSession, SessionTokens}; pub use client::{ - sanitize_server_name, Client, ClientBuildError, ClientBuilder, LoopCtrl, ServerVersionInfo, + sanitize_server_name, Client, ClientBuildError, ClientBuilder, LoopCtrl, ServerVendorInfo, SessionChange, }; pub use error::{ diff --git a/crates/matrix-sdk/tests/integration/client.rs b/crates/matrix-sdk/tests/integration/client.rs index 27390aa59ca..a1f199f5ffe 100644 --- a/crates/matrix-sdk/tests/integration/client.rs +++ b/crates/matrix-sdk/tests/integration/client.rs @@ -1492,7 +1492,7 @@ async fn test_room_sync_state_after() { } #[async_test] -async fn test_server_version() { +async fn test_server_vendor_info() { use matrix_sdk::test_utils::mocks::MatrixMockServer; let server = MatrixMockServer::new().await; @@ -1505,14 +1505,14 @@ async fn test_server_version() { .mount() .await; - let server_info = client.server_version().await.unwrap(); + let server_info = client.server_vendor_info().await.unwrap(); assert_eq!(server_info.server_name, "Synapse"); assert_eq!(server_info.version, "1.70.0"); } #[async_test] -async fn test_server_version_with_missing_fields() { +async fn test_server_vendor_info_with_missing_fields() { use matrix_sdk::test_utils::mocks::MatrixMockServer; let server = MatrixMockServer::new().await; @@ -1525,7 +1525,7 @@ async fn test_server_version_with_missing_fields() { .mount() .await; - let server_info = client.server_version().await.unwrap(); + let server_info = client.server_vendor_info().await.unwrap(); // Should use defaults for missing fields assert_eq!(server_info.server_name, "unknown"); From d81a54101b455764a17ec84498e6f6e9796690c3 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Wed, 13 Aug 2025 15:35:29 +0200 Subject: [PATCH 08/10] Apply suggestions from code review Signed-off-by: Benjamin Bouvier --- bindings/matrix-sdk-ffi/src/client_builder.rs | 2 +- crates/matrix-sdk/src/client/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/client_builder.rs b/bindings/matrix-sdk-ffi/src/client_builder.rs index 1de916f867c..b6edc4d4374 100644 --- a/bindings/matrix-sdk-ffi/src/client_builder.rs +++ b/bindings/matrix-sdk-ffi/src/client_builder.rs @@ -574,7 +574,7 @@ impl ClientBuilder { let sdk_client = inner_builder.build().await?; - // Log server version information at info level + // Log server version information at info level. if let Ok(server_info) = sdk_client.server_vendor_info().await { tracing::info!( server_name = %server_info.server_name, diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 68c8bcd3f6e..a5077064063 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -535,7 +535,7 @@ impl Client { /// Get the server vendor information from the federation API. /// /// This method calls the `/_matrix/federation/v1/version` endpoint to get - /// both the server name and version. + /// both the server's software name and version. /// /// # Examples /// @@ -553,7 +553,7 @@ impl Client { pub async fn server_vendor_info(&self) -> HttpResult { let res = self.send(get_server_version::v1::Request::new()).await?; - // Extract server info, using defaults if fields are missing + // Extract server info, using defaults if fields are missing. let server = res.server.unwrap_or_default(); let server_name_str = server.name.unwrap_or_else(|| "unknown".to_string()); let version = server.version.unwrap_or_else(|| "unknown".to_string()); From 7d13bd67f34e0bd138b4979340f40f88b0f58ce7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 Aug 2025 13:56:03 +0000 Subject: [PATCH 09/10] fix: Replace to_string() with to_owned() for string literals to resolve clippy warnings Co-authored-by: bnjbvr <1180019+bnjbvr@users.noreply.github.com> --- crates/matrix-sdk/src/client/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index a5077064063..7c98f62940e 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -555,8 +555,8 @@ impl Client { // Extract server info, using defaults if fields are missing. let server = res.server.unwrap_or_default(); - let server_name_str = server.name.unwrap_or_else(|| "unknown".to_string()); - let version = server.version.unwrap_or_else(|| "unknown".to_string()); + let server_name_str = server.name.unwrap_or_else(|| "unknown".to_owned()); + let version = server.version.unwrap_or_else(|| "unknown".to_owned()); Ok(ServerVendorInfo { server_name: server_name_str, version }) } From 2e3f8227ca278823220fdd91b2af1051162c7e29 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 Aug 2025 15:33:06 +0000 Subject: [PATCH 10/10] fix: formatting issues from cargo fmt Co-authored-by: bnjbvr <1180019+bnjbvr@users.noreply.github.com> --- crates/matrix-sdk/src/client/mod.rs | 11 +++++++---- crates/matrix-sdk/tests/integration/client.rs | 16 ++++------------ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 7c98f62940e..1c7314925dd 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -62,8 +62,8 @@ use ruma::{ uiaa, user_directory::search_users, }, - federation::discovery::get_server_version, error::FromHttpResponseError, + federation::discovery::get_server_version, FeatureFlag, MatrixVersion, OutgoingRequest, SupportedVersions, }, assign, @@ -547,17 +547,20 @@ impl Client { /// let client = Client::new(homeserver).await?; /// /// let server_info = client.server_vendor_info().await?; - /// println!("Server: {}, Version: {}", server_info.server_name, server_info.version); + /// println!( + /// "Server: {}, Version: {}", + /// server_info.server_name, server_info.version + /// ); /// # anyhow::Ok(()) }; /// ``` pub async fn server_vendor_info(&self) -> HttpResult { let res = self.send(get_server_version::v1::Request::new()).await?; - + // Extract server info, using defaults if fields are missing. let server = res.server.unwrap_or_default(); let server_name_str = server.name.unwrap_or_else(|| "unknown".to_owned()); let version = server.version.unwrap_or_else(|| "unknown".to_owned()); - + Ok(ServerVendorInfo { server_name: server_name_str, version }) } diff --git a/crates/matrix-sdk/tests/integration/client.rs b/crates/matrix-sdk/tests/integration/client.rs index a1f199f5ffe..957f3422b0b 100644 --- a/crates/matrix-sdk/tests/integration/client.rs +++ b/crates/matrix-sdk/tests/integration/client.rs @@ -1499,14 +1499,10 @@ async fn test_server_vendor_info() { let client = server.client_builder().build().await; // Mock the federation version endpoint - server - .mock_federation_version() - .ok("Synapse", "1.70.0") - .mount() - .await; + server.mock_federation_version().ok("Synapse", "1.70.0").mount().await; let server_info = client.server_vendor_info().await.unwrap(); - + assert_eq!(server_info.server_name, "Synapse"); assert_eq!(server_info.version, "1.70.0"); } @@ -1519,14 +1515,10 @@ async fn test_server_vendor_info_with_missing_fields() { let client = server.client_builder().build().await; // Mock the federation version endpoint with missing fields - server - .mock_federation_version() - .ok_empty() - .mount() - .await; + server.mock_federation_version().ok_empty().mount().await; let server_info = client.server_vendor_info().await.unwrap(); - + // Should use defaults for missing fields assert_eq!(server_info.server_name, "unknown"); assert_eq!(server_info.version, "unknown");