mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-04 10:19:16 +02:00
add forward messages API
This commit is contained in:
parent
e777b576cb
commit
cfb05bdf82
2 changed files with 41 additions and 2 deletions
|
@ -136,8 +136,8 @@ class Account(object):
|
||||||
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):
|
||||||
""" create or get an existing 1:1 chat object for the specified sender
|
""" create or get an existing chat object for the
|
||||||
of the specified message.
|
the specified message.
|
||||||
|
|
||||||
:param message: messsage id or message instance.
|
:param message: messsage id or message instance.
|
||||||
:returns: a :class:`Chat` object.
|
:returns: a :class:`Chat` object.
|
||||||
|
@ -191,6 +191,16 @@ class Account(object):
|
||||||
msg_ids = ffi.cast("uint32_t*", ffi.from_buffer(arr))
|
msg_ids = ffi.cast("uint32_t*", ffi.from_buffer(arr))
|
||||||
lib.dc_markseen_msgs(self._dc_context, msg_ids, len(messages))
|
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):
|
def start(self):
|
||||||
""" configure this account object, start receiving events,
|
""" configure this account object, start receiving events,
|
||||||
start IMAP/SMTP threads. """
|
start IMAP/SMTP threads. """
|
||||||
|
|
|
@ -122,6 +122,35 @@ class TestOnlineAccount:
|
||||||
assert ac1.get_config("mail_pw")
|
assert ac1.get_config("mail_pw")
|
||||||
assert ac1.is_configured()
|
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):
|
def test_send_and_receive_message(self, acfactory):
|
||||||
ac1 = acfactory.get_live_account()
|
ac1 = acfactory.get_live_account()
|
||||||
ac2 = acfactory.get_live_account()
|
ac2 = acfactory.get_live_account()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue