Skip to content

Commit 4c37c86

Browse files
committed
misc: Add filename to the thumbnails too so they can reference the original file
1 parent 2e0d7d3 commit 4c37c86

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

crates/matrix-sdk/src/media.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,8 @@ impl Media {
729729
thumbnail: Option<Thumbnail>,
730730
send_progress: SharedObservable<TransmissionProgress>,
731731
) -> Result<(MediaSource, Option<(MediaSource, Box<ThumbnailInfo>)>)> {
732-
let upload_thumbnail = self.upload_thumbnail(thumbnail, send_progress.clone());
732+
let upload_thumbnail =
733+
self.upload_thumbnail(thumbnail, filename.clone(), send_progress.clone());
733734

734735
let upload_attachment = async move {
735736
self.upload(content_type, data, filename, None)
@@ -747,6 +748,7 @@ impl Media {
747748
async fn upload_thumbnail(
748749
&self,
749750
thumbnail: Option<Thumbnail>,
751+
filename: Option<String>,
750752
send_progress: SharedObservable<TransmissionProgress>,
751753
) -> Result<Option<(MediaSource, Box<ThumbnailInfo>)>> {
752754
let Some(thumbnail) = thumbnail else {
@@ -755,8 +757,9 @@ impl Media {
755757

756758
let (data, content_type, thumbnail_info) = thumbnail.into_parts();
757759

760+
let filename = filename.map(|name| format!("thumbnail-{name}"));
758761
let response = self
759-
.upload(&content_type, data, None, None)
762+
.upload(&content_type, data, filename, None)
760763
.with_send_progress_observable(send_progress)
761764
.await?;
762765
let url = response.content_uri;

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ async fn test_room_attachment_send_info() {
104104

105105
mock.mock_authenticated_media_config().ok_default().mount().await;
106106

107+
let filename = "image.jpg";
108+
107109
let expected_event_id = event_id!("$h29iv0s8:example.com");
108110
mock.mock_room_send()
109111
.body_matches_partial_json(json!({
@@ -120,7 +122,15 @@ async fn test_room_attachment_send_info() {
120122

121123
mock.mock_upload()
122124
.expect_mime_type("image/jpeg")
123-
.expect_filename("image.jpg")
125+
.expect_filename(filename)
126+
.ok(mxc_uri!("mxc://example.com/AQwafuaFswefuhsfAFAgsw"))
127+
.mock_once()
128+
.mount()
129+
.await;
130+
131+
mock.mock_upload()
132+
.expect_mime_type("image/jpeg")
133+
.expect_filename("thumbnail-image.jpg")
124134
.ok(mxc_uri!("mxc://example.com/AQwafuaFswefuhsfAFAgsw"))
125135
.mock_once()
126136
.mount()
@@ -136,10 +146,17 @@ async fn test_room_attachment_send_info() {
136146
width: Some(uint!(800)),
137147
..Default::default()
138148
}))
139-
.caption(Some("image caption".to_owned()));
149+
.caption(Some("image caption".to_owned()))
150+
.thumbnail(Some(Thumbnail {
151+
data: "A thumbnail".as_bytes().to_owned(),
152+
content_type: mime::IMAGE_JPEG,
153+
height: uint!(200),
154+
width: uint!(200),
155+
size: uint!(200),
156+
}));
140157

141158
let response = room
142-
.send_attachment("image.jpg", &mime::IMAGE_JPEG, b"Hello world".to_vec(), config)
159+
.send_attachment(filename, &mime::IMAGE_JPEG, b"Hello world".to_vec(), config)
143160
.await
144161
.unwrap();
145162

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,7 +2216,7 @@ async fn test_gallery_uploads() {
22162216
mock_jpeg_upload(
22172217
&mock,
22182218
mxc_uri!("mxc://sdk.rs/thumbnail1"),
2219-
None,
2219+
Some(format!("thumbnail-{filename1}")),
22202220
allow_upload_lock.clone(),
22212221
)
22222222
.mock_once()
@@ -2234,7 +2234,7 @@ async fn test_gallery_uploads() {
22342234
mock_jpeg_upload(
22352235
&mock,
22362236
mxc_uri!("mxc://sdk.rs/thumbnail2"),
2237-
None,
2237+
Some(format!("thumbnail-{filename2}")),
22382238
allow_upload_lock.clone(),
22392239
)
22402240
.mock_once()

0 commit comments

Comments
 (0)