From 576e0949e02f24abd1cc4294ce037fa6dfa8a373 Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Mon, 24 Sep 2018 20:32:04 +0200 Subject: [PATCH 1/2] New `read_by` attribute in `Message` --- fbchat/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fbchat/models.py b/fbchat/models.py index cb4f678..7cc9d65 100644 --- a/fbchat/models.py +++ b/fbchat/models.py @@ -180,6 +180,8 @@ class Message(object): timestamp = None #: Whether the message is read is_read = None + #: A list of pepole IDs who read the message, works only with :func:`fbchat.Client.fetchThreadMessages` + read_by = None #: A dict with user's IDs as keys, and their :class:`MessageReaction` as values reactions = None #: The actual message @@ -201,6 +203,7 @@ class Message(object): attachments = [] self.attachments = attachments self.reactions = {} + self.read_by = [] def __repr__(self): return self.__unicode__() From bad9c7a4b9fe893713e4080badf228bf84cba2f5 Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Mon, 24 Sep 2018 20:33:43 +0200 Subject: [PATCH 2/2] `read_by` handling --- fbchat/client.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 69c858d..f3e629f 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -850,14 +850,22 @@ class Client(object): 'id': thread_id, 'message_limit': limit, 'load_messages': True, - 'load_read_receipts': False, + 'load_read_receipts': True, 'before': before })) if j.get('message_thread') is None: raise FBchatException('Could not fetch thread {}: {}'.format(thread_id, j)) - return list(reversed([graphql_to_message(message) for message in j['message_thread']['messages']['nodes']])) + messages = list(reversed([graphql_to_message(message) for message in j['message_thread']['messages']['nodes']])) + read_receipts = j['message_thread']['read_receipts']['nodes'] + + for message in messages: + for receipt in read_receipts: + if int(receipt['watermark']) >= int(message.timestamp): + message.read_by.append(receipt['actor']['id']) + + return messages def fetchThreadList(self, offset=None, limit=20, thread_location=ThreadLocation.INBOX, before=None): """Get thread list of your facebook account