Skip to content

Commit

Permalink
feat(sdk): Implement Default for AttachmentInfo types
Browse files Browse the repository at this point in the history
Since all of their fields are optional, it simplifies their construction.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
  • Loading branch information
zecakeh committed Jan 10, 2025
1 parent 4c6c07b commit c4da95d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
2 changes: 2 additions & 0 deletions crates/matrix-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions crates/matrix-sdk/src/attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UInt>,
Expand All @@ -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<Duration>,
Expand All @@ -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<Duration>,
Expand All @@ -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<UInt>,
Expand Down
14 changes: 4 additions & 10 deletions crates/matrix-sdk/tests/integration/room/attachment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down Expand Up @@ -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()));

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()));

Expand Down
8 changes: 3 additions & 5 deletions crates/matrix-sdk/tests/integration/send_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
},
));

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c4da95d

Please sign in to comment.