From 487a2eb3e3d09f1973fe2872d3a7f0220866f136 Mon Sep 17 00:00:00 2001 From: 2FWAH <36737818+2FWAH@users.noreply.github.com> Date: Fri, 1 Jun 2018 22:59:56 +0200 Subject: [PATCH] Add fetchThreads method Add a method to get all threads in Location (INBOX, ARCHIVED...) --- fbchat/client.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/fbchat/client.py b/fbchat/client.py index 2b20d69..7930b2d 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -472,6 +472,28 @@ class Client(object): """ FETCH METHODS """ + + def fetchThreads(self, thread_location): + """ + Get all threads in thread_location. + + :param thread_location: models.ThreadLocation: INBOX, PENDING, ARCHIVED or OTHER + :return: :class:`models.Thread` objects + :rtype: list + :raises: FBchatException if request failed + """ + Threads = [] + Threads += self.fetchThreadList(thread_location) + if len(Threads) == 0: + return [] + while True: + lastThreadTimestamp = Threads[-1].last_message_timestamp + candidates = client.fetchThreadList(before=lastThreadTimestamp, thread_location=thread_location) # return at max 20 threads before lastThreadTimestamp (included) + if len(candidates) > 1: + Threads += candidates[1:] + else: + break + return Threads # from newest to oldest def fetchAllUsers(self): """