mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
add account.get_chat_by_id API
This commit is contained in:
@@ -282,9 +282,24 @@ class Account(object):
|
|||||||
return Chat(self, const.DC_CHAT_ID_DEADDROP)
|
return Chat(self, const.DC_CHAT_ID_DEADDROP)
|
||||||
|
|
||||||
def get_message_by_id(self, msg_id):
|
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)
|
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):
|
def mark_seen_messages(self, messages):
|
||||||
""" mark the given set of messages as seen.
|
""" mark the given set of messages as seen.
|
||||||
|
|
||||||
@@ -495,7 +510,8 @@ class Account(object):
|
|||||||
self._imex_events.put(data1)
|
self._imex_events.put(data1)
|
||||||
|
|
||||||
def set_location(self, latitude=0.0, longitude=0.0, accuracy=0.0):
|
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 latitude: float (use 0.0 if not known)
|
||||||
:param longitude: float (use 0.0 if not known)
|
:param longitude: float (use 0.0 if not known)
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ class Chat(object):
|
|||||||
return None
|
return None
|
||||||
return from_dc_charpointer(dc_res)
|
return from_dc_charpointer(dc_res)
|
||||||
|
|
||||||
# ------ group management API ------------------------------
|
# ------ location streaming API ------------------------------
|
||||||
|
|
||||||
def is_sending_locations(self):
|
def is_sending_locations(self):
|
||||||
"""return True if this chat has location-sending enabled currently.
|
"""return True if this chat has location-sending enabled currently.
|
||||||
|
|||||||
@@ -121,6 +121,12 @@ class TestOfflineChat:
|
|||||||
str(chat1)
|
str(chat1)
|
||||||
repr(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):
|
def test_chat_idempotent(self, chat1, ac1):
|
||||||
contact1 = chat1.get_contacts()[0]
|
contact1 = chat1.get_contacts()[0]
|
||||||
chat2 = ac1.create_chat_by_contact(contact1.id)
|
chat2 = ac1.create_chat_by_contact(contact1.id)
|
||||||
|
|||||||
Reference in New Issue
Block a user