Make Message.timestamp a datetime object, and rename to .created_at
This commit is contained in:
@@ -779,7 +779,10 @@ class Client:
|
|||||||
|
|
||||||
for message in messages:
|
for message in messages:
|
||||||
for receipt in read_receipts:
|
for receipt in read_receipts:
|
||||||
if int(receipt["watermark"]) >= int(message.timestamp):
|
if (
|
||||||
|
_util.millis_to_datetime(int(receipt["watermark"]))
|
||||||
|
>= message.created_at
|
||||||
|
):
|
||||||
message.read_by.append(receipt["actor"]["id"])
|
message.read_by.append(receipt["actor"]["id"])
|
||||||
|
|
||||||
return messages
|
return messages
|
||||||
@@ -2721,7 +2724,7 @@ class Client:
|
|||||||
message_object=message,
|
message_object=message,
|
||||||
thread_id=thread_id,
|
thread_id=thread_id,
|
||||||
thread_type=thread_type,
|
thread_type=thread_type,
|
||||||
ts=message.timestamp,
|
ts=_util.datetime_to_millis(message.created_at),
|
||||||
metadata=metadata,
|
metadata=metadata,
|
||||||
msg=m,
|
msg=m,
|
||||||
)
|
)
|
||||||
@@ -2738,7 +2741,7 @@ class Client:
|
|||||||
mid=mid,
|
mid=mid,
|
||||||
tags=metadata.get("tags"),
|
tags=metadata.get("tags"),
|
||||||
author=author_id,
|
author=author_id,
|
||||||
timestamp=ts,
|
created_at=_util.millis_to_datetime(ts),
|
||||||
),
|
),
|
||||||
thread_id=thread_id,
|
thread_id=thread_id,
|
||||||
thread_type=thread_type,
|
thread_type=thread_type,
|
||||||
|
@@ -68,8 +68,8 @@ class Message:
|
|||||||
uid = attr.ib(None, init=False)
|
uid = attr.ib(None, init=False)
|
||||||
#: ID of the sender
|
#: ID of the sender
|
||||||
author = attr.ib(None, init=False)
|
author = attr.ib(None, init=False)
|
||||||
#: Timestamp of when the message was sent
|
#: Datetime of when the message was sent
|
||||||
timestamp = attr.ib(None, init=False)
|
created_at = attr.ib(None, init=False)
|
||||||
#: Whether the message is read
|
#: Whether the message is read
|
||||||
is_read = attr.ib(None, init=False)
|
is_read = attr.ib(None, init=False)
|
||||||
#: A list of people IDs who read the message, works only with :func:`fbchat.Client.fetchThreadMessages`
|
#: A list of people IDs who read the message, works only with :func:`fbchat.Client.fetchThreadMessages`
|
||||||
@@ -220,7 +220,7 @@ class Message:
|
|||||||
rtn.forwarded = cls._get_forwarded_from_tags(tags)
|
rtn.forwarded = cls._get_forwarded_from_tags(tags)
|
||||||
rtn.uid = str(data["message_id"])
|
rtn.uid = str(data["message_id"])
|
||||||
rtn.author = str(data["message_sender"]["id"])
|
rtn.author = str(data["message_sender"]["id"])
|
||||||
rtn.timestamp = data.get("timestamp_precise")
|
rtn.created_at = _util.millis_to_datetime(int(data.get("timestamp_precise")))
|
||||||
rtn.unsent = False
|
rtn.unsent = False
|
||||||
if data.get("unread") is not None:
|
if data.get("unread") is not None:
|
||||||
rtn.is_read = not data["unread"]
|
rtn.is_read = not data["unread"]
|
||||||
@@ -271,7 +271,7 @@ class Message:
|
|||||||
rtn.forwarded = cls._get_forwarded_from_tags(tags)
|
rtn.forwarded = cls._get_forwarded_from_tags(tags)
|
||||||
rtn.uid = metadata.get("messageId")
|
rtn.uid = metadata.get("messageId")
|
||||||
rtn.author = str(metadata.get("actorFbId"))
|
rtn.author = str(metadata.get("actorFbId"))
|
||||||
rtn.timestamp = metadata.get("timestamp")
|
rtn.created_at = _util.millis_to_datetime(metadata.get("timestamp"))
|
||||||
rtn.unsent = False
|
rtn.unsent = False
|
||||||
if data.get("data", {}).get("platform_xmd"):
|
if data.get("data", {}).get("platform_xmd"):
|
||||||
quick_replies = json.loads(data["data"]["platform_xmd"]).get(
|
quick_replies = json.loads(data["data"]["platform_xmd"]).get(
|
||||||
@@ -307,11 +307,11 @@ class Message:
|
|||||||
return rtn
|
return rtn
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _from_pull(cls, data, mid=None, tags=None, author=None, timestamp=None):
|
def _from_pull(cls, data, mid=None, tags=None, author=None, created_at=None):
|
||||||
rtn = cls(text=data.get("body"))
|
rtn = cls(text=data.get("body"))
|
||||||
rtn.uid = mid
|
rtn.uid = mid
|
||||||
rtn.author = author
|
rtn.author = author
|
||||||
rtn.timestamp = timestamp
|
rtn.created_at = created_at
|
||||||
|
|
||||||
if data.get("data") and data["data"].get("prng"):
|
if data.get("data") and data["data"].get("prng"):
|
||||||
try:
|
try:
|
||||||
|
Reference in New Issue
Block a user