From c4da95dce3c884a17531849d65647eba13f572ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Fri, 10 Jan 2025 12:07:26 +0100 Subject: [PATCH] feat(sdk): Implement Default for AttachmentInfo types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since all of their fields are optional, it simplifies their construction. Signed-off-by: Kévin Commaille --- crates/matrix-sdk/CHANGELOG.md | 2 ++ crates/matrix-sdk/src/attachment.rs | 8 ++++---- .../tests/integration/room/attachment/mod.rs | 14 ++++---------- crates/matrix-sdk/tests/integration/send_queue.rs | 8 +++----- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/crates/matrix-sdk/CHANGELOG.md b/crates/matrix-sdk/CHANGELOG.md index 3f3ff52cb4..3c0bff7f1a 100644 --- a/crates/matrix-sdk/CHANGELOG.md +++ b/crates/matrix-sdk/CHANGELOG.md @@ -9,6 +9,8 @@ All notable changes to this project will be documented in this file. ### Features - Allow to set and check whether an image is animated via its `ImageInfo`. +- Implement `Default` for `BaseImageInfo`, `BaseVideoIndo`, `BaseAudioInfo` and + `BaseFileInfo`. ### Refactor diff --git a/crates/matrix-sdk/src/attachment.rs b/crates/matrix-sdk/src/attachment.rs index 84e43c499f..c39f00e30a 100644 --- a/crates/matrix-sdk/src/attachment.rs +++ b/crates/matrix-sdk/src/attachment.rs @@ -29,7 +29,7 @@ use ruma::{ }; /// Base metadata about an image. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub struct BaseImageInfo { /// The height of the image in pixels. pub height: Option, @@ -44,7 +44,7 @@ pub struct BaseImageInfo { } /// Base metadata about a video. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub struct BaseVideoInfo { /// The duration of the video. pub duration: Option, @@ -59,7 +59,7 @@ pub struct BaseVideoInfo { } /// Base metadata about an audio clip. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub struct BaseAudioInfo { /// The duration of the audio clip. pub duration: Option, @@ -68,7 +68,7 @@ pub struct BaseAudioInfo { } /// Base metadata about a file. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub struct BaseFileInfo { /// The size of the file in bytes. pub size: Option, diff --git a/crates/matrix-sdk/tests/integration/room/attachment/mod.rs b/crates/matrix-sdk/tests/integration/room/attachment/mod.rs index 2a94c99166..7ef75d97cb 100644 --- a/crates/matrix-sdk/tests/integration/room/attachment/mod.rs +++ b/crates/matrix-sdk/tests/integration/room/attachment/mod.rs @@ -87,9 +87,7 @@ async fn test_room_attachment_send_info() { .info(AttachmentInfo::Image(BaseImageInfo { height: Some(uint!(600)), width: Some(uint!(800)), - size: None, - blurhash: None, - is_animated: None, + ..Default::default() })) .caption(Some("image caption".to_owned())); @@ -140,8 +138,7 @@ async fn test_room_attachment_send_wrong_info() { height: Some(uint!(600)), width: Some(uint!(800)), duration: Some(Duration::from_millis(3600)), - size: None, - blurhash: None, + ..Default::default() })) .caption(Some("image caption".to_owned())); @@ -216,9 +213,7 @@ async fn test_room_attachment_send_info_thumbnail() { .info(AttachmentInfo::Image(BaseImageInfo { height: Some(uint!(600)), width: Some(uint!(800)), - size: None, - blurhash: None, - is_animated: None, + ..Default::default() })); let response = room @@ -336,9 +331,8 @@ async fn test_room_attachment_send_is_animated() { .info(AttachmentInfo::Image(BaseImageInfo { height: Some(uint!(600)), width: Some(uint!(800)), - size: None, - blurhash: None, is_animated: Some(false), + ..Default::default() })) .caption(Some("image caption".to_owned())); diff --git a/crates/matrix-sdk/tests/integration/send_queue.rs b/crates/matrix-sdk/tests/integration/send_queue.rs index 2c96506209..a35fcad9de 100644 --- a/crates/matrix-sdk/tests/integration/send_queue.rs +++ b/crates/matrix-sdk/tests/integration/send_queue.rs @@ -53,8 +53,7 @@ async fn queue_attachment_no_thumbnail(q: &RoomSendQueue) -> (SendHandle, &'stat height: Some(uint!(13)), width: Some(uint!(37)), size: Some(uint!(42)), - blurhash: None, - is_animated: None, + ..Default::default() })); let handle = q .send_attachment(filename, content_type, data, config) @@ -85,8 +84,7 @@ async fn queue_attachment_with_thumbnail(q: &RoomSendQueue) -> (SendHandle, &'st height: Some(uint!(13)), width: Some(uint!(37)), size: Some(uint!(42)), - blurhash: None, - is_animated: None, + ..Default::default() }, )); @@ -1812,8 +1810,8 @@ async fn test_media_uploads() { height: Some(uint!(14)), width: Some(uint!(38)), size: Some(uint!(43)), - blurhash: None, is_animated: Some(false), + ..Default::default() }); let transaction_id = TransactionId::new();