mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-04 02:09:17 +02:00
make chats objects grow equality operators, probably we rather want to move to "attr" which handles all of this.
This commit is contained in:
parent
194bd82b8c
commit
0aed6355c3
2 changed files with 18 additions and 1 deletions
|
@ -104,6 +104,15 @@ class Chat:
|
|||
self.dc_context = dc_context
|
||||
self.id = chat_id
|
||||
|
||||
def __eq__(self, other_chat):
|
||||
return (
|
||||
self.dc_context == getattr(other_chat, "dc_context", None) and
|
||||
self.id == getattr(other_chat, "id", None)
|
||||
)
|
||||
|
||||
def __ne__(self, other_chat):
|
||||
return not self == other_chat
|
||||
|
||||
def send_text_message(self, msg):
|
||||
""" return ID of the message in this chat.
|
||||
'msg' should be unicode"""
|
||||
|
@ -122,6 +131,11 @@ class Message:
|
|||
def text(self):
|
||||
return ffi_unicode(capi.lib.dc_msg_get_text(self.dc_msg))
|
||||
|
||||
@property
|
||||
def chat(self):
|
||||
chat_id = capi.lib.dc_msg_get_chat_id(self.dc_msg)
|
||||
return Chat(self.dc_context, chat_id)
|
||||
|
||||
|
||||
class Account:
|
||||
def __init__(self, db_path, _logid=None):
|
||||
|
|
|
@ -26,6 +26,8 @@ class TestOfflineAccount:
|
|||
|
||||
chat2 = ac1.create_chat_by_contact(contact1.id)
|
||||
assert chat2.id == chat.id
|
||||
assert chat == chat2
|
||||
assert not (chat != chat2)
|
||||
|
||||
|
||||
class TestOnlineAccount:
|
||||
|
@ -71,7 +73,8 @@ class TestOnlineAccount:
|
|||
assert data1 == chat.id
|
||||
assert data2 == msg_id
|
||||
ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||
assert ev[1] == chat.id
|
||||
assert ev[2] == msg_id
|
||||
msg = ac2.get_message(msg_id)
|
||||
assert msg.text == "msg1"
|
||||
# note that ev[1] aka data1 contains a bogus channel id
|
||||
# probably should just not get passed from the core
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue