Skip to content

Commit c41ed8a

Browse files
zecakehstefanceriu
authored andcommitted
refactor(sdk): Use Ruma support for (un)stable feature flags for authenticated media
Signed-off-by: Kévin Commaille <[email protected]>
1 parent 53f02c9 commit c41ed8a

File tree

3 files changed

+7
-41
lines changed

3 files changed

+7
-41
lines changed

crates/matrix-sdk/src/config/request.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use std::{
1919
};
2020

2121
use matrix_sdk_common::debug::DebugStructExt;
22-
use ruma::api::MatrixVersion;
2322

2423
use crate::http_client::DEFAULT_REQUEST_TIMEOUT;
2524

@@ -49,7 +48,6 @@ pub struct RequestConfig {
4948
pub(crate) max_retry_time: Option<Duration>,
5049
pub(crate) max_concurrent_requests: Option<NonZeroUsize>,
5150
pub(crate) force_auth: bool,
52-
pub(crate) force_matrix_version: Option<MatrixVersion>,
5351
}
5452

5553
#[cfg(not(tarpaulin_include))]
@@ -62,16 +60,14 @@ impl Debug for RequestConfig {
6260
max_retry_time: retry_timeout,
6361
force_auth,
6462
max_concurrent_requests,
65-
force_matrix_version,
6663
} = self;
6764

6865
let mut res = fmt.debug_struct("RequestConfig");
6966
res.field("timeout", timeout)
7067
.maybe_field("read_timeout", read_timeout)
7168
.maybe_field("retry_limit", retry_limit)
7269
.maybe_field("max_retry_time", retry_timeout)
73-
.maybe_field("max_concurrent_requests", max_concurrent_requests)
74-
.maybe_field("force_matrix_version", force_matrix_version);
70+
.maybe_field("max_concurrent_requests", max_concurrent_requests);
7571

7672
if *force_auth {
7773
res.field("force_auth", &true);
@@ -90,7 +86,6 @@ impl Default for RequestConfig {
9086
max_retry_time: Default::default(),
9187
max_concurrent_requests: Default::default(),
9288
force_auth: false,
93-
force_matrix_version: Default::default(),
9489
}
9590
}
9691
}
@@ -173,17 +168,6 @@ impl RequestConfig {
173168
self.force_auth = true;
174169
self
175170
}
176-
177-
/// Force the Matrix version used to select which version of the endpoint to
178-
/// use.
179-
///
180-
/// Can be used to force the use of a stable endpoint when the versions
181-
/// advertised by the homeserver do not support it.
182-
#[must_use]
183-
pub(crate) fn force_matrix_version(mut self, version: MatrixVersion) -> Self {
184-
self.force_matrix_version = Some(version);
185-
self
186-
}
187171
}
188172

189173
#[cfg(test)]

crates/matrix-sdk/src/http_client/mod.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
use std::{
1616
any::type_name,
17-
borrow::Cow,
1817
fmt::Debug,
1918
num::NonZeroUsize,
2019
sync::{
@@ -109,15 +108,6 @@ impl HttpClient {
109108
{
110109
trace!(request_type = type_name::<R>(), "Serializing request");
111110

112-
let supported_versions = if let Some(matrix_version) = config.force_matrix_version {
113-
Cow::Owned(SupportedVersions {
114-
versions: [matrix_version].into(),
115-
features: Default::default(),
116-
})
117-
} else {
118-
Cow::Borrowed(supported_versions)
119-
};
120-
121111
let send_access_token = match access_token {
122112
Some(access_token) => {
123113
if config.force_auth {
@@ -130,7 +120,7 @@ impl HttpClient {
130120
};
131121

132122
let request = request
133-
.try_into_http_request::<BytesMut>(&homeserver, send_access_token, &supported_versions)?
123+
.try_into_http_request::<BytesMut>(&homeserver, send_access_token, supported_versions)?
134124
.map(|body| body.freeze());
135125

136126
Ok(request)

crates/matrix-sdk/src/media.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use mime::Mime;
2929
use ruma::{
3030
api::{
3131
client::{authenticated_media, error::ErrorKind, media},
32-
FeatureFlag, MatrixVersion,
32+
OutgoingRequest,
3333
},
3434
assign,
3535
events::room::{MediaSource, ThumbnailInfo},
@@ -441,18 +441,10 @@ impl Media {
441441
// available for the user or the file size
442442
.timeout(None);
443443

444-
// Use the authenticated endpoints when the server supports Matrix 1.11 or the
445-
// authenticated media stable feature.
446-
let (use_auth, request_config) =
447-
if self.client.server_versions().await?.contains(&MatrixVersion::V1_11) {
448-
(true, request_config)
449-
} else if self.client.unstable_features().await?.contains(&FeatureFlag::Msc3916Stable) {
450-
// We need to force the use of the stable endpoint with the Matrix version
451-
// because Ruma does not handle stable features.
452-
(true, request_config.force_matrix_version(MatrixVersion::V1_11))
453-
} else {
454-
(false, request_config)
455-
};
444+
// Use the authenticated endpoints when the server supports it.
445+
let supported_versions = self.client.supported_versions().await?;
446+
let use_auth =
447+
authenticated_media::get_content::v1::Request::is_supported(&supported_versions);
456448

457449
let content: Vec<u8> = match &request.source {
458450
MediaSource::Encrypted(file) => {

0 commit comments

Comments
 (0)