mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-05 02:29:28 +02:00
add sending timestamp
This commit is contained in:
parent
5fcbc11bf3
commit
68900edfbc
2 changed files with 32 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
||||||
from .cutil import as_dc_charpointer, from_dc_charpointer, iter_array
|
from .cutil import as_dc_charpointer, from_dc_charpointer, iter_array
|
||||||
from .capi import lib, ffi
|
from .capi import lib, ffi
|
||||||
from .types import property_with_doc
|
from .types import property_with_doc
|
||||||
|
from datetime import datetime
|
||||||
import attr
|
import attr
|
||||||
from attr import validators as v
|
from attr import validators as v
|
||||||
|
|
||||||
|
@ -184,9 +185,18 @@ class Message(object):
|
||||||
|
|
||||||
@property_with_doc
|
@property_with_doc
|
||||||
def text(self):
|
def text(self):
|
||||||
"""unicode representation. """
|
"""unicode text of this messages. """
|
||||||
return from_dc_charpointer(lib.dc_msg_get_text(self._dc_msg))
|
return from_dc_charpointer(lib.dc_msg_get_text(self._dc_msg))
|
||||||
|
|
||||||
|
@property_with_doc
|
||||||
|
def time_sent(self):
|
||||||
|
"""time when the message was sent.
|
||||||
|
|
||||||
|
:returns: datetime.datetime() object.
|
||||||
|
"""
|
||||||
|
ts = lib.dc_msg_get_timestamp(self._dc_msg)
|
||||||
|
return datetime.fromtimestamp(ts)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def chat(self):
|
def chat(self):
|
||||||
"""chat this message was posted in.
|
"""chat this message was posted in.
|
||||||
|
@ -196,6 +206,14 @@ class Message(object):
|
||||||
chat_id = lib.dc_msg_get_chat_id(self._dc_msg)
|
chat_id = lib.dc_msg_get_chat_id(self._dc_msg)
|
||||||
return Chat(self._dc_context, chat_id)
|
return Chat(self._dc_context, chat_id)
|
||||||
|
|
||||||
|
def get_sender_contact(self):
|
||||||
|
"""return the contact of who wrote the message.
|
||||||
|
|
||||||
|
:returns: :class:`Contact`` instance
|
||||||
|
"""
|
||||||
|
contact_id = lib.dc_msg_get_from_id(self._dc_msg)
|
||||||
|
return Contact(self._dc_context, contact_id)
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
class MessageState(object):
|
class MessageState(object):
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import pytest
|
import pytest
|
||||||
from deltachat.capi import lib
|
from deltachat.capi import lib
|
||||||
|
from datetime import datetime, timedelta
|
||||||
from conftest import wait_configuration_progress, wait_successful_IMAP_SMTP_connection
|
from conftest import wait_configuration_progress, wait_successful_IMAP_SMTP_connection
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,6 +97,18 @@ class TestOfflineAccount:
|
||||||
assert not msg_state.is_out_delivered()
|
assert not msg_state.is_out_delivered()
|
||||||
assert not msg_state.is_out_mdn_received()
|
assert not msg_state.is_out_mdn_received()
|
||||||
|
|
||||||
|
def test_chat_message_distinctions(self, acfactory):
|
||||||
|
ac1 = acfactory.get_configured_offline_account()
|
||||||
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
||||||
|
chat = ac1.create_chat_by_contact(contact1)
|
||||||
|
past1s = datetime.now() - timedelta(seconds=1)
|
||||||
|
msg = chat.send_text_message("msg1")
|
||||||
|
ts = msg.time_sent
|
||||||
|
assert ts.strftime("Y")
|
||||||
|
assert past1s < ts
|
||||||
|
contact = msg.get_sender_contact()
|
||||||
|
assert contact == ac1.get_self_contact()
|
||||||
|
|
||||||
def test_basic_configure_ok_addr_setting_forbidden(self, acfactory):
|
def test_basic_configure_ok_addr_setting_forbidden(self, acfactory):
|
||||||
ac1 = acfactory.get_configured_offline_account()
|
ac1 = acfactory.get_configured_offline_account()
|
||||||
assert ac1.get_config("mail_pw")
|
assert ac1.get_config("mail_pw")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue