python-o365 icon indicating copy to clipboard operation
python-o365 copied to clipboard

get_my_chats only returns the first set of chats and does not paginate

Open jhoult opened this issue 3 years ago • 3 comments

Like the subject says, when running get_my_chats() it doesn't return all the data.

this should work.

    def get_my_chats(self, limit=None, batch=None):
        """ Returns a list of chats that I am in
        :param int limit: number of chats to retrieve
        :param int batch: number of chats to be in each data set
        :rtype: list[ChatMessage] or Pagination of Chat
        """
        url = self.build_url(self._endpoints.get('get_my_chats'))

        if not batch and (limit is None or limit > MAX_BATCH_CHATS):
            batch = MAX_BATCH_CHATS

        params = {'$top': batch if batch else limit}
        response = self.con.get(url, params=params)
        if not response:
            return []

        data = response.json()
        next_link = data.get(NEXT_LINK_KEYWORD, None)

        chats = [self.chat_constructor(parent=self,
                                             **{self._cloud_data_key: message})
                    for message in data.get('value', [])]

        if batch and next_link:
            return Pagination(parent=self, data=chats,
                              constructor=self.chat_constructor,
                              next_link=next_link, limit=limit)
        else:
            return chats

jhoult avatar Jun 09 '22 19:06 jhoult

Did you check if this endpoint in MS GRAPH allows pagination? If yes and tested:

¿can you make a PR with this change so it can be merged and deployed?

alejcas avatar Jun 10 '22 09:06 alejcas

https://github.com/O365/python-o365/pull/791 hopefully I did it right, this is the first one i've done on github.

jhoult avatar Jun 12 '22 22:06 jhoult

thanks!

alejcas avatar Jul 11 '22 09:07 alejcas