diff --git a/ruma-client-api/CHANGELOG.md b/ruma-client-api/CHANGELOG.md index 68b91b6f..7d048e1d 100644 --- a/ruma-client-api/CHANGELOG.md +++ b/ruma-client-api/CHANGELOG.md @@ -89,6 +89,14 @@ Improvements: * `r0::message::get_message_events` * Add `logout_devices` field to `r0::account::change_password` * Add `r0::room::aliases` (introduced in r0.6.1) +* Add constructors that use `ruma_identifiers::MxcUri` for `Request` in the following endpoints: + ```rust + r0::media::{ + get_content, + get_content_as_filename, + get_content_thumbnail + } + ``` # 0.9.0 diff --git a/ruma-client-api/src/r0/media/get_content.rs b/ruma-client-api/src/r0/media/get_content.rs index 0569a0f1..0812d47f 100644 --- a/ruma-client-api/src/r0/media/get_content.rs +++ b/ruma-client-api/src/r0/media/get_content.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/media/r0/download/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-media-r0-download-servername-mediaid) use ruma_api::ruma_api; -use ruma_identifiers::ServerName; +use ruma_identifiers::{MxcUri, ServerName}; ruma_api! { metadata: { @@ -57,6 +57,11 @@ impl<'a> Request<'a> { pub fn new(media_id: &'a str, server_name: &'a ServerName) -> Self { Self { media_id, server_name, allow_remote: true } } + + /// Creates a new `Request` with the given url. + pub fn from_url(url: &'a MxcUri) -> Self { + Self { media_id: url.media_id(), server_name: url.server_name(), allow_remote: true } + } } impl Response { diff --git a/ruma-client-api/src/r0/media/get_content_as_filename.rs b/ruma-client-api/src/r0/media/get_content_as_filename.rs index d58f8e6b..ee60102d 100644 --- a/ruma-client-api/src/r0/media/get_content_as_filename.rs +++ b/ruma-client-api/src/r0/media/get_content_as_filename.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-media-r0-download-servername-mediaid-filename) use ruma_api::ruma_api; -use ruma_identifiers::ServerName; +use ruma_identifiers::{MxcUri, ServerName}; ruma_api! { metadata: { @@ -62,6 +62,16 @@ impl<'a> Request<'a> { pub fn new(media_id: &'a str, server_name: &'a ServerName, filename: &'a str) -> Self { Self { media_id, server_name, filename, allow_remote: true } } + + /// Creates a new `Request` with the given url and filename. + pub fn from_url(url: &'a MxcUri, filename: &'a str) -> Self { + Self { + media_id: url.media_id(), + server_name: url.server_name(), + filename, + allow_remote: true, + } + } } impl Response { diff --git a/ruma-client-api/src/r0/media/get_content_thumbnail.rs b/ruma-client-api/src/r0/media/get_content_thumbnail.rs index ade29e4a..2c31be9a 100644 --- a/ruma-client-api/src/r0/media/get_content_thumbnail.rs +++ b/ruma-client-api/src/r0/media/get_content_thumbnail.rs @@ -2,7 +2,7 @@ use js_int::UInt; use ruma_api::ruma_api; -use ruma_identifiers::ServerName; +use ruma_identifiers::{MxcUri, ServerName}; use ruma_serde::StringEnum; /// The desired resizing method. @@ -80,6 +80,19 @@ impl<'a> Request<'a> { pub fn new(media_id: &'a str, server_name: &'a ServerName, width: UInt, height: UInt) -> Self { Self { media_id, server_name, method: None, width, height, allow_remote: true } } + + /// Creates a new `Request` with the given url, desired thumbnail width and + /// desired thumbnail height. + pub fn from_url(url: &'a MxcUri, width: UInt, height: UInt) -> Self { + Self { + media_id: url.media_id(), + server_name: url.server_name(), + method: None, + width, + height, + allow_remote: true, + } + } } impl Response {