feat: lookup_key_contact_by_address(): Allow looking up ContactId::SELF without chat id

This doesn't fix anything currently, but let's allow such lookups to avoid future bugs.
This commit is contained in:
iequidoo
2025-08-09 10:03:19 -03:00
committed by iequidoo
parent f4a604dcfb
commit b4e28deed3
2 changed files with 15 additions and 0 deletions

View File

@@ -3819,6 +3819,9 @@ async fn lookup_key_contact_by_address(
chat_id: Option<ChatId>, chat_id: Option<ChatId>,
) -> Result<Option<ContactId>> { ) -> Result<Option<ContactId>> {
if context.is_self_addr(addr).await? { if context.is_self_addr(addr).await? {
if chat_id.is_none() {
return Ok(Some(ContactId::SELF));
}
let is_self_in_chat = context let is_self_in_chat = context
.sql .sql
.exists( .exists(

View File

@@ -5436,3 +5436,15 @@ async fn test_small_unencrypted_group() -> Result<()> {
Ok(()) Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_lookup_key_contact_by_address_self() -> Result<()> {
let mut tcm = TestContextManager::new();
let t = &tcm.alice().await;
let addr = &t.get_config(Config::Addr).await?.unwrap();
assert_eq!(
lookup_key_contact_by_address(t, addr, None).await?,
Some(ContactId::SELF)
);
Ok(())
}