add chat.is_group() API to help callers avoid having to check with constants

deprecate get_type()
This commit is contained in:
holger krekel
2020-03-03 06:00:20 +01:00
parent 6a6a719ab6
commit a665d6de59
2 changed files with 16 additions and 1 deletions

View File

@@ -51,6 +51,16 @@ class Chat(object):
# ------ chat status/metadata API ------------------------------
def is_group(self):
""" return true if this chat is a group chat.
:returns: True if chat is a group-chat, false if it's a contact 1:1 chat.
"""
return lib.dc_chat_get_type(self._dc_chat) in (
const.DC_CHAT_TYPE_GROUP,
const.DC_CHAT_TYPE_VERIFIED_GROUP
)
def is_deaddrop(self):
""" return true if this chat is a deaddrop chat.
@@ -129,7 +139,7 @@ class Chat(object):
return bool(lib.dc_chat_get_remaining_mute_duration(self.id))
def get_type(self):
""" return type of this chat.
""" (deprecated) return type of this chat.
:returns: one of const.DC_CHAT_TYPE_*
"""

View File

@@ -147,6 +147,9 @@ class TestOfflineChat:
str(chat1)
repr(chat1)
def test_is_group(self, chat1):
assert not chat1.is_group()
def test_chat_by_id(self, chat1):
chat2 = chat1.account.get_chat_by_id(chat1.id)
assert chat2 == chat1
@@ -169,6 +172,7 @@ class TestOfflineChat:
def test_add_member_event(self, ac1, make_plugin_recorder):
chat = ac1.create_group_chat(name="title1")
assert chat.is_group()
# promote the chat
chat.send_text("hello")
contact1 = ac1.create_contact("some1@hello.com", name="some1")
@@ -229,6 +233,7 @@ class TestOfflineChat:
def test_group_chat_qr(self, acfactory, ac1, verified):
ac2 = acfactory.get_configured_offline_account()
chat = ac1.create_group_chat(name="title1", verified=verified)
assert chat.is_group()
qr = chat.get_join_qr()
assert ac2.check_qr(qr).is_ask_verifygroup