Skip to content

Commit b349158

Browse files
zecakehpoljar
authored andcommitted
feat(sdk): Allow to set and check whether an image is animated
Using MSC4230. Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
1 parent def4bbb commit b349158

File tree

6 files changed

+75
-1
lines changed

6 files changed

+75
-1
lines changed

bindings/matrix-sdk-ffi/src/ruma.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ pub struct ImageInfo {
570570
pub thumbnail_info: Option<ThumbnailInfo>,
571571
pub thumbnail_source: Option<Arc<MediaSource>>,
572572
pub blurhash: Option<String>,
573+
pub is_animated: Option<bool>,
573574
}
574575

575576
impl From<ImageInfo> for RumaImageInfo {
@@ -582,6 +583,7 @@ impl From<ImageInfo> for RumaImageInfo {
582583
thumbnail_info: value.thumbnail_info.map(Into::into).map(Box::new),
583584
thumbnail_source: value.thumbnail_source.map(|source| (*source).clone().into()),
584585
blurhash: value.blurhash,
586+
is_animated: value.is_animated,
585587
})
586588
}
587589
}
@@ -603,6 +605,7 @@ impl TryFrom<&ImageInfo> for BaseImageInfo {
603605
width: Some(width),
604606
size: Some(size),
605607
blurhash: Some(blurhash),
608+
is_animated: value.is_animated,
606609
})
607610
}
608611
}
@@ -859,6 +862,7 @@ impl TryFrom<&matrix_sdk::ruma::events::room::ImageInfo> for ImageInfo {
859862
.transpose()?
860863
.map(Arc::new),
861864
blurhash: info.blurhash.clone(),
865+
is_animated: info.is_animated,
862866
})
863867
}
864868
}

crates/matrix-sdk/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ All notable changes to this project will be documented in this file.
66

77
## [Unreleased] - ReleaseDate
88

9+
### Features
10+
11+
- Allow to set and check whether an image is animated via its `ImageInfo`.
12+
([#4503](https://github.com/matrix-org/matrix-rust-sdk/pull/4503))
13+
914
### Refactor
1015

1116
- [**breaking**] Move the optional `RequestConfig` argument of the

crates/matrix-sdk/Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,15 @@ mime2ext = "0.1.53"
9696
once_cell = { workspace = true }
9797
pin-project-lite = { workspace = true }
9898
rand = { workspace = true , optional = true }
99-
ruma = { workspace = true, features = ["rand", "unstable-msc2448", "unstable-msc2965", "unstable-msc3930", "unstable-msc3245-v1-compat", "unstable-msc2867"] }
99+
ruma = { workspace = true, features = [
100+
"rand",
101+
"unstable-msc2448",
102+
"unstable-msc2965",
103+
"unstable-msc3930",
104+
"unstable-msc3245-v1-compat",
105+
"unstable-msc2867",
106+
"unstable-msc4230",
107+
] }
100108
serde = { workspace = true }
101109
serde_html_form = { workspace = true }
102110
serde_json = { workspace = true }

crates/matrix-sdk/src/attachment.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ pub struct BaseImageInfo {
3939
pub size: Option<UInt>,
4040
/// The [BlurHash](https://blurha.sh/) for this image.
4141
pub blurhash: Option<String>,
42+
/// Whether this image is animated.
43+
pub is_animated: Option<bool>,
4244
}
4345

4446
/// Base metadata about a video.
@@ -100,6 +102,7 @@ impl From<AttachmentInfo> for ImageInfo {
100102
width: info.width,
101103
size: info.size,
102104
blurhash: info.blurhash,
105+
is_animated: info.is_animated,
103106
}),
104107
_ => ImageInfo::new(),
105108
}

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ async fn test_room_attachment_send_info() {
8989
width: Some(uint!(800)),
9090
size: None,
9191
blurhash: None,
92+
is_animated: None,
9293
}))
9394
.caption(Some("image caption".to_owned()));
9495

@@ -217,6 +218,7 @@ async fn test_room_attachment_send_info_thumbnail() {
217218
width: Some(uint!(800)),
218219
size: None,
219220
blurhash: None,
221+
is_animated: None,
220222
}));
221223

222224
let response = room
@@ -299,3 +301,51 @@ async fn test_room_attachment_send_mentions() {
299301

300302
assert_eq!(expected_event_id, response.event_id);
301303
}
304+
305+
#[async_test]
306+
async fn test_room_attachment_send_is_animated() {
307+
let mock = MatrixMockServer::new().await;
308+
309+
let expected_event_id = event_id!("$h29iv0s8:example.com");
310+
mock.mock_room_send()
311+
.body_matches_partial_json(json!({
312+
"info": {
313+
"mimetype": "image/jpeg",
314+
"h": 600,
315+
"w": 800,
316+
"org.matrix.msc4230.is_animated": false,
317+
}
318+
}))
319+
.ok(expected_event_id)
320+
.mock_once()
321+
.mount()
322+
.await;
323+
324+
mock.mock_upload()
325+
.expect_mime_type("image/jpeg")
326+
.ok(mxc_uri!("mxc://example.com/AQwafuaFswefuhsfAFAgsw"))
327+
.mock_once()
328+
.mount()
329+
.await;
330+
331+
let client = mock.client_builder().build().await;
332+
let room = mock.sync_joined_room(&client, &DEFAULT_TEST_ROOM_ID).await;
333+
mock.mock_room_state_encryption().plain().mount().await;
334+
335+
let config = AttachmentConfig::new()
336+
.info(AttachmentInfo::Image(BaseImageInfo {
337+
height: Some(uint!(600)),
338+
width: Some(uint!(800)),
339+
size: None,
340+
blurhash: None,
341+
is_animated: Some(false),
342+
}))
343+
.caption(Some("image caption".to_owned()));
344+
345+
let response = room
346+
.send_attachment("image.jpg", &mime::IMAGE_JPEG, b"Hello world".to_vec(), config)
347+
.await
348+
.unwrap();
349+
350+
assert_eq!(expected_event_id, response.event_id)
351+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ async fn queue_attachment_no_thumbnail(q: &RoomSendQueue) -> (SendHandle, &'stat
5454
width: Some(uint!(37)),
5555
size: Some(uint!(42)),
5656
blurhash: None,
57+
is_animated: None,
5758
}));
5859
let handle = q
5960
.send_attachment(filename, content_type, data, config)
@@ -85,6 +86,7 @@ async fn queue_attachment_with_thumbnail(q: &RoomSendQueue) -> (SendHandle, &'st
8586
width: Some(uint!(37)),
8687
size: Some(uint!(42)),
8788
blurhash: None,
89+
is_animated: None,
8890
},
8991
));
9092

@@ -1811,6 +1813,7 @@ async fn test_media_uploads() {
18111813
width: Some(uint!(38)),
18121814
size: Some(uint!(43)),
18131815
blurhash: None,
1816+
is_animated: Some(false),
18141817
});
18151818

18161819
let transaction_id = TransactionId::new();
@@ -1871,6 +1874,7 @@ async fn test_media_uploads() {
18711874
assert_eq!(info.size, Some(uint!(43)));
18721875
assert_eq!(info.mimetype.as_deref(), Some("image/jpeg"));
18731876
assert!(info.blurhash.is_none());
1877+
assert_eq!(info.is_animated, Some(false));
18741878

18751879
// Check the data source: it should reference the send queue local storage.
18761880
let local_source = img_content.source;

0 commit comments

Comments
 (0)