diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index 514884207..ef2b70c83 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -273,6 +273,14 @@ class Account(object): ) return list(iter_array(dc_array, lambda x: Contact(self, x))) + def get_fresh_messages(self): + """ yield all fresh messages from all chats. """ + dc_array = ffi.gc( + lib.dc_get_fresh_msgs(self._dc_context), + lib.dc_array_unref + ) + yield from iter_array(dc_array, lambda x: Message.from_db(self, x)) + def create_chat_by_contact(self, contact): """ create or get an existing 1:1 chat object for the specified contact or contact id. diff --git a/python/tests/test_account.py b/python/tests/test_account.py index a411927b1..4b1948464 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -928,6 +928,13 @@ class TestOnlineAccount: assert msg_back.text == "message-back" assert msg_back.is_encrypted() + # test get_fresh_messages + fresh_msgs = list(ac1.get_fresh_messages()) + assert len(fresh_msgs) == 1 + assert fresh_msgs[0] == msg_back + msg_back.mark_seen() + assert not list(ac1.get_fresh_messages()) + # Test that we do not gossip peer keys in 1-to-1 chat, # as it makes no sense to gossip to peers their own keys. # Gossip is only sent in encrypted messages,