From f78f1795ebf243347ea441ef136faa05cf0e1172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Sun, 19 Oct 2025 12:23:19 +0200 Subject: [PATCH] Upgrade Ruma MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A new batch of breaking changes, allowing to stop providing dummy `SupportedVersions` where they are not necessary. Signed-off-by: Kévin Commaille --- Cargo.lock | 18 ++++---- Cargo.toml | 2 +- .../src/authentication/matrix/mod.rs | 6 +-- .../oauth/qrcode/rendezvous_channel.rs | 7 +++- .../src/client/builder/homeserver_config.rs | 15 ++----- crates/matrix-sdk/src/client/futures.rs | 5 ++- crates/matrix-sdk/src/client/mod.rs | 35 ++++++---------- crates/matrix-sdk/src/http_client/mod.rs | 42 +++++++++++++++---- crates/matrix-sdk/src/media.rs | 6 +-- 9 files changed, 77 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e9d40433e..748d4bb53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4822,7 +4822,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.13.0" -source = "git+https://github.com/ruma/ruma?rev=670349f66f7e3f403c6730967768472dcf1bcf60#670349f66f7e3f403c6730967768472dcf1bcf60" +source = "git+https://github.com/ruma/ruma?rev=bbb4a14e14864d364b78d605532db580eb2b28f0#bbb4a14e14864d364b78d605532db580eb2b28f0" dependencies = [ "assign", "js_int", @@ -4839,7 +4839,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.21.0" -source = "git+https://github.com/ruma/ruma?rev=670349f66f7e3f403c6730967768472dcf1bcf60#670349f66f7e3f403c6730967768472dcf1bcf60" +source = "git+https://github.com/ruma/ruma?rev=bbb4a14e14864d364b78d605532db580eb2b28f0#bbb4a14e14864d364b78d605532db580eb2b28f0" dependencies = [ "as_variant", "assign", @@ -4862,7 +4862,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.16.0" -source = "git+https://github.com/ruma/ruma?rev=670349f66f7e3f403c6730967768472dcf1bcf60#670349f66f7e3f403c6730967768472dcf1bcf60" +source = "git+https://github.com/ruma/ruma?rev=bbb4a14e14864d364b78d605532db580eb2b28f0#bbb4a14e14864d364b78d605532db580eb2b28f0" dependencies = [ "as_variant", "base64", @@ -4895,7 +4895,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.31.0" -source = "git+https://github.com/ruma/ruma?rev=670349f66f7e3f403c6730967768472dcf1bcf60#670349f66f7e3f403c6730967768472dcf1bcf60" +source = "git+https://github.com/ruma/ruma?rev=bbb4a14e14864d364b78d605532db580eb2b28f0#bbb4a14e14864d364b78d605532db580eb2b28f0" dependencies = [ "as_variant", "indexmap", @@ -4921,7 +4921,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.12.0" -source = "git+https://github.com/ruma/ruma?rev=670349f66f7e3f403c6730967768472dcf1bcf60#670349f66f7e3f403c6730967768472dcf1bcf60" +source = "git+https://github.com/ruma/ruma?rev=bbb4a14e14864d364b78d605532db580eb2b28f0#bbb4a14e14864d364b78d605532db580eb2b28f0" dependencies = [ "headers", "http", @@ -4941,7 +4941,7 @@ dependencies = [ [[package]] name = "ruma-html" version = "0.5.0" -source = "git+https://github.com/ruma/ruma?rev=670349f66f7e3f403c6730967768472dcf1bcf60#670349f66f7e3f403c6730967768472dcf1bcf60" +source = "git+https://github.com/ruma/ruma?rev=bbb4a14e14864d364b78d605532db580eb2b28f0#bbb4a14e14864d364b78d605532db580eb2b28f0" dependencies = [ "as_variant", "html5ever", @@ -4952,7 +4952,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.11.0" -source = "git+https://github.com/ruma/ruma?rev=670349f66f7e3f403c6730967768472dcf1bcf60#670349f66f7e3f403c6730967768472dcf1bcf60" +source = "git+https://github.com/ruma/ruma?rev=bbb4a14e14864d364b78d605532db580eb2b28f0#bbb4a14e14864d364b78d605532db580eb2b28f0" dependencies = [ "js_int", "thiserror 2.0.16", @@ -4961,7 +4961,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.16.0" -source = "git+https://github.com/ruma/ruma?rev=670349f66f7e3f403c6730967768472dcf1bcf60#670349f66f7e3f403c6730967768472dcf1bcf60" +source = "git+https://github.com/ruma/ruma?rev=bbb4a14e14864d364b78d605532db580eb2b28f0#bbb4a14e14864d364b78d605532db580eb2b28f0" dependencies = [ "cfg-if", "proc-macro-crate", @@ -4976,7 +4976,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.18.0" -source = "git+https://github.com/ruma/ruma?rev=670349f66f7e3f403c6730967768472dcf1bcf60#670349f66f7e3f403c6730967768472dcf1bcf60" +source = "git+https://github.com/ruma/ruma?rev=bbb4a14e14864d364b78d605532db580eb2b28f0#bbb4a14e14864d364b78d605532db580eb2b28f0" dependencies = [ "base64", "ed25519-dalek", diff --git a/Cargo.toml b/Cargo.toml index 4b8ca1a52..63ade22bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,7 +66,7 @@ rand = "0.8.5" regex = "1.11.2" reqwest = { version = "0.12.23", default-features = false } rmp-serde = "1.3.0" -ruma = { git = "https://github.com/ruma/ruma", rev = "670349f66f7e3f403c6730967768472dcf1bcf60", features = [ +ruma = { git = "https://github.com/ruma/ruma", rev = "bbb4a14e14864d364b78d605532db580eb2b28f0", features = [ "client-api-c", "compat-upload-signatures", "compat-arbitrary-length-ids", diff --git a/crates/matrix-sdk/src/authentication/matrix/mod.rs b/crates/matrix-sdk/src/authentication/matrix/mod.rs index 058179346..70073c68d 100644 --- a/crates/matrix-sdk/src/authentication/matrix/mod.rs +++ b/crates/matrix-sdk/src/authentication/matrix/mod.rs @@ -16,9 +16,9 @@ //! Types to interact with the native Matrix authentication API. -use std::fmt; #[cfg(feature = "sso-login")] use std::future::Future; +use std::{borrow::Cow, fmt}; use matrix_sdk_base::{SessionMeta, store::RoomLoadSettings}; use ruma::{ @@ -112,13 +112,13 @@ impl MatrixAuth { .try_into_http_request::>( homeserver.as_str(), SendAccessToken::None, - &supported_versions, + Cow::Owned(supported_versions), ) } else { sso_login::v3::Request::new(redirect_url.to_owned()).try_into_http_request::>( homeserver.as_str(), SendAccessToken::None, - &supported_versions, + Cow::Owned(supported_versions), ) }; diff --git a/crates/matrix-sdk/src/authentication/oauth/qrcode/rendezvous_channel.rs b/crates/matrix-sdk/src/authentication/oauth/qrcode/rendezvous_channel.rs index 14c5ec4cf..3271dcc05 100644 --- a/crates/matrix-sdk/src/authentication/oauth/qrcode/rendezvous_channel.rs +++ b/crates/matrix-sdk/src/authentication/oauth/qrcode/rendezvous_channel.rs @@ -113,6 +113,8 @@ impl RendezvousChannel { client: HttpClient, rendezvous_server: &Url, ) -> Result { + use std::borrow::Cow; + use ruma::api::{SupportedVersions, client::rendezvous::create_rendezvous_session}; let request = create_rendezvous_session::unstable::Request::default(); @@ -122,7 +124,10 @@ impl RendezvousChannel { None, rendezvous_server.to_string(), None, - &SupportedVersions { versions: Default::default(), features: Default::default() }, + Cow::Owned(SupportedVersions { + versions: Default::default(), + features: Default::default(), + }), Default::default(), ) .await?; diff --git a/crates/matrix-sdk/src/client/builder/homeserver_config.rs b/crates/matrix-sdk/src/client/builder/homeserver_config.rs index 1423bdb07..2c1c3b8e2 100644 --- a/crates/matrix-sdk/src/client/builder/homeserver_config.rs +++ b/crates/matrix-sdk/src/client/builder/homeserver_config.rs @@ -14,10 +14,7 @@ use ruma::{ OwnedServerName, ServerName, - api::{ - MatrixVersion, SupportedVersions, - client::discovery::{discover_homeserver, get_supported_versions}, - }, + api::client::discovery::{discover_homeserver, get_supported_versions}, }; use tracing::debug; use url::Url; @@ -185,10 +182,7 @@ async fn discover_homeserver( Some(RequestConfig::short_retry()), server.to_string(), None, - &SupportedVersions { - versions: [MatrixVersion::V1_0].into(), - features: Default::default(), - }, + (), Default::default(), ) .await @@ -212,10 +206,7 @@ pub(super) async fn get_supported_versions( Some(RequestConfig::short_retry()), homeserver_url.to_string(), None, - &SupportedVersions { - versions: [MatrixVersion::V1_0].into(), - features: Default::default(), - }, + (), Default::default(), ) .await diff --git a/crates/matrix-sdk/src/client/futures.rs b/crates/matrix-sdk/src/client/futures.rs index fd4107fd1..3769f542c 100644 --- a/crates/matrix-sdk/src/client/futures.rs +++ b/crates/matrix-sdk/src/client/futures.rs @@ -24,6 +24,7 @@ use ruma::api::{ OutgoingRequest, client::{error::ErrorKind, media}, error::FromHttpResponseError, + path_builder::PathBuilder, }; use tracing::{error, trace}; @@ -33,7 +34,7 @@ use crate::{ authentication::oauth::OAuthError, config::RequestConfig, error::{HttpError, HttpResult}, - http_client::SupportedAuthScheme, + http_client::{SupportedAuthScheme, SupportedPathBuilder}, media::MediaError, }; @@ -79,6 +80,8 @@ impl IntoFuture for SendRequest where R: OutgoingRequest + Clone + Debug + SendOutsideWasm + SyncOutsideWasm + 'static, R::Authentication: SupportedAuthScheme, + R::PathBuilder: SupportedPathBuilder, + for<'a> ::Input<'a>: SendOutsideWasm + SyncOutsideWasm, R::IncomingResponse: SendOutsideWasm + SyncOutsideWasm, HttpError: From>, { diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 7ff746396..505911ee8 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -45,7 +45,7 @@ use ruma::{ DeviceId, OwnedDeviceId, OwnedEventId, OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, RoomAliasId, RoomId, RoomOrAliasId, ServerName, UInt, UserId, api::{ - FeatureFlag, MatrixVersion, OutgoingRequest, SupportedVersions, + FeatureFlag, MatrixVersion, Metadata, OutgoingRequest, SupportedVersions, client::{ account::whoami, alias::{create_alias, delete_alias, get_alias}, @@ -71,6 +71,7 @@ use ruma::{ }, error::FromHttpResponseError, federation::discovery::get_server_version, + path_builder::PathBuilder, }, assign, events::direct::DirectUserIdentifier, @@ -99,7 +100,7 @@ use crate::{ EventHandler, EventHandlerContext, EventHandlerDropGuard, EventHandlerHandle, EventHandlerStore, ObservableEventHandler, SyncEvent, }, - http_client::{HttpClient, SupportedAuthScheme}, + http_client::{HttpClient, SupportedAuthScheme, SupportedPathBuilder}, latest_events::LatestEvents, media::MediaError, notification_settings::NotificationSettings, @@ -1895,6 +1896,8 @@ impl Client { where Request: OutgoingRequest + Clone + Debug, Request::Authentication: SupportedAuthScheme, + Request::PathBuilder: SupportedPathBuilder, + for<'a> ::Input<'a>: SendOutsideWasm + SyncOutsideWasm, HttpError: From>, { SendRequest { @@ -1914,10 +1917,13 @@ impl Client { where Request: OutgoingRequest + Debug, Request::Authentication: SupportedAuthScheme, + Request::PathBuilder: SupportedPathBuilder, + for<'a> ::Input<'a>: SendOutsideWasm + SyncOutsideWasm, HttpError: From>, { let homeserver = self.homeserver().to_string(); let access_token = self.access_token(); + let path_builder_input = Request::PathBuilder::get_path_builder_input(self).await?; self.inner .http_client @@ -1926,7 +1932,7 @@ impl Client { config, homeserver, access_token.as_deref(), - &self.supported_versions().await?, + path_builder_input, send_progress, ) .await @@ -1946,19 +1952,7 @@ impl Client { request_config: Option, ) -> HttpResult { let server_versions = self - .inner - .http_client - .send( - get_supported_versions::Request::new(), - request_config, - self.homeserver().to_string(), - None, - &SupportedVersions { - versions: [MatrixVersion::V1_0].into(), - features: Default::default(), - }, - Default::default(), - ) + .send_inner(get_supported_versions::Request::new(), request_config, Default::default()) .await?; Ok(server_versions) @@ -1983,10 +1977,7 @@ impl Client { Some(RequestConfig::short_retry()), server_url_string, None, - &SupportedVersions { - versions: [MatrixVersion::V1_0].into(), - features: Default::default(), - }, + (), Default::default(), ) .await; @@ -2925,8 +2916,8 @@ impl Client { // Use the authenticated endpoint when the server supports it. let supported_versions = self.supported_versions().await?; - let use_auth = - authenticated_media::get_media_config::v1::Request::is_supported(&supported_versions); + let use_auth = authenticated_media::get_media_config::v1::Request::PATH_BUILDER + .is_supported(&supported_versions); let upload_size = if use_auth { self.send(authenticated_media::get_media_config::v1::Request::default()) diff --git a/crates/matrix-sdk/src/http_client/mod.rs b/crates/matrix-sdk/src/http_client/mod.rs index 557574f8e..2af43bca6 100644 --- a/crates/matrix-sdk/src/http_client/mod.rs +++ b/crates/matrix-sdk/src/http_client/mod.rs @@ -14,6 +14,7 @@ use std::{ any::type_name, + borrow::Cow, fmt::Debug, num::NonZeroUsize, sync::{ @@ -27,14 +28,16 @@ use bytes::{Bytes, BytesMut}; use bytesize::ByteSize; use eyeball::SharedObservable; use http::Method; +use matrix_sdk_base::SendOutsideWasm; use ruma::api::{ - OutgoingRequest, SendAccessToken, SupportedVersions, auth_scheme, + OutgoingRequest, SendAccessToken, auth_scheme, error::{FromHttpResponseError, IntoHttpError}, + path_builder, }; use tokio::sync::{Semaphore, SemaphorePermit}; use tracing::{debug, field::debug, instrument, trace}; -use crate::{config::RequestConfig, error::HttpError}; +use crate::{HttpResult, config::RequestConfig, error::HttpError}; #[cfg(not(target_family = "wasm"))] mod native; @@ -101,7 +104,7 @@ impl HttpClient { config: RequestConfig, homeserver: String, access_token: Option<&str>, - supported_versions: &SupportedVersions, + path_builder_input: ::Input<'_>, ) -> Result, IntoHttpError> where R: OutgoingRequest + Debug, @@ -120,7 +123,7 @@ impl HttpClient { }; let request = request - .try_into_http_request::(&homeserver, send_access_token, supported_versions)? + .try_into_http_request::(&homeserver, send_access_token, path_builder_input)? .map(|body| body.freeze()); Ok(request) @@ -128,7 +131,7 @@ impl HttpClient { #[allow(clippy::too_many_arguments)] #[instrument( - skip(self, request, config, homeserver, access_token, supported_versions, send_progress), + skip(self, request, config, homeserver, access_token, path_builder_input, send_progress), fields( uri, method, @@ -146,7 +149,7 @@ impl HttpClient { config: Option, homeserver: String, access_token: Option<&str>, - supported_versions: &SupportedVersions, + path_builder_input: ::Input<'_>, send_progress: SharedObservable, ) -> Result where @@ -170,7 +173,7 @@ impl HttpClient { span.record("config", debug(config)).record("request_id", request_id); let request = self - .serialize_request(request, config, homeserver, access_token, supported_versions) + .serialize_request(request, config, homeserver, access_token, path_builder_input) .map_err(HttpError::IntoHttp)?; let method = request.method(); @@ -260,6 +263,31 @@ impl SupportedAuthScheme for auth_scheme::AppserviceToken {} impl SupportedAuthScheme for auth_scheme::AppserviceTokenOptional {} +/// Marker trait to identify the authentication schemes that the +/// [`Client`](crate::Client) supports. +/// +/// This trait can also be implemented for custom +/// [`PathBuilder`](path_builder::PathBuilder)s if necessary. +pub trait SupportedPathBuilder: path_builder::PathBuilder { + fn get_path_builder_input( + client: &crate::Client, + ) -> impl Future>> + SendOutsideWasm; +} + +impl SupportedPathBuilder for path_builder::VersionHistory { + async fn get_path_builder_input( + client: &crate::Client, + ) -> HttpResult> { + client.supported_versions().await.map(Cow::Owned) + } +} + +impl SupportedPathBuilder for path_builder::SinglePath { + async fn get_path_builder_input(_client: &crate::Client) -> HttpResult<()> { + Ok(()) + } +} + #[cfg(all(test, not(target_family = "wasm")))] mod tests { use std::{ diff --git a/crates/matrix-sdk/src/media.rs b/crates/matrix-sdk/src/media.rs index 93ca60c3e..85725819e 100644 --- a/crates/matrix-sdk/src/media.rs +++ b/crates/matrix-sdk/src/media.rs @@ -29,7 +29,7 @@ use mime::Mime; use ruma::{ MilliSecondsSinceUnixEpoch, MxcUri, OwnedMxcUri, TransactionId, UInt, api::{ - OutgoingRequest, + Metadata, client::{authenticated_media, error::ErrorKind, media}, }, assign, @@ -442,8 +442,8 @@ impl Media { // Use the authenticated endpoints when the server supports it. let supported_versions = self.client.supported_versions().await?; - let use_auth = - authenticated_media::get_content::v1::Request::is_supported(&supported_versions); + let use_auth = authenticated_media::get_content::v1::Request::PATH_BUILDER + .is_supported(&supported_versions); let content: Vec = match &request.source { MediaSource::Encrypted(file) => {