diff --git a/CHANGELOG.md b/CHANGELOG.md index 422f47b8d..714cd3d22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ - Cleanly terminate deltachat-rpc-server. Also terminate on ctrl-c. - Refactorings #4317 - +- Add JSON-RPC API `can_send()`. ### Fixes - Fix python bindings README documentation on installing the bindings from source. diff --git a/deltachat-jsonrpc/src/api/mod.rs b/deltachat-jsonrpc/src/api/mod.rs index e821a5b68..eac81c312 100644 --- a/deltachat-jsonrpc/src/api/mod.rs +++ b/deltachat-jsonrpc/src/api/mod.rs @@ -1701,6 +1701,15 @@ impl CommandApi { Ok(msg_id) } + /// Checks if messages can be sent to a given chat. + async fn can_send(&self, account_id: u32, chat_id: u32) -> Result { + let ctx = self.get_context(account_id).await?; + let chat_id = ChatId::new(chat_id); + let chat = Chat::load_from_db(&ctx, chat_id).await?; + let can_send = chat.can_send(&ctx).await?; + Ok(can_send) + } + // --------------------------------------------- // functions for the composer // the composer is the message input field diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/chat.py b/deltachat-rpc-client/src/deltachat_rpc_client/chat.py index 65063a6f3..a9cfad8ab 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/chat.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/chat.py @@ -105,6 +105,10 @@ class Chat: info = await self._rpc.get_full_chat_by_id(self.account.id, self.id) return AttrDict(chat=self, **info) + async def can_send(self) -> bool: + """Return true if messages can be sent to the chat.""" + return await self._rpc.can_send(self.account.id, self.id) + async def send_message( self, text: Optional[str] = None, diff --git a/deltachat-rpc-client/tests/test_something.py b/deltachat-rpc-client/tests/test_something.py index fc05854d6..ee08791fe 100644 --- a/deltachat-rpc-client/tests/test_something.py +++ b/deltachat-rpc-client/tests/test_something.py @@ -147,7 +147,9 @@ async def test_chat(acfactory) -> None: assert alice_chat_bob != bob_chat_alice assert repr(alice_chat_bob) await alice_chat_bob.delete() + assert not await bob_chat_alice.can_send() await bob_chat_alice.accept() + assert await bob_chat_alice.can_send() await bob_chat_alice.block() bob_chat_alice = await snapshot.sender.create_chat() await bob_chat_alice.mute()