Skip to content

Commit c4da95d

Browse files
committed
feat(sdk): Implement Default for AttachmentInfo types
Since all of their fields are optional, it simplifies their construction. Signed-off-by: Kévin Commaille <[email protected]>
1 parent 4c6c07b commit c4da95d

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

crates/matrix-sdk/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ All notable changes to this project will be documented in this file.
99
### Features
1010

1111
- Allow to set and check whether an image is animated via its `ImageInfo`.
12+
- Implement `Default` for `BaseImageInfo`, `BaseVideoIndo`, `BaseAudioInfo` and
13+
`BaseFileInfo`.
1214

1315
### Refactor
1416

crates/matrix-sdk/src/attachment.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use ruma::{
2929
};
3030

3131
/// Base metadata about an image.
32-
#[derive(Debug, Clone)]
32+
#[derive(Debug, Clone, Default)]
3333
pub struct BaseImageInfo {
3434
/// The height of the image in pixels.
3535
pub height: Option<UInt>,
@@ -44,7 +44,7 @@ pub struct BaseImageInfo {
4444
}
4545

4646
/// Base metadata about a video.
47-
#[derive(Debug, Clone)]
47+
#[derive(Debug, Clone, Default)]
4848
pub struct BaseVideoInfo {
4949
/// The duration of the video.
5050
pub duration: Option<Duration>,
@@ -59,7 +59,7 @@ pub struct BaseVideoInfo {
5959
}
6060

6161
/// Base metadata about an audio clip.
62-
#[derive(Debug, Clone)]
62+
#[derive(Debug, Clone, Default)]
6363
pub struct BaseAudioInfo {
6464
/// The duration of the audio clip.
6565
pub duration: Option<Duration>,
@@ -68,7 +68,7 @@ pub struct BaseAudioInfo {
6868
}
6969

7070
/// Base metadata about a file.
71-
#[derive(Debug, Clone)]
71+
#[derive(Debug, Clone, Default)]
7272
pub struct BaseFileInfo {
7373
/// The size of the file in bytes.
7474
pub size: Option<UInt>,

crates/matrix-sdk/tests/integration/room/attachment/mod.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ async fn test_room_attachment_send_info() {
8787
.info(AttachmentInfo::Image(BaseImageInfo {
8888
height: Some(uint!(600)),
8989
width: Some(uint!(800)),
90-
size: None,
91-
blurhash: None,
92-
is_animated: None,
90+
..Default::default()
9391
}))
9492
.caption(Some("image caption".to_owned()));
9593

@@ -140,8 +138,7 @@ async fn test_room_attachment_send_wrong_info() {
140138
height: Some(uint!(600)),
141139
width: Some(uint!(800)),
142140
duration: Some(Duration::from_millis(3600)),
143-
size: None,
144-
blurhash: None,
141+
..Default::default()
145142
}))
146143
.caption(Some("image caption".to_owned()));
147144

@@ -216,9 +213,7 @@ async fn test_room_attachment_send_info_thumbnail() {
216213
.info(AttachmentInfo::Image(BaseImageInfo {
217214
height: Some(uint!(600)),
218215
width: Some(uint!(800)),
219-
size: None,
220-
blurhash: None,
221-
is_animated: None,
216+
..Default::default()
222217
}));
223218

224219
let response = room
@@ -336,9 +331,8 @@ async fn test_room_attachment_send_is_animated() {
336331
.info(AttachmentInfo::Image(BaseImageInfo {
337332
height: Some(uint!(600)),
338333
width: Some(uint!(800)),
339-
size: None,
340-
blurhash: None,
341334
is_animated: Some(false),
335+
..Default::default()
342336
}))
343337
.caption(Some("image caption".to_owned()));
344338

crates/matrix-sdk/tests/integration/send_queue.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ async fn queue_attachment_no_thumbnail(q: &RoomSendQueue) -> (SendHandle, &'stat
5353
height: Some(uint!(13)),
5454
width: Some(uint!(37)),
5555
size: Some(uint!(42)),
56-
blurhash: None,
57-
is_animated: None,
56+
..Default::default()
5857
}));
5958
let handle = q
6059
.send_attachment(filename, content_type, data, config)
@@ -85,8 +84,7 @@ async fn queue_attachment_with_thumbnail(q: &RoomSendQueue) -> (SendHandle, &'st
8584
height: Some(uint!(13)),
8685
width: Some(uint!(37)),
8786
size: Some(uint!(42)),
88-
blurhash: None,
89-
is_animated: None,
87+
..Default::default()
9088
},
9189
));
9290

@@ -1812,8 +1810,8 @@ async fn test_media_uploads() {
18121810
height: Some(uint!(14)),
18131811
width: Some(uint!(38)),
18141812
size: Some(uint!(43)),
1815-
blurhash: None,
18161813
is_animated: Some(false),
1814+
..Default::default()
18171815
});
18181816

18191817
let transaction_id = TransactionId::new();

0 commit comments

Comments
 (0)