fix: Decide on filename used for sending depending on the original Viewtype

If a user attaches an image as `File`, we should send the original filename. And vice versa, if it's
`Image` originally, we mustn't reveal the filename.

The filename used for sending is now also saved to the db, so all the sender's devices will display
the same filename in the message info.
This commit is contained in:
iequidoo
2025-07-08 06:22:28 -03:00
committed by iequidoo
parent acba27a328
commit 75b7bea78f
4 changed files with 64 additions and 80 deletions

View File

@@ -1962,12 +1962,7 @@ async fn test_sticker(
let msg = bob.recv_msg(&sent_msg).await;
assert_eq!(msg.chat_id, bob_chat.id);
assert_eq!(msg.get_viewtype(), res_viewtype);
let msg_filename = msg.get_filename().unwrap();
match res_viewtype {
Viewtype::Sticker => assert_eq!(msg_filename, filename),
Viewtype::Image => assert!(msg_filename.starts_with("image_")),
_ => panic!("Not implemented"),
}
assert_eq!(msg.get_filename().unwrap(), filename);
assert_eq!(msg.get_width(), w);
assert_eq!(msg.get_height(), h);
assert!(msg.get_filebytes(&bob).await?.unwrap() > 250);
@@ -3739,9 +3734,11 @@ async fn test_nonimage_with_png_ext() -> Result<()> {
let sent_msg = alice.send_msg(alice_chat.get_id(), &mut msg).await;
assert_eq!(msg.viewtype, Viewtype::File);
assert_eq!(msg.get_filemime().unwrap(), "application/octet-stream");
assert!(!msg.get_filename().unwrap().contains("screenshot"));
let msg_bob = bob.recv_msg(&sent_msg).await;
assert_eq!(msg_bob.viewtype, Viewtype::File);
assert_eq!(msg_bob.get_filemime().unwrap(), "application/octet-stream");
assert!(!msg_bob.get_filename().unwrap().contains("screenshot"));
Ok(())
}