From a4dcf656f32008bc25b870cf556862ede6431903 Mon Sep 17 00:00:00 2001 From: link2xt Date: Fri, 3 Nov 2023 13:55:07 +0000 Subject: [PATCH] api: add JSON-RPC get_chat_id_by_contact_id API (#4918) --- deltachat-jsonrpc/src/api.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/deltachat-jsonrpc/src/api.rs b/deltachat-jsonrpc/src/api.rs index 9745c42d0..d7999e980 100644 --- a/deltachat-jsonrpc/src/api.rs +++ b/deltachat-jsonrpc/src/api.rs @@ -1391,6 +1391,19 @@ impl CommandApi { // chat // --------------------------------------------- + /// Returns the [`ChatId`] for the 1:1 chat with `contact_id` if it exists. + /// + /// If it does not exist, `None` is returned. + async fn get_chat_id_by_contact_id( + &self, + account_id: u32, + contact_id: u32, + ) -> Result> { + let ctx = self.get_context(account_id).await?; + let chat_id = ChatId::lookup_by_contact(&ctx, ContactId::new(contact_id)).await?; + Ok(chat_id.map(|id| id.to_u32())) + } + /// Returns all message IDs of the given types in a chat. /// Typically used to show a gallery. ///