mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
fix create_chat_by_message to work according to docs
This commit is contained in:
@@ -188,12 +188,11 @@ class Account(object):
|
|||||||
if hasattr(contact, "id"):
|
if hasattr(contact, "id"):
|
||||||
if contact._dc_context != self._dc_context:
|
if contact._dc_context != self._dc_context:
|
||||||
raise ValueError("Contact belongs to a different Account")
|
raise ValueError("Contact belongs to a different Account")
|
||||||
contact_id = getattr(contact, "id", contact)
|
contact_id = contact.id
|
||||||
else:
|
else:
|
||||||
assert isinstance(contact, int)
|
assert isinstance(contact, int)
|
||||||
contact_id = contact
|
contact_id = contact
|
||||||
chat_id = lib.dc_create_chat_by_contact_id(
|
chat_id = lib.dc_create_chat_by_contact_id(self._dc_context, contact_id)
|
||||||
self._dc_context, contact_id)
|
|
||||||
return Chat(self._dc_context, chat_id)
|
return Chat(self._dc_context, chat_id)
|
||||||
|
|
||||||
def create_chat_by_message(self, message):
|
def create_chat_by_message(self, message):
|
||||||
@@ -203,10 +202,13 @@ class Account(object):
|
|||||||
:param message: messsage id or message instance.
|
:param message: messsage id or message instance.
|
||||||
:returns: a :class:`deltachat.chatting.Chat` object.
|
:returns: a :class:`deltachat.chatting.Chat` object.
|
||||||
"""
|
"""
|
||||||
if self._dc_context != message._dc_context:
|
if hasattr(message, "id"):
|
||||||
raise ValueError("Message belongs to a different Account")
|
if self._dc_context != message._dc_context:
|
||||||
msg_id = getattr(message, "id", message)
|
raise ValueError("Message belongs to a different Account")
|
||||||
assert isinstance(msg_id, int)
|
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)
|
chat_id = lib.dc_create_chat_by_msg_id(self._dc_context, msg_id)
|
||||||
return Chat(self._dc_context, chat_id)
|
return Chat(self._dc_context, chat_id)
|
||||||
|
|
||||||
|
|||||||
@@ -145,6 +145,14 @@ class TestOfflineAccount:
|
|||||||
assert not msg_state.is_out_delivered()
|
assert not msg_state.is_out_delivered()
|
||||||
assert not msg_state.is_out_mdn_received()
|
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):
|
def test_message_image(self, acfactory, data, lp):
|
||||||
ac1 = acfactory.get_configured_offline_account()
|
ac1 = acfactory.get_configured_offline_account()
|
||||||
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
||||||
|
|||||||
Reference in New Issue
Block a user