diff --git a/deltachat-jsonrpc/src/api.rs b/deltachat-jsonrpc/src/api.rs index 561efd809..6e0535f3d 100644 --- a/deltachat-jsonrpc/src/api.rs +++ b/deltachat-jsonrpc/src/api.rs @@ -23,8 +23,8 @@ use deltachat::ephemeral::Timer; use deltachat::imex; use deltachat::location; use deltachat::message::{ - self, delete_msgs_ex, get_existing_msg_ids, get_msg_read_receipts, markseen_msgs, Message, - MessageState, MsgId, Viewtype, + self, delete_msgs_ex, get_existing_msg_ids, get_msg_read_receipt_count, get_msg_read_receipts, + markseen_msgs, Message, MessageState, MsgId, Viewtype, }; use deltachat::peer_channels::{ leave_webxdc_realtime, send_webxdc_realtime_advertisement, send_webxdc_realtime_data, @@ -1434,6 +1434,18 @@ impl CommandApi { MessageInfo::from_msg_id(&ctx, MsgId::new(message_id)).await } + /// Returns count of read receipts on message. + /// + /// This view count is meant as a feedback measure for the channel owner only. + async fn get_message_read_receipt_count( + &self, + account_id: u32, + message_id: u32, + ) -> Result { + let ctx = self.get_context(account_id).await?; + get_msg_read_receipt_count(&ctx, MsgId::new(message_id)).await + } + /// Returns contacts that sent read receipts and the time of reading. async fn get_message_read_receipts( &self, diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/message.py b/deltachat-rpc-client/src/deltachat_rpc_client/message.py index 6bb5d98f8..9ba1c7cff 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/message.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/message.py @@ -44,6 +44,14 @@ class Message: read_receipts = self._rpc.get_message_read_receipts(self.account.id, self.id) return [AttrDict(read_receipt) for read_receipt in read_receipts] + def get_read_receipt_count(self) -> int: + """ + Returns count of read receipts on message. + + This view count is meant as a feedback measure for the channel owner only. + """ + return self._rpc.get_message_read_receipt_count(self.account.id, self.id) + def get_reactions(self) -> Optional[AttrDict]: """Get message reactions.""" reactions = self._rpc.get_message_reactions(self.account.id, self.id) diff --git a/deltachat-rpc-client/tests/test_something.py b/deltachat-rpc-client/tests/test_something.py index ab466f639..8758dd593 100644 --- a/deltachat-rpc-client/tests/test_something.py +++ b/deltachat-rpc-client/tests/test_something.py @@ -930,6 +930,9 @@ def test_read_receipt(acfactory): assert len(read_receipts) == 1 assert read_receipts[0].contact_id == alice_contact_bob.id + read_receipt_cnt = read_msg.get_read_receipt_count() + assert read_receipt_cnt == 1 + def test_get_http_response(acfactory): alice = acfactory.new_configured_account() diff --git a/src/message.rs b/src/message.rs index afb33f152..82ca488b4 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1506,6 +1506,16 @@ pub async fn get_msg_read_receipts( .await } +/// Returns count of read receipts on message. +/// +/// This view count is meant as a feedback measure for the channel owner only. +pub async fn get_msg_read_receipt_count(context: &Context, msg_id: MsgId) -> Result { + context + .sql + .count("SELECT COUNT(*) FROM msgs_mdns WHERE msg_id=?", (msg_id,)) + .await +} + pub(crate) fn guess_msgtype_from_suffix(msg: &Message) -> Option<(Viewtype, &'static str)> { msg.param .get(Param::Filename)