feat: Send avatars as large as usual images when possible

- Remove limits on the avatar width and height, having a limit on its weight is sufficient.
- Send avatars as large as usual images in protected chats, Outlook servers can't see avatars there
  anyway (they don't allow headers larger than 32k).
This commit is contained in:
iequidoo
2024-08-07 18:42:22 -03:00
parent b74ff278ce
commit ec7f3ec90f
6 changed files with 97 additions and 68 deletions

View File

@@ -1,6 +1,7 @@
use anyhow::Result;
use pretty_assertions::assert_eq;
use crate::blob;
use crate::chat::{self, add_contact_to_chat, Chat, ProtectionStatus};
use crate::chatlist::Chatlist;
use crate::config::Config;
@@ -953,6 +954,37 @@ async fn test_no_unencrypted_name_if_encrypted() -> Result<()> {
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_contact_avatar() -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
enable_verified_oneonone_chats(&[alice]).await;
let bob = &tcm.bob().await;
mark_as_verified(alice, bob).await;
let alice_bob_chat = alice.create_chat(bob).await;
let file = alice.dir.path().join("avatar.jpg");
let bytes = include_bytes!("../../test-data/image/avatar1000x1000.jpg");
tokio::fs::write(&file, bytes).await?;
alice
.set_config(Config::Selfavatar, Some(file.to_str().unwrap()))
.await?;
let sent_msg = alice
.send_text(alice_bob_chat.id, "hello, I have a new avatar")
.await;
bob.recv_msg(&sent_msg).await;
let bob_alice_contact = bob.add_or_lookup_contact(alice).await;
let avatar_path = bob_alice_contact.get_profile_image(bob).await?.unwrap();
tokio::task::block_in_place(move || {
let (_, exif) = blob::image_metadata(&std::fs::File::open(&avatar_path)?)?;
assert!(exif.is_none());
let img = image::open(&avatar_path)?;
assert_eq!(img.width(), 1000);
assert_eq!(img.height(), 1000);
Result::<()>::Ok(())
})?;
Ok(())
}
// ============== Helper Functions ==============
async fn assert_verified(this: &TestContext, other: &TestContext, protected: ProtectionStatus) {