refactor: Remove Message.set_file() / dc_msg_set_file() and related code (#6558)

Now that we are deduplicating everywhere, we can get rid of some code.

The old python bindings did not get an optional `name` parameter because
they are deprecated anyway, but it would be easy to add it.
This commit is contained in:
Hocuri
2025-02-22 10:47:52 +01:00
committed by GitHub
parent 253331b7fd
commit a49dfeca6e
9 changed files with 77 additions and 108 deletions

View File

@@ -2,6 +2,7 @@ use std::time::Duration;
use super::*;
use crate::message::{Message, Viewtype};
use crate::param::Param;
use crate::sql;
use crate::test_utils::{self, TestContext};
use crate::tools::SystemTime;
@@ -44,20 +45,6 @@ async fn test_lowercase_ext() {
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_as_file_name() {
let t = TestContext::new().await;
let blob = BlobObject::create_and_deduplicate_from_bytes(&t, FILE_BYTES, "foo.txt").unwrap();
assert_eq!(blob.as_file_name(), FILE_DEDUPLICATED);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_as_rel_path() {
let t = TestContext::new().await;
let blob = BlobObject::create_and_deduplicate_from_bytes(&t, FILE_BYTES, "foo.txt").unwrap();
assert_eq!(blob.as_rel_path(), Path::new(FILE_DEDUPLICATED));
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_suffix() {
let t = TestContext::new().await;
@@ -655,6 +642,12 @@ impl SendImageCheckMediaquality<'_> {
alice_msg.save_file(&alice, &file_saved).await?;
check_image_size(file_saved, compressed_width, compressed_height);
if original_width == compressed_width {
assert_extension(&alice, alice_msg, extension).await;
} else {
assert_extension(&alice, alice_msg, "jpg").await;
}
let bob_msg = bob.recv_msg(&sent).await;
assert_eq!(bob_msg.get_viewtype(), Viewtype::Image);
assert_eq!(bob_msg.get_width() as u32, compressed_width);
@@ -673,10 +666,53 @@ impl SendImageCheckMediaquality<'_> {
assert!(exif.is_none());
let img = check_image_size(file_saved, compressed_width, compressed_height);
if original_width == compressed_width {
assert_extension(&bob, bob_msg, extension).await;
} else {
assert_extension(&bob, bob_msg, "jpg").await;
}
Ok(img)
}
}
async fn assert_extension(context: &TestContext, msg: Message, extension: &str) {
assert!(msg
.param
.get(Param::File)
.unwrap()
.ends_with(&format!(".{extension}")));
assert!(msg
.param
.get(Param::Filename)
.unwrap()
.ends_with(&format!(".{extension}")));
assert!(msg
.get_filename()
.unwrap()
.ends_with(&format!(".{extension}")));
assert_eq!(
msg.get_file(context)
.unwrap()
.extension()
.unwrap()
.to_str()
.unwrap(),
extension
);
assert_eq!(
msg.param
.get_blob(Param::File, context)
.await
.unwrap()
.unwrap()
.suffix()
.unwrap(),
extension
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_send_big_gif_as_image() -> Result<()> {
let bytes = include_bytes!("../../test-data/image/screenshot.gif");