From b3359fccdb2044eaeee1d7aa19cc12a79d380c78 Mon Sep 17 00:00:00 2001 From: Joe Lau Date: Wed, 28 Jun 2017 18:06:55 -0700 Subject: [PATCH] Add last_message_timestamp to Thread objects --- fbchat/client.py | 3 ++- fbchat/models.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 1aaf26d..d3dc252 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -736,9 +736,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']].last_message_timestamp = k['last_message_timestamp'] 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'], last_message_timestamp=k['last_message_timestamp'])) else: raise Exception('A thread had an unknown thread type: {}'.format(k)) diff --git a/fbchat/models.py b/fbchat/models.py index 1697c28..24b508d 100644 --- a/fbchat/models.py +++ b/fbchat/models.py @@ -13,13 +13,16 @@ class Thread(object): photo = str #: The name of the thread name = str + #: Timestamp of last message + last_message_timestamp = str - def __init__(self, _type, uid, photo=None, name=None): + def __init__(self, _type, uid, photo=None, name=None, last_message_timestamp=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 def __repr__(self): return self.__unicode__()