mirror of
https://github.com/chatmail/core.git
synced 2026-05-09 09:56:31 +03:00
Add JSON-RPC API to get reactions
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
- BREAKING: jsonrpc:
|
- BREAKING: jsonrpc:
|
||||||
- `get_chatlist_items_by_entries` now takes only chatids instead of `ChatListEntries`
|
- `get_chatlist_items_by_entries` now takes only chatids instead of `ChatListEntries`
|
||||||
- `get_chatlist_entries` now returns `Vec<u32>` of chatids instead of `ChatListEntries`
|
- `get_chatlist_entries` now returns `Vec<u32>` of chatids instead of `ChatListEntries`
|
||||||
|
- JSON-RPC: add API to get reactions outside the message snapshot
|
||||||
### Fixes
|
### Fixes
|
||||||
- Make the bots automatically accept group chat contact requests. #4377
|
- Make the bots automatically accept group chat contact requests. #4377
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ use deltachat::{
|
|||||||
provider::get_provider_info,
|
provider::get_provider_info,
|
||||||
qr,
|
qr,
|
||||||
qr_code_generator::{generate_backup_qr, get_securejoin_qr_svg},
|
qr_code_generator::{generate_backup_qr, get_securejoin_qr_svg},
|
||||||
reaction::send_reaction,
|
reaction::{get_msg_reactions, send_reaction},
|
||||||
securejoin,
|
securejoin,
|
||||||
stock_str::StockMessage,
|
stock_str::StockMessage,
|
||||||
webxdc::StatusUpdateSerial,
|
webxdc::StatusUpdateSerial,
|
||||||
@@ -46,6 +46,7 @@ use types::http::HttpResponse;
|
|||||||
use types::message::MessageData;
|
use types::message::MessageData;
|
||||||
use types::message::MessageObject;
|
use types::message::MessageObject;
|
||||||
use types::provider_info::ProviderInfo;
|
use types::provider_info::ProviderInfo;
|
||||||
|
use types::reactions::JSONRPCReactions;
|
||||||
use types::webxdc::WebxdcMessageInfo;
|
use types::webxdc::WebxdcMessageInfo;
|
||||||
|
|
||||||
use self::events::Event;
|
use self::events::Event;
|
||||||
@@ -1721,6 +1722,21 @@ impl CommandApi {
|
|||||||
Ok(message_id.to_u32())
|
Ok(message_id.to_u32())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns reactions to the message.
|
||||||
|
async fn get_message_reactions(
|
||||||
|
&self,
|
||||||
|
account_id: u32,
|
||||||
|
message_id: u32,
|
||||||
|
) -> Result<Option<JSONRPCReactions>> {
|
||||||
|
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<u32> {
|
async fn send_msg(&self, account_id: u32, chat_id: u32, data: MessageData) -> Result<u32> {
|
||||||
let ctx = self.get_context(account_id).await?;
|
let ctx = self.get_context(account_id).await?;
|
||||||
let mut message = Message::new(if let Some(viewtype) = data.viewtype {
|
let mut message = Message::new(if let Some(viewtype) = data.viewtype {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import TYPE_CHECKING, Union
|
from typing import TYPE_CHECKING, Optional, Union
|
||||||
|
|
||||||
from ._utils import AttrDict
|
from ._utils import AttrDict
|
||||||
from .contact import Contact
|
from .contact import Contact
|
||||||
@@ -35,6 +35,13 @@ class Message:
|
|||||||
snapshot["message"] = self
|
snapshot["message"] = self
|
||||||
return snapshot
|
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:
|
async def mark_seen(self) -> None:
|
||||||
"""Mark the message as seen."""
|
"""Mark the message as seen."""
|
||||||
await self._rpc.markseen_msgs(self.account.id, [self.id])
|
await self._rpc.markseen_msgs(self.account.id, [self.id])
|
||||||
|
|||||||
@@ -239,6 +239,10 @@ async def test_message(acfactory) -> None:
|
|||||||
|
|
||||||
await message.mark_seen()
|
await message.mark_seen()
|
||||||
await message.send_reaction("😎")
|
await message.send_reaction("😎")
|
||||||
|
reactions = await message.get_reactions()
|
||||||
|
assert reactions
|
||||||
|
snapshot = await message.get_snapshot()
|
||||||
|
assert reactions == snapshot.reactions
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio()
|
@pytest.mark.asyncio()
|
||||||
|
|||||||
Reference in New Issue
Block a user