From 0767ef4902bd7de9cc3002e91583e6764a432870 Mon Sep 17 00:00:00 2001 From: 2FWAH <36737818+2FWAH@users.noreply.github.com> Date: Fri, 1 Jun 2018 23:27:34 +0200 Subject: [PATCH] Add fetchAllUsersFromThreads Add a method to get all users involved in threads (given as a parameter) --- fbchat/client.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/fbchat/client.py b/fbchat/client.py index 7360bcc..7fb4305 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -494,7 +494,29 @@ class Client(object): else: break return Threads # from newest to oldest - + + def fetchAllUsersFromThreads(client, threads): + """ + Get all users involved in threads. + + :param threads: models.Thread: List of threads to check for users + :return: :class:`models.User` objects + :rtype: list + :raises: FBchatException if request failed + """ + Users = [] + for thread in threads: + if thread.type == ThreadType.USER: + if thread.uid not in [user.uid for user in Users]: + Users.append(thread) + elif thread.type == ThreadType.GROUP: + for userID in thread.participants: + if userID not in [user.uid for user in Users]: + Users.append(self.fetchUserInfo(userID)[userID]) + else: + pass + return Users + def fetchAllUsers(self): """ Gets all users the client is currently chatting with