mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-04 10:19:16 +02:00
introduce message interface
This commit is contained in:
parent
1d11566ad4
commit
194bd82b8c
3 changed files with 32 additions and 7 deletions
|
@ -112,6 +112,17 @@ class Chat:
|
||||||
return capi.lib.dc_send_text_msg(self.dc_context, self.id, msg)
|
return capi.lib.dc_send_text_msg(self.dc_context, self.id, msg)
|
||||||
|
|
||||||
|
|
||||||
|
class Message:
|
||||||
|
def __init__(self, dc_context, msg_id):
|
||||||
|
self.dc_context = dc_context
|
||||||
|
self.id = msg_id
|
||||||
|
self.dc_msg = capi.lib.dc_get_msg(self.dc_context, msg_id)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def text(self):
|
||||||
|
return ffi_unicode(capi.lib.dc_msg_get_text(self.dc_msg))
|
||||||
|
|
||||||
|
|
||||||
class Account:
|
class Account:
|
||||||
def __init__(self, db_path, _logid=None):
|
def __init__(self, db_path, _logid=None):
|
||||||
self.dc_context = ctx = capi.lib.dc_context_new(
|
self.dc_context = ctx = capi.lib.dc_context_new(
|
||||||
|
@ -145,10 +156,19 @@ class Account:
|
||||||
return Contact(self.dc_context, contact_id)
|
return Contact(self.dc_context, contact_id)
|
||||||
|
|
||||||
def create_chat_by_contact(self, contact):
|
def create_chat_by_contact(self, contact):
|
||||||
chat_id = capi.lib.dc_create_chat_by_contact_id(self.dc_context, contact.id)
|
""" return a Chat object, created from the contact.
|
||||||
assert chat_id >= capi.lib.DC_CHAT_ID_LAST_SPECIAL, chat_id
|
|
||||||
|
@param contact: chat_id (int) or contact object.
|
||||||
|
"""
|
||||||
|
contact_id = getattr(contact, "id", contact)
|
||||||
|
assert isinstance(contact_id, int)
|
||||||
|
chat_id = capi.lib.dc_create_chat_by_contact_id(
|
||||||
|
self.dc_context, contact_id)
|
||||||
return Chat(self.dc_context, chat_id)
|
return Chat(self.dc_context, chat_id)
|
||||||
|
|
||||||
|
def get_message(self, msg_id):
|
||||||
|
return Message(self.dc_context, msg_id)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
deltachat.set_context_callback(self.dc_context, self._process_event)
|
deltachat.set_context_callback(self.dc_context, self._process_event)
|
||||||
capi.lib.dc_configure(self.dc_context)
|
capi.lib.dc_configure(self.dc_context)
|
||||||
|
|
|
@ -22,7 +22,10 @@ class TestOfflineAccount:
|
||||||
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")
|
||||||
chat = ac1.create_chat_by_contact(contact1)
|
chat = ac1.create_chat_by_contact(contact1)
|
||||||
assert chat.id
|
assert chat.id >= lib.DC_CHAT_ID_LAST_SPECIAL, chat.id
|
||||||
|
|
||||||
|
chat2 = ac1.create_chat_by_contact(contact1.id)
|
||||||
|
assert chat2.id == chat.id
|
||||||
|
|
||||||
|
|
||||||
class TestOnlineAccount:
|
class TestOnlineAccount:
|
||||||
|
@ -62,11 +65,13 @@ class TestOnlineAccount:
|
||||||
self.wait_successful_IMAP_SMTP_connection(ac2)
|
self.wait_successful_IMAP_SMTP_connection(ac2)
|
||||||
self.wait_configuration_progress(ac1, 1000)
|
self.wait_configuration_progress(ac1, 1000)
|
||||||
self.wait_configuration_progress(ac2, 1000)
|
self.wait_configuration_progress(ac2, 1000)
|
||||||
msgnum = chat.send_text_message("msg1")
|
msg_id = chat.send_text_message("msg1")
|
||||||
ev = ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
|
ev = ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
|
||||||
evt_name, data1, data2 = ev
|
evt_name, data1, data2 = ev
|
||||||
assert data1 == chat.id
|
assert data1 == chat.id
|
||||||
assert data2 == msgnum
|
assert data2 == msg_id
|
||||||
ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
|
ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||||
assert ev[1] == chat.id
|
assert ev[1] == chat.id
|
||||||
assert ev[2] == msgnum
|
assert ev[2] == msg_id
|
||||||
|
msg = ac2.get_message(msg_id)
|
||||||
|
assert msg.text == "msg1"
|
||||||
|
|
|
@ -3,9 +3,9 @@ minversion = 2.0
|
||||||
distshare = {homedir}/.tox/distshare
|
distshare = {homedir}/.tox/distshare
|
||||||
# make sure to update environment list in travis.yml and appveyor.yml
|
# make sure to update environment list in travis.yml and appveyor.yml
|
||||||
envlist =
|
envlist =
|
||||||
lint
|
|
||||||
py27
|
py27
|
||||||
py35
|
py35
|
||||||
|
lint
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
commands = pytest {posargs:tests}
|
commands = pytest {posargs:tests}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue