getPublicRooms method

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

Lists the public rooms on the server.

This API returns paginated responses. The rooms are ordered by the number of joined members, with the largest rooms first.

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 public room lists 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?>);
}