From a051adcbc06da31f72019467e4b7a738b1eb277b Mon Sep 17 00:00:00 2001 From: 2FWAH <36737818+2FWAH@users.noreply.github.com> Date: Thu, 22 Feb 2018 17:49:26 +0100 Subject: [PATCH 1/2] Fix ThreadLocation to work with new GraphQL --- fbchat/models.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fbchat/models.py b/fbchat/models.py index ad90ea2..947d943 100644 --- a/fbchat/models.py +++ b/fbchat/models.py @@ -451,10 +451,10 @@ class ThreadType(Enum): class ThreadLocation(Enum): """Used to specify where a thread is located (inbox, pending, archived, other).""" - INBOX = 'inbox' - PENDING = 'pending' - ARCHIVED = 'action:archived' - OTHER = 'other' + INBOX = 'INBOX' + PENDING = 'PENDING' + ARCHIVED = 'ARCHIVED' + OTHER = 'OTHER' class TypingStatus(Enum): """Used to specify whether the user is typing or has stopped typing""" From c04d38cf6360d7d961705a5374554bce5dc4c7e7 Mon Sep 17 00:00:00 2001 From: 2FWAH <36737818+2FWAH@users.noreply.github.com> Date: Thu, 22 Feb 2018 19:53:56 +0100 Subject: [PATCH 2/2] Handle last_message_timestamp Set last_message_timestamp for one to one and group conversations. --- fbchat/graphql.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fbchat/graphql.py b/fbchat/graphql.py index f4ee001..a0b9500 100644 --- a/fbchat/graphql.py +++ b/fbchat/graphql.py @@ -181,6 +181,7 @@ def graphql_to_thread(thread): c_info = get_customization_info(thread) participants = [node['messaging_actor'] for node in thread['all_participants']['nodes']] user = next(p for p in participants if p['id'] == thread['thread_key']['other_user_id']) + last_message_timestamp = thread['last_message']['nodes'][0]['timestamp_precise'] return User( user['id'], @@ -196,7 +197,8 @@ def graphql_to_thread(thread): emoji=c_info.get('emoji'), own_nickname=c_info.get('own_nickname'), photo=user['big_image_src'].get('uri'), - message_count=thread.get('messages_count') + message_count=thread.get('messages_count'), + last_message_timestamp=last_message_timestamp ) else: raise FBchatException('Unknown thread type: {}, with data: {}'.format(thread.get('thread_type'), thread)) @@ -205,6 +207,7 @@ def graphql_to_group(group): if group.get('image') is None: group['image'] = {} c_info = get_customization_info(group) + last_message_timestamp = group['last_message']['nodes'][0]['timestamp_precise'] return Group( group['thread_key']['thread_fbid'], participants=set([node['messaging_actor']['id'] for node in group['all_participants']['nodes']]), @@ -213,7 +216,8 @@ def graphql_to_group(group): emoji=c_info.get('emoji'), photo=group['image'].get('uri'), name=group.get('name'), - message_count=group.get('messages_count') + message_count=group.get('messages_count'), + last_message_timestamp=last_message_timestamp ) def graphql_to_room(room):