diff --git a/src/chat.rs b/src/chat.rs index b045f781c..7f3bbf886 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -2298,6 +2298,10 @@ impl Chat { async fn get_sync_id(&self, context: &Context) -> Result> { match self.typ { Chattype::Single => { + if self.is_device_talk() { + return Ok(Some(SyncId::Device)); + } + let mut r = None; for contact_id in get_chat_contacts(context, self.id).await? { if contact_id == ContactId::SELF && !self.is_self_talk() { @@ -4750,6 +4754,9 @@ pub(crate) enum SyncId { Grpid(String), /// "Message-ID"-s, from oldest to latest. Used for ad-hoc groups. Msgids(Vec), + + // Special id for device chat. + Device, } /// An action synchronised to other devices. @@ -4811,6 +4818,7 @@ impl Context { ChatId::lookup_by_message(&msg) .with_context(|| format!("No chat found for Message-IDs {msgids:?}"))? } + SyncId::Device => ChatId::get_for_contact(self, ContactId::DEVICE).await?, }; match action { SyncAction::Block => chat_id.block_ex(self, Nosync).await, diff --git a/src/chat/chat_tests.rs b/src/chat/chat_tests.rs index c72e22aab..cdf81c1f5 100644 --- a/src/chat/chat_tests.rs +++ b/src/chat/chat_tests.rs @@ -3059,6 +3059,34 @@ async fn test_sync_visibility() -> Result<()> { Ok(()) } +/// Tests syncing of chat visibility on device message chat. +/// +/// Previously due to a bug pinning "Device Messages" +/// chat resulted in creation of `device@localhost` chat +/// on another device. +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_sync_device_messages_visibility() -> 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 device_chat_id0 = ChatId::get_for_contact(alice0, ContactId::DEVICE).await?; + device_chat_id0 + .set_visibility(alice0, ChatVisibility::Pinned) + .await?; + + sync(alice0, alice1).await; + + let device_chat_id1 = ChatId::get_for_contact(alice1, ContactId::DEVICE).await?; + let device_chat1 = Chat::load_from_db(alice1, device_chat_id1).await?; + assert_eq!(device_chat1.get_visibility(), ChatVisibility::Pinned); + + Ok(()) +} + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_sync_muted() -> Result<()> { let alice0 = &TestContext::new_alice().await;