From 20fb7c3c82afb7723fe6d72877f890fbeb9a1b9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= <76261501+zecakeh@users.noreply.github.com> Date: Mon, 5 Apr 2021 11:40:27 +0200 Subject: [PATCH] client-api: Add constructors with MxcUri in media::get_content*::Request --- ruma-client-api/CHANGELOG.md | 8 ++++++++ ruma-client-api/src/r0/media/get_content.rs | 7 ++++++- .../src/r0/media/get_content_as_filename.rs | 12 +++++++++++- .../src/r0/media/get_content_thumbnail.rs | 15 ++++++++++++++- 4 files changed, 39 insertions(+), 3 deletions(-) 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 {