Do not allow to save drafts in non-writeable chats, fix #1986 (#1997)

This commit is contained in:
Hocuri
2020-10-19 13:15:48 +02:00
committed by GitHub
parent 3c6d52842e
commit c005f756d6
3 changed files with 24 additions and 0 deletions

View File

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

View File

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