diff --git a/python/src/deltachat/chat.py b/python/src/deltachat/chat.py index bd3890b70..51100712c 100644 --- a/python/src/deltachat/chat.py +++ b/python/src/deltachat/chat.py @@ -82,6 +82,14 @@ class Chat(object): """ return not lib.dc_chat_is_unpromoted(self._dc_chat) + def can_send(self): + """Check if messages can be sent to a give chat. + This is not true eg. for the deaddrop or for the device-talk + + :returns: True if the chat is writable, False otherwise + """ + return lib.dc_chat_can_send(self._dc_chat) + def is_protected(self): """ return True if this chat is a protected chat. diff --git a/python/tests/test_account.py b/python/tests/test_account.py index e65f27ced..f14bbe032 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -1032,6 +1032,16 @@ class TestOnlineAccount: assert msg_in.text == text2 assert ac1.get_config("addr") in [x.addr for x in msg_in.chat.get_contacts()] + def test_no_draft_if_cant_send(self, acfactory): + """Tests that no quote can be set if the user can't send to this chat""" + ac1 = acfactory.get_one_online_account() + device_chat = ac1.get_device_chat() + msg = Message.new_empty(ac1, "text") + device_chat.set_draft(msg) + + assert not device_chat.can_send() + assert device_chat.get_draft() is None + def test_prefer_encrypt(self, acfactory, lp): """Test quorum rule for encryption preference in 1:1 and group chat.""" ac1, ac2, ac3 = acfactory.get_many_online_accounts(3) diff --git a/src/chat.rs b/src/chat.rs index a57cf7988..86bae829a 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -460,6 +460,12 @@ impl ChatId { msg.param.set(Param::File, blob.as_name()); } } + + let chat = Chat::load_from_db(context, self).await?; + if !chat.can_send() { + bail!("Can't set a draft: Can't send"); + } + context .sql .execute(