diff --git a/CHANGELOG.md b/CHANGELOG.md index 500f46ebc..787d93d2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Move format=flowed support to a separate crate #3869 ### API-Changes +- jsonrpc: add python API for webxdc updates #3872 ### Fixes - Do not add an error if the message is encrypted but not signed #3860 diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/message.py b/deltachat-rpc-client/src/deltachat_rpc_client/message.py index 644984fc1..a83da8b96 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/message.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/message.py @@ -1,3 +1,4 @@ +import json from typing import TYPE_CHECKING from ._utils import AttrDict @@ -47,3 +48,19 @@ class Message: async def mark_seen(self) -> None: """Mark the message as seen.""" await self._rpc.markseen_msgs(self.account.id, [self.id]) + + async def send_webxdc_status_update(self, update: dict, description: str) -> None: + """Send a webxdc status update. This message must be a webxdc.""" + await self._rpc.send_webxdc_status_update( + self.account.id, self.id, json.dumps(update), description + ) + + async def get_webxdc_status_updates(self, last_known_serial: int = 0) -> list: + return json.loads( + await self._rpc.get_webxdc_status_updates( + self.account.id, self.id, last_known_serial + ) + ) + + async def get_webxdc_info(self) -> dict: + return await self._rpc.get_webxdc_info(self.account.id, self.id) diff --git a/deltachat-rpc-client/tests/test_webxdc.py b/deltachat-rpc-client/tests/test_webxdc.py new file mode 100644 index 000000000..1bc5f02c1 --- /dev/null +++ b/deltachat-rpc-client/tests/test_webxdc.py @@ -0,0 +1,50 @@ +import pytest + +from deltachat_rpc_client import EventType + + +@pytest.mark.asyncio +async def test_webxdc(acfactory) -> None: + alice, bob = await acfactory.get_online_accounts(2) + + bob_addr = await bob.get_config("addr") + alice_contact_bob = await alice.create_contact(bob_addr, "Bob") + alice_chat_bob = await alice_contact_bob.create_chat() + await alice_chat_bob.send_message( + text="Let's play chess!", file="../test-data/webxdc/chess.xdc" + ) + + while True: + event = await bob.wait_for_event() + if event.type == EventType.INCOMING_MSG: + bob_chat_alice = bob.get_chat_by_id(event.chat_id) + message = bob.get_message_by_id(event.msg_id) + break + + webxdc_info = await message.get_webxdc_info() + assert webxdc_info == { + "document": None, + "icon": "icon.png", + "internetAccess": False, + "name": "Chess Board", + "sourceCodeUrl": None, + "summary": None, + } + + status_updates = await message.get_webxdc_status_updates() + assert status_updates == [] + + await bob_chat_alice.accept() + await message.send_webxdc_status_update({"payload": 42}, "") + await message.send_webxdc_status_update({"payload": "Second update"}, "description") + + status_updates = await message.get_webxdc_status_updates() + assert status_updates == [ + {"payload": 42, "serial": 1, "max_serial": 2}, + {"payload": "Second update", "serial": 2, "max_serial": 2}, + ] + + status_updates = await message.get_webxdc_status_updates(1) + assert status_updates == [ + {"payload": "Second update", "serial": 2, "max_serial": 2}, + ]