Commit 90964b68b4

90964b68b4a3d1845d0a528ea421d7c22811adb7

parent: c2566233c3

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-06-23 22:20 UTC
committer: <strk@kbt.io>

fix: show authenticated media download hint

Layout: unified · split

src/render.rs +60 −1
@@ -415,6 +415,15 @@ fn mxc_to_emxc(
415415 Ok(emxc_url.to_string())
416416}
417417
418fn media_download_command(source: &MediaSource) -> Option<String> {
419 match source {
420 MediaSource::Plain(url) => {
421 Some(format!("/matrix media download {} <file>", url.as_str()))
422 }
423 MediaSource::Encrypted(_) => None,
424 }
425}
426
418427impl<C: HasUrlOrFile> Render for C {
419428 type RenderContext = Url;
420429 const TAGS: &'static [&'static str] = &["matrix_media"];
@@ -443,7 +452,16 @@ impl<C: HasUrlOrFile> Render for C {
443452 tags: self.tags(),
444453 };
445454
446 RenderedContent { lines: vec![line] }
455 let mut lines = vec![line];
456
457 if let Some(command) = media_download_command(self.source()) {
458 lines.push(RenderedLine {
459 message: format!("authenticated download: {}", command),
460 tags: self.tags(),
461 });
462 }
463
464 RenderedContent { lines }
447465 }
448466}
449467
@@ -1025,4 +1043,45 @@ mod tests {
10251043 mxc_to_emxc(&mxc_url, &homeserver, &encrypt_info).unwrap()
10261044 );
10271045 }
1046
1047 #[test]
1048 fn test_plain_media_download_command() {
1049 let source = MediaSource::Plain(OwnedMxcUri::from(
1050 "mxc://matrix.org/some-media-id",
1051 ));
1052
1053 assert_eq!(
1054 Some(
1055 "/matrix media download mxc://matrix.org/some-media-id <file>"
1056 .to_owned()
1057 ),
1058 media_download_command(&source)
1059 );
1060 }
1061
1062 #[test]
1063 fn test_encrypted_media_has_no_plain_download_command() {
1064 use std::collections::BTreeMap;
1065
1066 let mut hashes: BTreeMap<String, Base64> = BTreeMap::new();
1067 hashes.insert("sha256".to_string(), Base64::parse("aGFzaA").unwrap());
1068 let encrypt_info = EncryptedFileInit {
1069 key: JsonWebKeyInit {
1070 k: Base64::parse("dGVzdA").unwrap(),
1071 kty: "oct".to_string(),
1072 key_ops: vec![],
1073 ext: true,
1074 alg: "A256CTR".to_string(),
1075 }
1076 .into(),
1077 iv: Base64::parse("aXY").unwrap(),
1078 v: "v2".to_string(),
1079 url: OwnedMxcUri::from("mxc://some-url"),
1080 hashes,
1081 }
1082 .into();
1083 let source = MediaSource::Encrypted(Box::new(encrypt_info));
1084
1085 assert_eq!(None, media_download_command(&source));
1086 }
10281087}