From a56abc92dbf4153a05cce005f26e9c078cfa540f Mon Sep 17 00:00:00 2001 From: Jackson Date: Wed, 3 Apr 2024 01:19:11 +0200 Subject: [PATCH] implement room_list_paginate it's like user_list_paginate but for rooms --- synadm/api.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/synadm/api.py b/synadm/api.py index 31f74fa..bbb0dcb 100644 --- a/synadm/api.py +++ b/synadm/api.py @@ -774,6 +774,34 @@ def room_list(self, _from, limit, name, order_by, reverse): "dir": "b" if reverse else None }) + def room_list_paginate(self, limit, name, order_by, reverse, _from=0): + """ Yields API responses for room listing. + + Args: + limit (int): Maximum number of rooms returned per pagination. + name (string or None): Search for a room by name. Passed as + `search_term` in the room list API. Use Python None to avoid + searching. + order_by (string): Synapse Room list API specific argument. + reverse (bool): Whether the results should be + _from (int): Initial offset in pagination. + + Yields: + dict: The Admin API response for listing accounts. + https://element-hq.github.io/synapse/latest/admin_api/rooms.html#list-room-api + """ + while _from is not None: + response = self.query("get", "v1/rooms", params={ + "from": _from, + "limit": limit, + "search_term": name, + "order_by": order_by, + "dir": "b" if reverse else None + }) + yield response + _from = response.get("next_batch", None) + self.log.debug(f"room_list_paginate: next from value = {_from}") + def room_details(self, room_id): """ Get details about a room """