From fb8b9f60cea1a0ffd2de57d647c9c1947fa472b3 Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Thu, 11 May 2023 20:34:51 +0200 Subject: [PATCH] api: jsonrpc: new `MessageReadReceipt` type and `get_message_read_receipts(account_id, message_id)` jsonrpc method --- deltachat-jsonrpc/src/api/mod.rs | 22 ++++++++++++++++++++-- deltachat-jsonrpc/src/api/types/message.rs | 7 +++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/deltachat-jsonrpc/src/api/mod.rs b/deltachat-jsonrpc/src/api/mod.rs index 825925378..b71718299 100644 --- a/deltachat-jsonrpc/src/api/mod.rs +++ b/deltachat-jsonrpc/src/api/mod.rs @@ -4,6 +4,7 @@ use std::{collections::HashMap, str::FromStr}; use anyhow::{anyhow, bail, ensure, Context, Result}; pub use deltachat::accounts::Accounts; +use deltachat::message::get_msg_read_receipts; use deltachat::qr::Qr; use deltachat::{ chat::{ @@ -43,8 +44,7 @@ use types::chat::FullChat; use types::contact::ContactObject; use types::events::Event; use types::http::HttpResponse; -use types::message::MessageData; -use types::message::MessageObject; +use types::message::{MessageData, MessageObject, MessageReadReceipt}; use types::provider_info::ProviderInfo; use types::reactions::JSONRPCReactions; use types::webxdc::WebxdcMessageInfo; @@ -1118,6 +1118,24 @@ impl CommandApi { get_msg_info(&ctx, MsgId::new(message_id)).await } + /// Returns contacts that sent read receipts and the time of reading. + async fn get_message_read_receipts( + &self, + account_id: u32, + message_id: u32, + ) -> Result> { + let ctx = self.get_context(account_id).await?; + let receipts = get_msg_read_receipts(&ctx, MsgId::new(message_id)) + .await? + .iter() + .map(|(contact_id, ts)| MessageReadReceipt { + contact_id: contact_id.to_u32(), + timestamp: *ts, + }) + .collect(); + Ok(receipts) + } + /// Asks the core to start downloading a message fully. /// This function is typically called when the user hits the "Download" button /// that is shown by the UI in case `download_state` is `'Available'` or `'Failure'` diff --git a/deltachat-jsonrpc/src/api/types/message.rs b/deltachat-jsonrpc/src/api/types/message.rs index 13cb3cbd4..d4baf7721 100644 --- a/deltachat-jsonrpc/src/api/types/message.rs +++ b/deltachat-jsonrpc/src/api/types/message.rs @@ -536,3 +536,10 @@ pub struct MessageData { pub override_sender_name: Option, pub quoted_message_id: Option, } + +#[derive(Serialize, TypeDef)] +#[serde(rename_all = "camelCase")] +pub struct MessageReadReceipt { + pub contact_id: u32, + pub timestamp: i64, +}