diff --git a/fbchat/client.py b/fbchat/client.py index bde5f89..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 @@ -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/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): 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__()