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(()) +}