Skip to content

Commit

Permalink
fix: Look up ContactId::DEVICE by ContactId::DEVICE_ADDR (#6323)
Browse files Browse the repository at this point in the history
At least this fixes the bug when the device chat is e.g. archived by the user on one device, but
this user action is synchronized as archiving a chat with a new contact having the address
"device@localhost" on another device. Not sure if we want to sinchronize actions on the device chats
at all because they are chats with different devices, but maybe that simplifies UX, so let's discuss
it first and maybe disable synchronization in a separate commit.
  • Loading branch information
iequidoo committed Dec 15, 2024
1 parent b74ff27 commit 6e65cac
Showing 1 changed file with 16 additions and 1 deletion.
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

0 comments on commit 6e65cac

Please sign in to comment.