mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-04 10:19:16 +02:00
add account.get_chats() API
This commit is contained in:
parent
ff9a624714
commit
3015c3c6d7
2 changed files with 22 additions and 0 deletions
|
@ -144,6 +144,22 @@ class Account(object):
|
||||||
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)
|
||||||
|
|
||||||
|
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):
|
def get_message_by_id(self, msg_id):
|
||||||
""" return Message instance. """
|
""" return Message instance. """
|
||||||
return Message(self._dc_context, msg_id)
|
return Message(self._dc_context, msg_id)
|
||||||
|
|
|
@ -54,6 +54,12 @@ class TestOfflineAccount:
|
||||||
assert chat == chat2
|
assert chat == chat2
|
||||||
assert not (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):
|
def test_message(self, acfactory):
|
||||||
ac1 = acfactory.get_offline_account()
|
ac1 = acfactory.get_offline_account()
|
||||||
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue