diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index 338c947ed..e76a5de2a 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -282,9 +282,24 @@ class Account(object): return Chat(self, const.DC_CHAT_ID_DEADDROP) def get_message_by_id(self, msg_id): - """ return Message instance. """ + """ return Message instance. + :param msg_id: integer id of this message. + :returns: :class:`deltachat.message.Message` instance. + """ return Message.from_db(self, msg_id) + def get_chat_by_id(self, chat_id): + """ return Chat instance. + :param chat_id: integer id of this chat. + :returns: :class:`deltachat.chat.Chat` instance. + :raises: ValueError if chat does not exist. + """ + res = lib.dc_get_chat(self._dc_context, chat_id) + if res == ffi.NULL: + raise ValueError("cannot get chat with id={}".format(chat_id)) + lib.dc_chat_unref(res) + return Chat(self, chat_id) + def mark_seen_messages(self, messages): """ mark the given set of messages as seen. @@ -495,7 +510,8 @@ class Account(object): self._imex_events.put(data1) def set_location(self, latitude=0.0, longitude=0.0, accuracy=0.0): - """set location for this chat. + """set a new location. It effects all chats where we currently + have enabled location streaming. :param latitude: float (use 0.0 if not known) :param longitude: float (use 0.0 if not known) diff --git a/python/src/deltachat/chat.py b/python/src/deltachat/chat.py index dfc68a16c..6fe0d9556 100644 --- a/python/src/deltachat/chat.py +++ b/python/src/deltachat/chat.py @@ -324,7 +324,7 @@ class Chat(object): return None return from_dc_charpointer(dc_res) - # ------ group management API ------------------------------ + # ------ location streaming API ------------------------------ def is_sending_locations(self): """return True if this chat has location-sending enabled currently. diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 41d197b81..bfcff497e 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -121,6 +121,12 @@ class TestOfflineChat: str(chat1) repr(chat1) + def test_chat_by_id(self, chat1): + chat2 = chat1.account.get_chat_by_id(chat1.id) + assert chat2 == chat1 + with pytest.raises(ValueError): + chat1.account.get_chat_by_id(123123) + def test_chat_idempotent(self, chat1, ac1): contact1 = chat1.get_contacts()[0] chat2 = ac1.create_chat_by_contact(contact1.id)