diff --git a/src/config.rs b/src/config.rs index 461b17b25..027ef083a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -779,7 +779,7 @@ mod tests { use super::*; use crate::constants; - use crate::test_utils::{sync, TestContext}; + use crate::test_utils::{sync, TestContext, TestContextManager}; #[test] fn test_to_string() { @@ -1007,6 +1007,65 @@ mod tests { Ok(()) } + /// Sync message mustn't be sent if self-{status,avatar} is changed by a self-sent message. + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + async fn test_no_sync_on_self_sent_msg() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice0 = &tcm.alice().await; + let alice1 = &tcm.alice().await; + for a in [alice0, alice1] { + a.set_config_bool(Config::SyncMsgs, true).await?; + } + + let status = "Synced via usual message"; + alice0.set_config(Config::Selfstatus, Some(status)).await?; + alice0.pop_sent_msg().await; // Sync message + let status1 = "Synced via sync message"; + alice1.set_config(Config::Selfstatus, Some(status1)).await?; + tcm.send_recv(alice0, alice1, "hi Alice!").await; + assert_eq!( + alice1.get_config(Config::Selfstatus).await?, + Some(status.to_string()) + ); + sync(alice1, alice0).await; + assert_eq!( + alice0.get_config(Config::Selfstatus).await?, + Some(status1.to_string()) + ); + + // Need a chat with another contact to send self-avatar. + let bob = &tcm.bob().await; + let a0b_chat_id = tcm.send_recv_accept(bob, alice0, "hi").await.chat_id; + let file = alice0.dir.path().join("avatar.png"); + let bytes = include_bytes!("../test-data/image/avatar64x64.png"); + tokio::fs::write(&file, bytes).await?; + alice0 + .set_config(Config::Selfavatar, Some(file.to_str().unwrap())) + .await?; + alice0.pop_sent_msg().await; // Sync message + let file = alice1.dir.path().join("avatar.jpg"); + let bytes = include_bytes!("../test-data/image/avatar1000x1000.jpg"); + tokio::fs::write(&file, bytes).await?; + alice1 + .set_config(Config::Selfavatar, Some(file.to_str().unwrap())) + .await?; + let sent_msg = alice0.send_text(a0b_chat_id, "hi").await; + alice1.recv_msg(&sent_msg).await; + assert!(alice1 + .get_config(Config::Selfavatar) + .await? + .filter(|path| path.ends_with(".png")) + .is_some()); + sync(alice1, alice0).await; + assert!(alice0 + .get_config(Config::Selfavatar) + .await? + .filter(|path| path.ends_with(".jpg")) + .is_some()); + + Ok(()) + } + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_event_config_synced() -> Result<()> { let alice0 = TestContext::new_alice().await; diff --git a/src/contact.rs b/src/contact.rs index 70db10b15..216a28b7e 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -1537,7 +1537,7 @@ WHERE type=? AND id IN ( /// as profile images can be set only by receiving messages, this should be always the case, however. /// /// For contact SELF, the image is not saved in the contact-database but as Config::Selfavatar; -/// this typically happens if we see message with our own profile image, sent from another device. +/// this typically happens if we see message with our own profile image. pub(crate) async fn set_profile_image( context: &Context, contact_id: ContactId, @@ -1550,7 +1550,7 @@ pub(crate) async fn set_profile_image( if contact_id == ContactId::SELF { if was_encrypted { context - .set_config_internal(Config::Selfavatar, Some(profile_image)) + .set_config_ex(Nosync, Config::Selfavatar, Some(profile_image)) .await?; } else { info!(context, "Do not use unencrypted selfavatar."); @@ -1564,7 +1564,7 @@ pub(crate) async fn set_profile_image( if contact_id == ContactId::SELF { if was_encrypted { context - .set_config_internal(Config::Selfavatar, None) + .set_config_ex(Nosync, Config::Selfavatar, None) .await?; } else { info!(context, "Do not use unencrypted selfavatar deletion."); @@ -1597,7 +1597,7 @@ pub(crate) async fn set_status( if contact_id == ContactId::SELF { if encrypted && has_chat_version { context - .set_config_internal(Config::Selfstatus, Some(&status)) + .set_config_ex(Nosync, Config::Selfstatus, Some(&status)) .await?; } } else {