diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index 4af13cd1b..a5404f04e 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -188,12 +188,11 @@ class Account(object): if hasattr(contact, "id"): if contact._dc_context != self._dc_context: raise ValueError("Contact belongs to a different Account") - contact_id = getattr(contact, "id", contact) + contact_id = contact.id else: assert isinstance(contact, int) contact_id = contact - chat_id = lib.dc_create_chat_by_contact_id( - self._dc_context, contact_id) + chat_id = lib.dc_create_chat_by_contact_id(self._dc_context, contact_id) return Chat(self._dc_context, chat_id) def create_chat_by_message(self, message): @@ -203,10 +202,13 @@ class Account(object): :param message: messsage id or message instance. :returns: a :class:`deltachat.chatting.Chat` object. """ - if self._dc_context != message._dc_context: - raise ValueError("Message belongs to a different Account") - msg_id = getattr(message, "id", message) - assert isinstance(msg_id, int) + if hasattr(message, "id"): + if self._dc_context != message._dc_context: + raise ValueError("Message belongs to a different Account") + msg_id = message.id + else: + assert isinstance(message, int) + msg_id = message chat_id = lib.dc_create_chat_by_msg_id(self._dc_context, msg_id) return Chat(self._dc_context, chat_id) diff --git a/python/tests/test_account.py b/python/tests/test_account.py index da4a3c7e1..b1e4aa00b 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -145,6 +145,14 @@ class TestOfflineAccount: assert not msg_state.is_out_delivered() assert not msg_state.is_out_mdn_received() + def test_create_chat_by_mssage_id(self, acfactory): + ac1 = acfactory.get_configured_offline_account() + contact1 = ac1.create_contact("some1@hello.com", name="some1") + chat = ac1.create_chat_by_contact(contact1) + msg = chat.send_text("msg1") + assert chat == ac1.create_chat_by_message(msg) + assert chat == ac1.create_chat_by_message(msg.id) + def test_message_image(self, acfactory, data, lp): ac1 = acfactory.get_configured_offline_account() contact1 = ac1.create_contact("some1@hello.com", name="some1")