getPublicRooms method

Future<GetPublicRoomsResponse> getPublicRooms({
  1. int? limit,
  2. String? since,
  3. String? server,
})

Lists a server's published room directory.

This API returns paginated responses.

Changed in `v1.19` The server determines the order of the rooms returned by this endpoint. Previously, rooms were ordered with the largest joined member count first. Continuing to order by largest first or another stable order is recommended.

limit Limit the number of results returned.

since A pagination token from a previous request, allowing clients to get the next (or previous) batch of rooms. The direction of pagination is specified solely by which token is supplied, rather than via an explicit flag.

server The server to fetch the published room directory from. Defaults to the local server. Case sensitive.

Implementation

Future<GetPublicRoomsResponse> getPublicRooms({
  int? limit,
  String? since,
  String? server,
}) async {
  final requestUri = Uri(
    path: '_matrix/client/v3/publicRooms',
    queryParameters: {
      if (limit != null) 'limit': limit.toString(),
      if (since != null) 'since': since,
      if (server != null) 'server': server,
    },
  );
  final request = Request('GET', baseUri!.resolveUri(requestUri));
  final response = await httpClient.send(request);
  final responseBody = await response.stream.toBytes();
  if (response.statusCode != 200) unexpectedResponse(response, responseBody);
  final responseString = utf8.decode(responseBody);
  final json = jsonDecode(responseString);
  return GetPublicRoomsResponse.fromJson(json as Map<String, Object?>);
}