mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 01:16:31 +03:00
feat: do not convert Viewtype::File to image
This commit is contained in:
@@ -11,7 +11,7 @@ from unittest.mock import MagicMock
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from deltachat_rpc_client import EventType, events
|
from deltachat_rpc_client import EventType, events
|
||||||
from deltachat_rpc_client.const import DownloadState, MessageState
|
from deltachat_rpc_client.const import DownloadState, MessageState, ViewType
|
||||||
from deltachat_rpc_client.pytestplugin import E2EE_INFO_MSGS
|
from deltachat_rpc_client.pytestplugin import E2EE_INFO_MSGS
|
||||||
from deltachat_rpc_client.rpc import JsonRpcError, Rpc
|
from deltachat_rpc_client.rpc import JsonRpcError, Rpc
|
||||||
|
|
||||||
@@ -550,7 +550,7 @@ def test_import_export_online_all(acfactory, tmp_path, data, log) -> None:
|
|||||||
assert len(ac1.get_contacts()) == 1
|
assert len(ac1.get_contacts()) == 1
|
||||||
|
|
||||||
original_image_path = data.get_path("image/avatar64x64.png")
|
original_image_path = data.get_path("image/avatar64x64.png")
|
||||||
chat1.send_file(str(original_image_path))
|
chat1.send_message(file=str(original_image_path), viewtype=ViewType.IMAGE)
|
||||||
|
|
||||||
# Add another 100KB file that ensures that the progress is smooth enough
|
# Add another 100KB file that ensures that the progress is smooth enough
|
||||||
path = tmp_path / "attachment.txt"
|
path = tmp_path / "attachment.txt"
|
||||||
|
|||||||
@@ -421,6 +421,7 @@ async fn test_recode_image_balanced_png() {
|
|||||||
extension: "png",
|
extension: "png",
|
||||||
original_width: 1920,
|
original_width: 1920,
|
||||||
original_height: 1080,
|
original_height: 1080,
|
||||||
|
res_viewtype: Some(Viewtype::File),
|
||||||
compressed_width: 1920,
|
compressed_width: 1920,
|
||||||
compressed_height: 1080,
|
compressed_height: 1080,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@@ -436,6 +437,7 @@ async fn test_recode_image_balanced_png() {
|
|||||||
extension: "png",
|
extension: "png",
|
||||||
original_width: 1920,
|
original_width: 1920,
|
||||||
original_height: 1080,
|
original_height: 1080,
|
||||||
|
res_viewtype: Some(Viewtype::File),
|
||||||
compressed_width: 1920,
|
compressed_width: 1920,
|
||||||
compressed_height: 1080,
|
compressed_height: 1080,
|
||||||
set_draft: true,
|
set_draft: true,
|
||||||
@@ -605,8 +607,10 @@ impl SendImageCheckMediaquality<'_> {
|
|||||||
}
|
}
|
||||||
let sent = alice.send_msg(chat.id, &mut msg).await;
|
let sent = alice.send_msg(chat.id, &mut msg).await;
|
||||||
let alice_msg = alice.get_last_msg().await;
|
let alice_msg = alice.get_last_msg().await;
|
||||||
|
if viewtype != Viewtype::File {
|
||||||
assert_eq!(alice_msg.get_width() as u32, compressed_width);
|
assert_eq!(alice_msg.get_width() as u32, compressed_width);
|
||||||
assert_eq!(alice_msg.get_height() as u32, compressed_height);
|
assert_eq!(alice_msg.get_height() as u32, compressed_height);
|
||||||
|
}
|
||||||
let file_saved = alice
|
let file_saved = alice
|
||||||
.get_blobdir()
|
.get_blobdir()
|
||||||
.join("saved-".to_string() + &alice_msg.get_filename().unwrap());
|
.join("saved-".to_string() + &alice_msg.get_filename().unwrap());
|
||||||
@@ -621,8 +625,10 @@ impl SendImageCheckMediaquality<'_> {
|
|||||||
|
|
||||||
let bob_msg = bob.recv_msg(&sent).await;
|
let bob_msg = bob.recv_msg(&sent).await;
|
||||||
assert_eq!(bob_msg.get_viewtype(), res_viewtype);
|
assert_eq!(bob_msg.get_viewtype(), res_viewtype);
|
||||||
|
if viewtype != Viewtype::File {
|
||||||
assert_eq!(bob_msg.get_width() as u32, compressed_width);
|
assert_eq!(bob_msg.get_width() as u32, compressed_width);
|
||||||
assert_eq!(bob_msg.get_height() as u32, compressed_height);
|
assert_eq!(bob_msg.get_height() as u32, compressed_height);
|
||||||
|
}
|
||||||
let file_saved = bob
|
let file_saved = bob
|
||||||
.get_blobdir()
|
.get_blobdir()
|
||||||
.join("saved-".to_string() + &bob_msg.get_filename().unwrap());
|
.join("saved-".to_string() + &bob_msg.get_filename().unwrap());
|
||||||
|
|||||||
10
src/chat.rs
10
src/chat.rs
@@ -2464,18 +2464,10 @@ async fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<()> {
|
|||||||
.param
|
.param
|
||||||
.get_file_blob(context)?
|
.get_file_blob(context)?
|
||||||
.with_context(|| format!("attachment missing for message of type #{}", msg.viewtype))?;
|
.with_context(|| format!("attachment missing for message of type #{}", msg.viewtype))?;
|
||||||
let mut maybe_image = false;
|
|
||||||
|
|
||||||
if msg.viewtype == Viewtype::File || msg.viewtype == Viewtype::Image {
|
if msg.viewtype == Viewtype::File || msg.viewtype == Viewtype::Image {
|
||||||
// Correct the type, take care not to correct already very special
|
|
||||||
// formats as GIF or VOICE.
|
|
||||||
//
|
|
||||||
// Typical conversions:
|
|
||||||
// - from FILE to AUDIO/VIDEO/IMAGE
|
|
||||||
// - from FILE/IMAGE to GIF */
|
|
||||||
if let Some((better_type, _)) = message::guess_msgtype_from_suffix(msg) {
|
if let Some((better_type, _)) = message::guess_msgtype_from_suffix(msg) {
|
||||||
if better_type == Viewtype::Image {
|
if better_type == Viewtype::Image {
|
||||||
maybe_image = true;
|
|
||||||
} else if better_type != Viewtype::Webxdc
|
} else if better_type != Viewtype::Webxdc
|
||||||
|| context
|
|| context
|
||||||
.ensure_sendable_webxdc_file(&blob.to_abs_path())
|
.ensure_sendable_webxdc_file(&blob.to_abs_path())
|
||||||
@@ -2494,7 +2486,7 @@ async fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<()> {
|
|||||||
if msg.viewtype == Viewtype::Vcard {
|
if msg.viewtype == Viewtype::Vcard {
|
||||||
msg.try_set_vcard(context, &blob.to_abs_path()).await?;
|
msg.try_set_vcard(context, &blob.to_abs_path()).await?;
|
||||||
}
|
}
|
||||||
if msg.viewtype == Viewtype::File && maybe_image || msg.viewtype == Viewtype::Image {
|
if msg.viewtype == Viewtype::Image {
|
||||||
let new_name = blob
|
let new_name = blob
|
||||||
.check_or_recode_image(context, msg.get_filename(), &mut msg.viewtype)
|
.check_or_recode_image(context, msg.get_filename(), &mut msg.viewtype)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user