mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 07:16:31 +03:00
feat: Look up ContactId::DEVICE by ContactId::DEVICE_ADDR
This commit is contained in:
@@ -752,6 +752,9 @@ impl Contact {
|
|||||||
|
|
||||||
let addr_normalized = addr_normalize(addr);
|
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? {
|
if context.is_self_addr(&addr_normalized).await? {
|
||||||
return Ok(Some(ContactId::SELF));
|
return Ok(Some(ContactId::SELF));
|
||||||
}
|
}
|
||||||
@@ -810,8 +813,11 @@ impl Contact {
|
|||||||
ensure!(!addr.is_empty(), "Can not add_or_lookup empty address");
|
ensure!(!addr.is_empty(), "Can not add_or_lookup empty address");
|
||||||
ensure!(origin != Origin::Unknown, "Missing valid origin");
|
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? {
|
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);
|
let mut name = sanitize_name(name);
|
||||||
|
|||||||
@@ -249,6 +249,10 @@ async fn test_add_or_lookup() {
|
|||||||
assert_eq!(contact.get_name(), stock_str::self_msg(&t).await);
|
assert_eq!(contact.get_name(), stock_str::self_msg(&t).await);
|
||||||
assert_eq!(contact.get_addr(), ""); // we're not configured
|
assert_eq!(contact.get_addr(), ""); // we're not configured
|
||||||
assert!(!contact.is_blocked());
|
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)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
@@ -705,6 +709,11 @@ async fn test_lookup_id_by_addr() {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(id, Some(ContactId::SELF));
|
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)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
|||||||
Reference in New Issue
Block a user