1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-04 18:29:19 +02:00

Merge pull request #395 from deltachat/rcvdtime

add a function to get the receive time of a message
This commit is contained in:
björn petersen 2018-10-16 23:56:21 +02:00 committed by GitHub
commit e8a1d29125
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 2 deletions

View file

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

View file

@ -92,13 +92,23 @@ class Message(object):
@property_with_doc @property_with_doc
def time_sent(self): def time_sent(self):
"""time (utc) when the message was sent. """UTC time when the message was sent.
:returns: naive datetime.datetime() object. :returns: naive datetime.datetime() object.
""" """
ts = lib.dc_msg_get_timestamp(self._dc_msg) ts = lib.dc_msg_get_timestamp(self._dc_msg)
return datetime.utcfromtimestamp(ts) 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 @property
def chat(self): def chat(self):
"""chat this message was posted in. """chat this message was posted in.

View file

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

View file

@ -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. * Get the text of the message.
* If there is no text associated with the message, an empty string is returned. * If there is no text associated with the message, an empty string is returned.

View file

@ -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_viewtype (const dc_msg_t*);
int dc_msg_get_state (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_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_text (const dc_msg_t*);
char* dc_msg_get_file (const dc_msg_t*); char* dc_msg_get_file (const dc_msg_t*);
char* dc_msg_get_filename (const dc_msg_t*); char* dc_msg_get_filename (const dc_msg_t*);