fix: use dedicated ID for sync messages affecting device chat

Otherwise `device@localhost` chat may appear on the other device.
This commit is contained in:
link2xt
2025-02-17 03:08:47 +00:00
committed by l
parent 130bef8c4a
commit 546d13ef72
2 changed files with 36 additions and 0 deletions

View File

@@ -2298,6 +2298,10 @@ impl Chat {
async fn get_sync_id(&self, context: &Context) -> Result<Option<SyncId>> {
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<String>),
// 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,

View File

@@ -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;