From 9e32cf17a44a6d5ff6b9bb75d6c0aa7da9f262f5 Mon Sep 17 00:00:00 2001 From: Ritvik Annam Date: Thu, 10 Aug 2017 00:53:06 -0500 Subject: [PATCH 1/2] fetchThreadList now pulls message_count --- fbchat/client.py | 3 ++- fbchat/models.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index bde5f89..79a5083 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -740,9 +740,10 @@ class Client(object): if k['thread_type'] == 1: if k['other_user_fbid'] not in participants: raise Exception('A thread was not in participants: {}'.format(j['payload'])) + participants[k['other_user_fbid']].message_count = k['message_count'] entries.append(participants[k['other_user_fbid']]) elif k['thread_type'] == 2: - entries.append(Group(k['thread_fbid'], participants=set([p.strip('fbid:') for p in k['participants']]), photo=k['image_src'], name=k['name'])) + entries.append(Group(k['thread_fbid'], participants=set([p.strip('fbid:') for p in k['participants']]), photo=k['image_src'], name=k['name'], message_count=k['message_count'])) else: raise Exception('A thread had an unknown thread type: {}'.format(k)) diff --git a/fbchat/models.py b/fbchat/models.py index 24b508d..3f9fd77 100644 --- a/fbchat/models.py +++ b/fbchat/models.py @@ -15,14 +15,16 @@ class Thread(object): name = str #: Timestamp of last message last_message_timestamp = str - - def __init__(self, _type, uid, photo=None, name=None, last_message_timestamp=None): + #: Number of messages in the thread + message_count = int + def __init__(self, _type, uid, photo=None, name=None, last_message_timestamp=None, message_count=None): """Represents a Facebook thread""" self.uid = str(uid) self.type = _type self.photo = photo self.name = name self.last_message_timestamp = last_message_timestamp + self.message_count = message_count def __repr__(self): return self.__unicode__() From 44cf08bdfdbd7f07b0f1efc3dce69f2fa3d93a4e Mon Sep 17 00:00:00 2001 From: Ritvik Annam Date: Thu, 10 Aug 2017 01:10:39 -0500 Subject: [PATCH 2/2] fetchThreadInfo now pulls message_count --- fbchat/client.py | 2 +- fbchat/graphql.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 79a5083..3c40cc7 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -638,7 +638,7 @@ class Client(object): })) j = self.graphql_requests(*queries) - + for i, entry in enumerate(j): if entry.get('message_thread') is None: # If you don't have an existing thread with this person, attempt to retrieve user data anyways diff --git a/fbchat/graphql.py b/fbchat/graphql.py index f149a45..70679cf 100644 --- a/fbchat/graphql.py +++ b/fbchat/graphql.py @@ -99,7 +99,8 @@ def graphql_to_user(user): emoji=c_info.get('emoji'), own_nickname=c_info.get('own_nickname'), photo=user['profile_picture'].get('uri'), - name=user.get('name') + name=user.get('name'), + message_count=user.get('messages_count') ) def graphql_to_group(group): @@ -113,7 +114,8 @@ def graphql_to_group(group): color=c_info.get('color'), emoji=c_info.get('emoji'), photo=group['image'].get('uri'), - name=group.get('name') + name=group.get('name'), + message_count=group.get('messages_count') ) def graphql_to_page(page): @@ -127,7 +129,8 @@ def graphql_to_page(page): city=page.get('city').get('name'), category=page.get('category_type'), photo=page['profile_picture'].get('uri'), - name=page.get('name') + name=page.get('name'), + message_count=page.get('messages_count') ) def graphql_queries_to_json(*queries):