From 934ca6a7d72443d230c2ccf3fb92813d047427a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asiel=20D=C3=ADaz=20Ben=C3=ADtez?= Date: Sun, 22 Oct 2023 09:14:08 -0400 Subject: [PATCH] api: add send_draft() to JSON-RPC API (#4839) --- deltachat-jsonrpc/src/api/mod.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/deltachat-jsonrpc/src/api/mod.rs b/deltachat-jsonrpc/src/api/mod.rs index bcdc642f0..580634cf5 100644 --- a/deltachat-jsonrpc/src/api/mod.rs +++ b/deltachat-jsonrpc/src/api/mod.rs @@ -2053,6 +2053,23 @@ impl CommandApi { ChatId::new(chat_id).set_draft(&ctx, Some(&mut draft)).await } + + // send the chat's current set draft + async fn misc_send_draft(&self, account_id: u32, chat_id: u32) -> Result { + let ctx = self.get_context(account_id).await?; + if let Some(draft) = ChatId::new(chat_id).get_draft(&ctx).await? { + let mut draft = draft; + let msg_id = chat::send_msg(&ctx, ChatId::new(chat_id), &mut draft) + .await? + .to_u32(); + Ok(msg_id) + } else { + Err(anyhow!( + "chat with id {} doesn't have draft message", + chat_id + )) + } + } } // Helper functions (to prevent code duplication)