From b4e28deed3e3a3b9e59101f2bd44a3e05db8b4e5 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Sat, 9 Aug 2025 10:03:19 -0300 Subject: [PATCH] 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. --- src/receive_imf.rs | 3 +++ src/receive_imf/receive_imf_tests.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 980fddead..b08821012 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -3819,6 +3819,9 @@ async fn lookup_key_contact_by_address( chat_id: Option, ) -> Result> { if context.is_self_addr(addr).await? { + if chat_id.is_none() { + return Ok(Some(ContactId::SELF)); + } let is_self_in_chat = context .sql .exists( diff --git a/src/receive_imf/receive_imf_tests.rs b/src/receive_imf/receive_imf_tests.rs index 1a65ca808..ef7a31233 100644 --- a/src/receive_imf/receive_imf_tests.rs +++ b/src/receive_imf/receive_imf_tests.rs @@ -5436,3 +5436,15 @@ async fn test_small_unencrypted_group() -> Result<()> { 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(()) +}