mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 23:06:32 +03:00
add chat.is_group() API to help callers avoid having to check with constants
deprecate get_type()
This commit is contained in:
@@ -51,6 +51,16 @@ class Chat(object):
|
|||||||
|
|
||||||
# ------ chat status/metadata API ------------------------------
|
# ------ 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):
|
def is_deaddrop(self):
|
||||||
""" return true if this chat is a deaddrop chat.
|
""" 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))
|
return bool(lib.dc_chat_get_remaining_mute_duration(self.id))
|
||||||
|
|
||||||
def get_type(self):
|
def get_type(self):
|
||||||
""" return type of this chat.
|
""" (deprecated) return type of this chat.
|
||||||
|
|
||||||
:returns: one of const.DC_CHAT_TYPE_*
|
:returns: one of const.DC_CHAT_TYPE_*
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -147,6 +147,9 @@ class TestOfflineChat:
|
|||||||
str(chat1)
|
str(chat1)
|
||||||
repr(chat1)
|
repr(chat1)
|
||||||
|
|
||||||
|
def test_is_group(self, chat1):
|
||||||
|
assert not chat1.is_group()
|
||||||
|
|
||||||
def test_chat_by_id(self, chat1):
|
def test_chat_by_id(self, chat1):
|
||||||
chat2 = chat1.account.get_chat_by_id(chat1.id)
|
chat2 = chat1.account.get_chat_by_id(chat1.id)
|
||||||
assert chat2 == chat1
|
assert chat2 == chat1
|
||||||
@@ -169,6 +172,7 @@ class TestOfflineChat:
|
|||||||
|
|
||||||
def test_add_member_event(self, ac1, make_plugin_recorder):
|
def test_add_member_event(self, ac1, make_plugin_recorder):
|
||||||
chat = ac1.create_group_chat(name="title1")
|
chat = ac1.create_group_chat(name="title1")
|
||||||
|
assert chat.is_group()
|
||||||
# promote the chat
|
# promote the chat
|
||||||
chat.send_text("hello")
|
chat.send_text("hello")
|
||||||
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
||||||
@@ -229,6 +233,7 @@ class TestOfflineChat:
|
|||||||
def test_group_chat_qr(self, acfactory, ac1, verified):
|
def test_group_chat_qr(self, acfactory, ac1, verified):
|
||||||
ac2 = acfactory.get_configured_offline_account()
|
ac2 = acfactory.get_configured_offline_account()
|
||||||
chat = ac1.create_group_chat(name="title1", verified=verified)
|
chat = ac1.create_group_chat(name="title1", verified=verified)
|
||||||
|
assert chat.is_group()
|
||||||
qr = chat.get_join_qr()
|
qr = chat.get_join_qr()
|
||||||
assert ac2.check_qr(qr).is_ask_verifygroup
|
assert ac2.check_qr(qr).is_ask_verifygroup
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user