diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index 40d3d9b2..5e39cfa4 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -136,8 +136,8 @@ class Account(object): return Chat(self._dc_context, chat_id) def create_chat_by_message(self, message): - """ create or get an existing 1:1 chat object for the specified sender - of the specified message. + """ create or get an existing chat object for the + the specified message. :param message: messsage id or message instance. :returns: a :class:`Chat` object. @@ -191,6 +191,16 @@ class Account(object): msg_ids = ffi.cast("uint32_t*", ffi.from_buffer(arr)) lib.dc_markseen_msgs(self._dc_context, msg_ids, len(messages)) + def forward_messages(self, messages, chat): + """ Forward list of messages to a chat. + + :param messages: list of :class:`Message` object. + :param chat: :class:`Chat` object. + :returns: None + """ + msg_ids = [msg.id for msg in messages] + lib.dc_forward_msgs(self._dc_context, msg_ids, len(msg_ids), chat.id) + def start(self): """ configure this account object, start receiving events, start IMAP/SMTP threads. """ diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 5cb83f85..9ae20e4b 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -122,6 +122,35 @@ class TestOnlineAccount: assert ac1.get_config("mail_pw") assert ac1.is_configured() + def test_forward_messages(self, acfactory): + ac1 = acfactory.get_live_account() + ac2 = acfactory.get_live_account() + c2 = ac1.create_contact(email=ac2.get_config("addr")) + chat = ac1.create_chat_by_contact(c2) + assert chat.id >= lib.DC_CHAT_ID_LAST_SPECIAL + + self.wait_successful_IMAP_SMTP_connection(ac1) + self.wait_successful_IMAP_SMTP_connection(ac2) + self.wait_configuration_progress(ac1, 1000) + self.wait_configuration_progress(ac2, 1000) + msg_out = chat.send_text_message("message2") + + # wait for other account to receive + ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED") + assert ev[2] == msg_out.id + msg_in = ac2.get_message_by_id(msg_out.id) + assert msg_in.text == "message2" + + # check the message arrived in contact-requests/deaddrop + chat2 = msg_in.chat + assert msg_in in chat2.get_messages() + assert chat2.is_deaddrop() + chat3 = ac2.create_group_chat("newgroup") + assert not chat3.is_promoted() + ac2.forward_messages([msg_in], chat3) + assert chat3.is_promoted() + assert chat3.get_messages() + def test_send_and_receive_message(self, acfactory): ac1 = acfactory.get_live_account() ac2 = acfactory.get_live_account()