From 5fd7ef5191db277c2f57f7d50c5ef0b19e6a117b Mon Sep 17 00:00:00 2001 From: Blue Date: Thu, 26 Dec 2019 17:27:15 +0100 Subject: [PATCH 1/2] Add a optional timestamp parameter to mark_as_read and mark_as_unread --- fbchat/_client.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/fbchat/_client.py b/fbchat/_client.py index 0b14591..e451d22 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -1722,41 +1722,46 @@ class Client: j = self._payload_post("/ajax/mercury/delivery_receipts.php", data) return True - def _read_status(self, read, thread_ids): + def _read_status(self, read, thread_ids, timestamp=None): thread_ids = _util.require_list(thread_ids) - data = {"watermarkTimestamp": _util.now(), "shouldSendReadReceipt": "true"} + data = { + "watermarkTimestamp": timestamp or _util.now(), + "shouldSendReadReceipt": "true", + } for thread_id in thread_ids: data["ids[{}]".format(thread_id)] = "true" if read else "false" j = self._payload_post("/ajax/mercury/change_read_status.php", data) - def mark_as_read(self, thread_ids=None): + def mark_as_read(self, thread_ids=None, timestamp=None): """Mark threads as read. All messages inside the specified threads will be marked as read. Args: thread_ids: User/Group IDs to set as read. See :ref:`intro_threads` + timestamp: Timestamp to signal the read cursor at, in milliseconds, default is now() Raises: FBchatException: If request failed """ - self._read_status(True, thread_ids) + self._read_status(True, thread_ids, timestamp) - def mark_as_unread(self, thread_ids=None): + def mark_as_unread(self, thread_ids=None, timestamp=None): """Mark threads as unread. All messages inside the specified threads will be marked as unread. Args: thread_ids: User/Group IDs to set as unread. See :ref:`intro_threads` + timestamp: Timestamp to signal the read cursor at, in milliseconds, default is now() Raises: FBchatException: If request failed """ - self._read_status(False, thread_ids) + self._read_status(False, thread_ids, timestamp) def mark_as_seen(self): """ From 49d5891bf5d2a22ae9c4533c88e673ea96b650d1 Mon Sep 17 00:00:00 2001 From: Blue Date: Wed, 1 Jan 2020 23:24:06 +0100 Subject: [PATCH 2/2] Use datetime instead of raw timestamp --- fbchat/_client.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fbchat/_client.py b/fbchat/_client.py index e451d22..845e941 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -1726,7 +1726,9 @@ class Client: thread_ids = _util.require_list(thread_ids) data = { - "watermarkTimestamp": timestamp or _util.now(), + "watermarkTimestamp": _util.datetime_to_millis(timestamp) + if timestamp + else _util.now(), "shouldSendReadReceipt": "true", } @@ -1742,7 +1744,7 @@ class Client: Args: thread_ids: User/Group IDs to set as read. See :ref:`intro_threads` - timestamp: Timestamp to signal the read cursor at, in milliseconds, default is now() + timestamp: Timestamp (as a Datetime) to signal the read cursor at, default is the current time Raises: FBchatException: If request failed @@ -1756,7 +1758,7 @@ class Client: Args: thread_ids: User/Group IDs to set as unread. See :ref:`intro_threads` - timestamp: Timestamp to signal the read cursor at, in milliseconds, default is now() + timestamp: Timestamp (as a Datetime) to signal the read cursor at, default is the current time Raises: FBchatException: If request failed