Few nitpicky fixes

This commit is contained in:
Mads Marquart
2019-01-31 20:12:59 +01:00
parent af3bd55535
commit 7f0da012c2

View File

@@ -501,25 +501,25 @@ class Client(object):
:raises: FBchatException if request failed :raises: FBchatException if request failed
""" """
threads = [] threads = []
threads += self.fetchThreadList(thread_location=thread_location)
if not threads:
return []
last_thread_timestamp = None
while True: while True:
# break if limit is exceeded # break if limit is exceeded
if limit and len(threads) >= limit: if limit and len(threads) >= limit:
break break
last_thread_timestamp = threads[-1].last_message_timestamp
# fetchThreadList returns at max 20 threads before last_thread_timestamp (included) # fetchThreadList returns at max 20 threads before last_thread_timestamp (included)
candidates = self.fetchThreadList(before=last_thread_timestamp, candidates = self.fetchThreadList(before=last_thread_timestamp,
thread_location=thread_location thread_location=thread_location
) )
if len(candidates) > 1: if len(candidates) > 1:
threads += candidates[1:] threads += candidates[1:]
else: # End of threads else: # End of threads
break break
last_thread_timestamp = threads[-1].last_message_timestamp
# FB returns a sorted list of threads # FB returns a sorted list of threads
if (before is not None and int(last_thread_timestamp) > before) or \ if (before is not None and int(last_thread_timestamp) > before) or \
(after is not None and int(last_thread_timestamp) < after): (after is not None and int(last_thread_timestamp) < after):
@@ -527,7 +527,7 @@ class Client(object):
# Return only threads between before and after (if set) # Return only threads between before and after (if set)
if before is not None or after is not None: if before is not None or after is not None:
for t in list(threads): for t in threads:
last_message_timestamp = int(t.last_message_timestamp) last_message_timestamp = int(t.last_message_timestamp)
if (before is not None and last_message_timestamp > before) or \ if (before is not None and last_message_timestamp > before) or \
(after is not None and last_message_timestamp < after): (after is not None and last_message_timestamp < after):
@@ -559,7 +559,7 @@ class Client(object):
users_to_fetch.append(user_id) users_to_fetch.append(user_id)
else: else:
pass pass
for user_id,user in self.fetchUserInfo(*users_to_fetch).items(): for user_id, user in self.fetchUserInfo(*users_to_fetch).items():
users.append(user) users.append(user)
return users return users