From 9e32cf17a44a6d5ff6b9bb75d6c0aa7da9f262f5 Mon Sep 17 00:00:00 2001 From: Ritvik Annam Date: Thu, 10 Aug 2017 00:53:06 -0500 Subject: [PATCH] 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__()