mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
Add JSON-RPC API can_send()
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
- Cleanly terminate deltachat-rpc-server.
|
- Cleanly terminate deltachat-rpc-server.
|
||||||
Also terminate on ctrl-c.
|
Also terminate on ctrl-c.
|
||||||
- Refactorings #4317
|
- Refactorings #4317
|
||||||
|
- Add JSON-RPC API `can_send()`.
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
- Fix python bindings README documentation on installing the bindings from source.
|
- Fix python bindings README documentation on installing the bindings from source.
|
||||||
|
|||||||
@@ -1701,6 +1701,15 @@ impl CommandApi {
|
|||||||
Ok(msg_id)
|
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
|
// functions for the composer
|
||||||
// the composer is the message input field
|
// the composer is the message input field
|
||||||
|
|||||||
@@ -105,6 +105,10 @@ class Chat:
|
|||||||
info = await self._rpc.get_full_chat_by_id(self.account.id, self.id)
|
info = await self._rpc.get_full_chat_by_id(self.account.id, self.id)
|
||||||
return AttrDict(chat=self, **info)
|
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(
|
async def send_message(
|
||||||
self,
|
self,
|
||||||
text: Optional[str] = None,
|
text: Optional[str] = None,
|
||||||
|
|||||||
@@ -147,7 +147,9 @@ async def test_chat(acfactory) -> None:
|
|||||||
assert alice_chat_bob != bob_chat_alice
|
assert alice_chat_bob != bob_chat_alice
|
||||||
assert repr(alice_chat_bob)
|
assert repr(alice_chat_bob)
|
||||||
await alice_chat_bob.delete()
|
await alice_chat_bob.delete()
|
||||||
|
assert not await bob_chat_alice.can_send()
|
||||||
await bob_chat_alice.accept()
|
await bob_chat_alice.accept()
|
||||||
|
assert await bob_chat_alice.can_send()
|
||||||
await bob_chat_alice.block()
|
await bob_chat_alice.block()
|
||||||
bob_chat_alice = await snapshot.sender.create_chat()
|
bob_chat_alice = await snapshot.sender.create_chat()
|
||||||
await bob_chat_alice.mute()
|
await bob_chat_alice.mute()
|
||||||
|
|||||||
Reference in New Issue
Block a user