Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Look up ContactId::DEVICE by ContactId::DEVICE_ADDR (#6323) #6342

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7546,6 +7546,27 @@ mod tests {
Ok(())
}

/// Tests that user actions on device chats are synced despite they are different chats.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_sync_device_chats() -> Result<()> {
let alice0 = &TestContext::new_alice().await;
let alice1 = &TestContext::new_alice().await;
for a in [alice0, alice1] {
a.set_config_bool(Config::SyncMsgs, true).await?;
}
let a0dev_chat_id = ChatId::get_for_contact(alice0, ContactId::DEVICE).await?;
let a1dev_chat_id = ChatId::get_for_contact(alice1, ContactId::DEVICE).await?;
let a1dev_chat = Chat::load_from_db(alice1, a1dev_chat_id).await?;
assert_eq!(a1dev_chat.get_visibility(), ChatVisibility::Normal);
a0dev_chat_id
.set_visibility(alice0, ChatVisibility::Pinned)
.await?;
sync(alice0, alice1).await;
let a1dev_chat = Chat::load_from_db(alice1, a1dev_chat_id).await?;
assert_eq!(a1dev_chat.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;
Expand Down
17 changes: 16 additions & 1 deletion src/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,9 @@ impl Contact {

let addr_normalized = addr_normalize(addr);

if addr_normalized == ContactId::DEVICE_ADDR {
return Ok(Some(ContactId::DEVICE));
}
if context.is_self_addr(&addr_normalized).await? {
return Ok(Some(ContactId::SELF));
}
Expand Down Expand Up @@ -800,8 +803,11 @@ impl Contact {
ensure!(!addr.is_empty(), "Can not add_or_lookup empty address");
ensure!(origin != Origin::Unknown, "Missing valid origin");

if addr.as_ref() == ContactId::DEVICE_ADDR {
return Ok((ContactId::DEVICE, Modifier::None));
}
if context.is_self_addr(addr).await? {
return Ok((ContactId::SELF, sth_modified));
return Ok((ContactId::SELF, Modifier::None));
}

let mut name = sanitize_name(name);
Expand Down Expand Up @@ -2228,6 +2234,10 @@ mod tests {
assert_eq!(contact.get_name(), stock_str::self_msg(&t).await);
assert_eq!(contact.get_addr(), ""); // we're not configured
assert!(!contact.is_blocked());

let contact = Contact::get_by_id(&t, ContactId::DEVICE).await.unwrap();
assert_eq!(contact.get_addr(), "device@localhost");
assert!(!contact.is_blocked());
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
Expand Down Expand Up @@ -2684,6 +2694,11 @@ mod tests {
.await
.unwrap();
assert_eq!(id, Some(ContactId::SELF));

let id = Contact::lookup_id_by_addr(&alice.ctx, ContactId::DEVICE_ADDR, Origin::Unknown)
.await
.unwrap();
assert_eq!(id, Some(ContactId::DEVICE));
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
Expand Down
Loading