diff --git a/fbchat/_client.py b/fbchat/_client.py index 23d185a..b5746f1 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -206,7 +206,7 @@ class Client: ) -> Iterable[Tuple[_threads.ThreadABC, int]]: """Search for messages in all threads. - Intended to be used alongside `ThreadABC.search_messages` + Intended to be used alongside `ThreadABC.search_messages`. Warning! If someone send a message to a thread that matches the query, while we're searching, some snippets will get returned twice, and some will be lost. @@ -215,8 +215,7 @@ class Client: Args: query: Text to search for - limit: Max. number of threads to retrieve. If ``None``, all threads will be - retrieved + limit: Max. number of items to retrieve. If ``None``, all will be retrieved Example: Search for messages, and print the amount of snippets in each thread. @@ -372,6 +371,8 @@ class Client: ) -> Iterable[_threads.ThreadABC]: """Fetch the client's thread list. + The returned threads are ordered by last active first. + Args: limit: Max. number of threads to retrieve. If ``None``, all threads will be retrieved. diff --git a/fbchat/_threads/_abc.py b/fbchat/_threads/_abc.py index ca690df..29f72b5 100644 --- a/fbchat/_threads/_abc.py +++ b/fbchat/_threads/_abc.py @@ -316,7 +316,7 @@ class ThreadABC(metaclass=abc.ABCMeta): This is fundamentally unfixable, it's just how the endpoint is implemented. - The returned message snippets are ordered by last sent. + The returned message snippets are ordered by last sent first. Args: query: Text to search for @@ -368,7 +368,7 @@ class ThreadABC(metaclass=abc.ABCMeta): def fetch_messages(self, limit: Optional[int]) -> Iterable["_models.Message"]: """Fetch messages in a thread. - The returned messages are ordered by most recent first. + The returned messages are ordered by last sent first. Args: limit: Max. number of threads to retrieve. If ``None``, all threads will be @@ -390,9 +390,10 @@ class ThreadABC(metaclass=abc.ABCMeta): before = None for limit in _util.get_limits(limit, MAX_BATCH_LIMIT): messages = self._fetch_messages(limit, before) + messages.reverse() if before: - # Strip the first thread + # Strip the first messages yield from messages[1:] else: yield from messages @@ -413,8 +414,6 @@ class ThreadABC(metaclass=abc.ABCMeta): result = j[self.id]["message_shared_media"] - print(len(result["edges"])) - rtn = [] for edge in result["edges"]: node = edge["node"] @@ -433,6 +432,8 @@ class ThreadABC(metaclass=abc.ABCMeta): def fetch_images(self, limit: Optional[int]) -> Iterable["_models.Attachment"]: """Fetch images/videos posted in the thread. + The returned images are ordered by last sent first. + Args: limit: Max. number of images to retrieve. If ``None``, all images will be retrieved.