Add last_message_timestamp to Thread objects

This commit is contained in:
Joe Lau
2017-06-28 18:06:55 -07:00
parent d8f7366d1f
commit b3359fccdb
2 changed files with 6 additions and 2 deletions

View File

@@ -736,9 +736,10 @@ class Client(object):
if k['thread_type'] == 1: if k['thread_type'] == 1:
if k['other_user_fbid'] not in participants: if k['other_user_fbid'] not in participants:
raise Exception('A thread was not in participants: {}'.format(j['payload'])) 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']]) entries.append(participants[k['other_user_fbid']])
elif k['thread_type'] == 2: 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: else:
raise Exception('A thread had an unknown thread type: {}'.format(k)) raise Exception('A thread had an unknown thread type: {}'.format(k))

View File

@@ -13,13 +13,16 @@ class Thread(object):
photo = str photo = str
#: The name of the thread #: The name of the thread
name = str 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""" """Represents a Facebook thread"""
self.uid = str(uid) self.uid = str(uid)
self.type = _type self.type = _type
self.photo = photo self.photo = photo
self.name = name self.name = name
self.last_message_timestamp = last_message_timestamp
def __repr__(self): def __repr__(self):
return self.__unicode__() return self.__unicode__()