From 932bde4f9f8871fcae111f7d076b32e727118f59 Mon Sep 17 00:00:00 2001 From: John Westhoff Date: Thu, 29 Dec 2016 13:12:17 -0500 Subject: [PATCH] Added support for group threds in getThreadInfo --- fbchat/client.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 777de09..8b07dce 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -326,21 +326,27 @@ class Client(object): # Strip the start and parse out the returned image_id return json.loads(r._content[9:])['payload']['metadata'][0]['image_id'] - def getThreadInfo(self, userID, start, end=None): + def getThreadInfo(self, userID, start, end=None, thread_type='user'): """Get the info of one Thread :param userID: ID of the user you want the messages from :param start: the start index of a thread :param end: (optional) the last index of a thread + :param thread_type: (optional) change from 'user' for group threads """ if not end: end = start + 20 if end <= start: end = start + end data = {} - data['messages[user_ids][%s][offset]'%userID] = start - data['messages[user_ids][%s][limit]'%userID] = end - data['messages[user_ids][%s][timestamp]'%userID] = now() + if thread_type == 'user': + key = 'user_ids' + else: + key = 'thread_fbids' + + data['messages[{}][{}][offset]'.format(key, userID)] = start + data['messages[{}][{}][limit]'.format(key, userID)] = end + data['messages[{}][{}][timestamp]'.format(key, userID)] = now() r = self._post(MessagesURL, query=data) if not r.ok or len(r.text) == 0: