Commit 0f04ee46de

0f04ee46deae5a67618b57fb844486f100715e4d

parent: 10fdcae0e3

Unsigned

Joey@macstudio <johuang@aligntech.com> · 2026-07-12 10:33 UTC
committer: <strk@kbt.io>

fix: render authenticated media download inline

Layout: unified · split

src/render.rs +38 −22
@@ -442,6 +442,16 @@ fn media_download_command(source: &MediaSource) -> Option<String> {
442442 }
443443}
444444
445fn media_download_message<C: HasUrlOrFile>(content: &C) -> Option<String> {
446 media_download_command(content.source()).map(|command| {
447 format!(
448 "attached `{}`, authenticated download: {}",
449 content.body(),
450 command
451 )
452 })
453}
454
445455impl<C: HasUrlOrFile> Render for C {
446456 type RenderContext = Url;
447457 const TAGS: &'static [&'static str] = &["matrix_media"];
@@ -456,34 +466,23 @@ impl<C: HasUrlOrFile> Render for C {
456466 }
457467 .unwrap_or_else(|_| self.resolve_url().to_string());
458468
459 let message = format!(
460 "{color_delimiter}<{color_reset}{}{color_delimiter}>\
461 [{color_reset}{}{color_delimiter}]{color_reset}",
462 self.body(),
463 mxc_url,
464 color_delimiter = Weechat::color("color_delimiter"),
465 color_reset = Weechat::color("reset")
466 );
469 let message = media_download_message(self).unwrap_or_else(|| {
470 format!(
471 "{color_delimiter}<{color_reset}{}{color_delimiter}>\
472 [{color_reset}{}{color_delimiter}]{color_reset}",
473 self.body(),
474 mxc_url,
475 color_delimiter = Weechat::color("color_delimiter"),
476 color_reset = Weechat::color("reset")
477 )
478 });
467479
468480 let line = RenderedLine {
469481 message,
470482 tags: self.tags(),
471483 };
472484
473 let mut lines = vec![line];
474
475 if let Some(command) = media_download_command(self.source()) {
476 lines.push(RenderedLine {
477 message: format!(
478 "{}authenticated download: {}",
479 Weechat::prefix(Prefix::Network),
480 command
481 ),
482 tags: self.tags(),
483 });
484 }
485
486 RenderedContent { lines }
485 RenderedContent { lines: vec![line] }
487486 }
488487}
489488
@@ -1035,6 +1034,23 @@ mod tests {
10351034 );
10361035 }
10371036
1037 #[test]
1038 fn test_plain_media_renders_authenticated_download_message() {
1039 let content = ImageMessageEventContent::plain(
1040 "image.png".to_owned(),
1041 OwnedMxcUri::from("mxc://matrix.org/some-media-id"),
1042 );
1043
1044 assert_eq!(
1045 Some(
1046 "attached `image.png`, authenticated download: /matrix media \
1047 download mxc://matrix.org/some-media-id [file]"
1048 .to_owned()
1049 ),
1050 media_download_message(&content)
1051 );
1052 }
1053
10381054 #[test]
10391055 fn test_encrypted_media_has_no_plain_download_command() {
10401056 use std::collections::BTreeMap;