diff --git a/CHANGELOG.md b/CHANGELOG.md index d7464eacc..957ff1f93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - BREAKING: jsonrpc: - `get_chatlist_items_by_entries` now takes only chatids instead of `ChatListEntries` - `get_chatlist_entries` now returns `Vec` of chatids instead of `ChatListEntries` +- JSON-RPC: add API to get reactions outside the message snapshot ### Fixes - Make the bots automatically accept group chat contact requests. #4377 diff --git a/deltachat-jsonrpc/src/api/mod.rs b/deltachat-jsonrpc/src/api/mod.rs index 98942a855..6f7c1353a 100644 --- a/deltachat-jsonrpc/src/api/mod.rs +++ b/deltachat-jsonrpc/src/api/mod.rs @@ -24,7 +24,7 @@ use deltachat::{ provider::get_provider_info, qr, qr_code_generator::{generate_backup_qr, get_securejoin_qr_svg}, - reaction::send_reaction, + reaction::{get_msg_reactions, send_reaction}, securejoin, stock_str::StockMessage, webxdc::StatusUpdateSerial, @@ -46,6 +46,7 @@ use types::http::HttpResponse; use types::message::MessageData; use types::message::MessageObject; use types::provider_info::ProviderInfo; +use types::reactions::JSONRPCReactions; use types::webxdc::WebxdcMessageInfo; use self::events::Event; @@ -1721,6 +1722,21 @@ impl CommandApi { Ok(message_id.to_u32()) } + /// Returns reactions to the message. + async fn get_message_reactions( + &self, + account_id: u32, + message_id: u32, + ) -> Result> { + let ctx = self.get_context(account_id).await?; + let reactions = get_msg_reactions(&ctx, MsgId::new(message_id)).await?; + if reactions.is_empty() { + Ok(None) + } else { + Ok(Some(reactions.into())) + } + } + async fn send_msg(&self, account_id: u32, chat_id: u32, data: MessageData) -> Result { let ctx = self.get_context(account_id).await?; let mut message = Message::new(if let Some(viewtype) = data.viewtype { diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/message.py b/deltachat-rpc-client/src/deltachat_rpc_client/message.py index 5ec30961a..38a0b11f7 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/message.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/message.py @@ -1,6 +1,6 @@ import json from dataclasses import dataclass -from typing import TYPE_CHECKING, Union +from typing import TYPE_CHECKING, Optional, Union from ._utils import AttrDict from .contact import Contact @@ -35,6 +35,13 @@ class Message: snapshot["message"] = self return snapshot + async def get_reactions(self) -> Optional[AttrDict]: + """Get message reactions.""" + reactions = await self._rpc.get_message_reactions(self.account.id, self.id) + if reactions: + return AttrDict(reactions) + return None + async def mark_seen(self) -> None: """Mark the message as seen.""" await self._rpc.markseen_msgs(self.account.id, [self.id]) diff --git a/deltachat-rpc-client/tests/test_something.py b/deltachat-rpc-client/tests/test_something.py index d17c28a16..20f7acaae 100644 --- a/deltachat-rpc-client/tests/test_something.py +++ b/deltachat-rpc-client/tests/test_something.py @@ -239,6 +239,10 @@ async def test_message(acfactory) -> None: await message.mark_seen() await message.send_reaction("😎") + reactions = await message.get_reactions() + assert reactions + snapshot = await message.get_snapshot() + assert reactions == snapshot.reactions @pytest.mark.asyncio()