diff --git a/python/src/deltachat/__init__.py b/python/src/deltachat/__init__.py index c8fe3874..0daae841 100644 --- a/python/src/deltachat/__init__.py +++ b/python/src/deltachat/__init__.py @@ -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 = {} diff --git a/python/src/deltachat/message.py b/python/src/deltachat/message.py index 0ecb6452..000d3aa2 100644 --- a/python/src/deltachat/message.py +++ b/python/src/deltachat/message.py @@ -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. diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 27d33f78..978e4ef3 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -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) diff --git a/src/dc_msg.c b/src/dc_msg.c index 88f6b26c..bc814677 100644 --- a/src/dc_msg.c +++ b/src/dc_msg.c @@ -253,6 +253,27 @@ time_t dc_msg_get_timestamp(const dc_msg_t* msg) } +/** + * Get message receive time. + * The receive time is returned as a unix timestamp in seconds. + * + * To get the sending time, use dc_msg_get_timestamp(). + * + * @memberof dc_msg_t + * @param msg The message object. + * @return Receiving time of the message. + * For outgoing messages, 0 is returned. + */ +time_t dc_msg_get_received_timestamp(const dc_msg_t* msg) +{ + if (msg==NULL || msg->magic!=DC_MSG_MAGIC) { + return 0; + } + + return msg->timestamp_rcvd; +} + + /** * Get the text of the message. * If there is no text associated with the message, an empty string is returned. diff --git a/src/deltachat.h b/src/deltachat.h index f2061e2b..bbf09917 100644 --- a/src/deltachat.h +++ b/src/deltachat.h @@ -494,6 +494,7 @@ uint32_t dc_msg_get_chat_id (const dc_msg_t*); int dc_msg_get_viewtype (const dc_msg_t*); int dc_msg_get_state (const dc_msg_t*); time_t dc_msg_get_timestamp (const dc_msg_t*); +time_t dc_msg_get_received_timestamp(const dc_msg_t*); char* dc_msg_get_text (const dc_msg_t*); char* dc_msg_get_file (const dc_msg_t*); char* dc_msg_get_filename (const dc_msg_t*);