diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index c93497d70..22ad3eed9 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -231,7 +231,7 @@ class Account(object): :returns: a :class:`deltachat.chatting.Chat` object. """ bytes_name = name.encode("utf8") - chat_id = lib.dc_create_group_chat(self._dc_context, verified, bytes_name) + chat_id = lib.dc_create_group_chat(self._dc_context, int(verified), bytes_name) return Chat(self, chat_id) def get_chats(self): @@ -378,6 +378,15 @@ class Account(object): raise ValueError("could not join group") return Chat(self, chat_id) + # + # meta API for start/stop and event based processing + # + + def wait_next_incoming_message(self): + """ wait for and return next incoming message. """ + ev = self._evlogger.get_matching("DC_EVENT_INCOMING_MSG") + return self.get_message_by_id(ev[2]) + def start_threads(self): """ start IMAP/SMTP threads (and configure account if it hasn't happened). diff --git a/python/src/deltachat/chatting.py b/python/src/deltachat/chatting.py index 56e095194..2a5de9b12 100644 --- a/python/src/deltachat/chatting.py +++ b/python/src/deltachat/chatting.py @@ -109,6 +109,13 @@ class Chat(object): """ return not lib.dc_chat_is_unpromoted(self._dc_chat) + def is_verified(self): + """ return True if this chat is a verified group. + + :returns: True if chat is verified, False otherwise. + """ + return lib.dc_chat_is_verified(self._dc_chat) + def get_name(self): """ return name of this chat. diff --git a/python/src/deltachat/message.py b/python/src/deltachat/message.py index bfd5a95b1..735883763 100644 --- a/python/src/deltachat/message.py +++ b/python/src/deltachat/message.py @@ -101,6 +101,10 @@ class Message(object): """ return True if this message is a setup message. """ return lib.dc_msg_is_setupmessage(self._dc_msg) + def is_encrypted(self): + """ return True if this message was encrypted. """ + return bool(lib.dc_msg_get_showpadlock(self._dc_msg)) + def get_message_info(self): """ Return informational text for a single message. diff --git a/python/tests/test_account.py b/python/tests/test_account.py index ff7704c25..e1d2a4f71 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -443,6 +443,7 @@ class TestOnlineAccount: lp.sec("sending text message from ac1 to ac2") msg_out = chat.send_text("message1") + assert not msg_out.is_encrypted() lp.sec("wait for ac2 to receive message") ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED") @@ -460,6 +461,7 @@ class TestOnlineAccount: assert ev[2] > msg_out.id msg_back = ac1.get_message_by_id(ev[2]) assert msg_back.text == "message-back" + assert msg_back.is_encrypted() def test_saved_mime_on_received_message(self, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts() @@ -564,6 +566,38 @@ class TestOnlineAccount: assert ch.id >= 10 wait_securejoin_inviter_progress(ac1, 1000) + def test_qr_verified_group_and_chatting(self, acfactory, lp): + ac1, ac2 = acfactory.get_two_online_accounts() + lp.sec("ac1: create verified-group QR, ac2 scans and joins") + chat1 = ac1.create_group_chat("hello", verified=True) + assert chat1.is_verified() + qr = chat1.get_join_qr() + lp.sec("ac2: start QR-code based join-group protocol") + chat2 = ac2.qr_join_chat(qr) + assert chat2.id >= 10 + wait_securejoin_inviter_progress(ac1, 1000) + + lp.sec("ac2: read member added message") + msg = ac2.wait_next_incoming_message() + assert msg.is_encrypted() + assert "added" in msg.text.lower() + + lp.sec("ac1: send message") + msg_out = chat1.send_text("hello") + assert msg_out.is_encrypted() + + lp.sec("ac2: read message and check it's verified chat") + msg = ac2.wait_next_incoming_message() + assert msg.text == "hello" + assert msg.chat.is_verified() + assert msg.is_encrypted() + + lp.sec("ac2: send message and let ac1 read it") + chat2.send_text("world") + msg = ac1.wait_next_incoming_message() + assert msg.text == "world" + assert msg.is_encrypted() + def test_set_get_profile_image(self, acfactory, data, lp): ac1, ac2 = acfactory.get_two_online_accounts()