diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index 875b097c..833a42fc 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -144,6 +144,22 @@ class Account(object): chat_id = lib.dc_create_chat_by_msg_id(self._dc_context, msg_id) return Chat(self._dc_context, chat_id) + def get_chats(self): + """ return list of chats. + + :returns: a list of :class:`Chat` objects. + """ + dc_chatlist = ffi.gc( + lib.dc_get_chatlist(self._dc_context, 0, ffi.NULL, 0), + lib.dc_chatlist_unref + ) + + chatlist = [] + for i in range(0, lib.dc_chatlist_get_cnt(dc_chatlist)): + chat_id = lib.dc_chatlist_get_chat_id(dc_chatlist, i) + chatlist.append(Chat(self._dc_context, chat_id)) + return chatlist + def get_message_by_id(self, msg_id): """ return Message instance. """ return Message(self._dc_context, msg_id) diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 51aa3933..51b5af01 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -54,6 +54,12 @@ class TestOfflineAccount: assert chat == chat2 assert not (chat != chat2) + for ichat in ac1.get_chats(): + if ichat.id == chat.id: + break + else: + pytest.fail("could not find chat") + def test_message(self, acfactory): ac1 = acfactory.get_offline_account() contact1 = ac1.create_contact("some1@hello.com", name="some1")