Add JSON-RPC API can_send()

This commit is contained in:
link2xt
2023-04-14 20:10:18 +00:00
parent b369a30544
commit 28a13e98a6
4 changed files with 16 additions and 1 deletions

View File

@@ -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.

View File

@@ -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<bool> {
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

View File

@@ -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,

View File

@@ -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()