diff --git a/deltachat-jsonrpc/src/api/types/contact.rs b/deltachat-jsonrpc/src/api/types/contact.rs index 54f68dcc3..eb85cf35c 100644 --- a/deltachat-jsonrpc/src/api/types/contact.rs +++ b/deltachat-jsonrpc/src/api/types/contact.rs @@ -19,6 +19,7 @@ pub struct ContactObject { profile_image: Option, // BLOBS name_and_addr: String, is_blocked: bool, + e2ee_avail: bool, /// True if the contact can be added to verified groups. /// @@ -79,6 +80,7 @@ impl ContactObject { profile_image, //BLOBS name_and_addr: contact.get_name_n_addr(), is_blocked: contact.is_blocked(), + e2ee_avail: contact.e2ee_avail(context).await?, is_verified, is_profile_verified, verifier_id, diff --git a/src/contact.rs b/src/contact.rs index 8911f3aa2..89369a12d 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -1402,6 +1402,17 @@ impl Contact { self.status.as_str() } + /// Returns whether end-to-end encryption to the contact is available. + pub async fn e2ee_avail(&self, context: &Context) -> Result { + if self.id == ContactId::SELF { + return Ok(true); + } + let Some(peerstate) = Peerstate::from_addr(context, &self.addr).await? else { + return Ok(false); + }; + Ok(peerstate.peek_key(false).is_some()) + } + /// Returns true if the contact /// can be added to verified chats, /// i.e. has a verified key @@ -2673,6 +2684,8 @@ mod tests { let encrinfo = Contact::get_encrinfo(&alice, contact_bob_id).await?; assert_eq!(encrinfo, "No encryption"); + let contact = Contact::get_by_id(&alice, contact_bob_id).await?; + assert!(!contact.e2ee_avail(&alice).await?); let bob = TestContext::new_bob().await; let chat_alice = bob @@ -2696,6 +2709,8 @@ bob@example.net: CCCB 5AA9 F6E1 141C 9431 65F1 DB18 B18C BCF7 0487" ); + let contact = Contact::get_by_id(&alice, contact_bob_id).await?; + assert!(contact.e2ee_avail(&alice).await?); Ok(()) }