1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-03 17:59:19 +02:00

add msg.time_received and a test

This commit is contained in:
holger krekel 2018-10-16 23:49:03 +02:00
parent fb334b8b05
commit ad84e4578b
3 changed files with 14 additions and 2 deletions

View file

@ -2,7 +2,7 @@ from deltachat import capi, const
from deltachat.capi import ffi
from deltachat.account import Account # noqa
__version__ = "0.7.1"
__version__ = "0.8.0.dev1"
_DC_CALLBACK_MAP = {}

View file

@ -92,13 +92,23 @@ class Message(object):
@property_with_doc
def time_sent(self):
"""time (utc) when the message was sent.
"""UTC time when the message was sent.
:returns: naive datetime.datetime() object.
"""
ts = lib.dc_msg_get_timestamp(self._dc_msg)
return datetime.utcfromtimestamp(ts)
@property_with_doc
def time_received(self):
"""UTC time when the message was received.
:returns: naive datetime.datetime() object or None if message is an outgoing one.
"""
ts = lib.dc_msg_get_received_timestamp(self._dc_msg)
if ts:
return datetime.utcfromtimestamp(ts)
@property
def chat(self):
"""chat this message was posted in.

View file

@ -181,6 +181,7 @@ class TestOfflineAccount:
past1s = datetime.utcnow() - timedelta(seconds=1)
msg = chat.send_text("msg1")
ts = msg.time_sent
assert msg.time_received is None
assert ts.strftime("Y")
assert past1s < ts
contact = msg.get_sender_contact()
@ -259,6 +260,7 @@ class TestOnlineAccount:
assert msg_in in chat2.get_messages()
assert chat2.is_deaddrop()
assert chat2.count_fresh_messages() == 0
assert msg_in.time_received > msg_in.time_sent
lp.sec("create new chat with contact and verify it's proper")
chat2b = ac2.create_chat_by_message(msg_in)