queryPublicRooms method

Future<QueryPublicRoomsResponse> queryPublicRooms({
  1. String? server,
  2. PublicRoomQueryFilter? filter,
  3. bool? includeAllNetworks,
  4. int? limit,
  5. String? since,
  6. String? thirdPartyInstanceId,
})
inherited

Lists the public rooms on the server, with optional filter.

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

server The server to fetch the public room lists from. Defaults to the local server.

filter Filter to apply to the results.

includeAllNetworks Whether or not to include all known networks/protocols from application services on the node. Defaults to false.

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.

thirdPartyInstanceId The specific third party network/protocol to request from the node. Can only be used if include_all_networks is false.

Implementation

Future<QueryPublicRoomsResponse> queryPublicRooms(
    {String? server,
    PublicRoomQueryFilter? filter,
    bool? includeAllNetworks,
    int? limit,
    String? since,
    String? thirdPartyInstanceId}) async {
  final requestUri =
      Uri(path: '_api/client/v3/publicRooms', queryParameters: {
    if (server != null) 'server': server,
  });
  final request = Request('POST', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  request.headers['content-type'] = 'application/json';
  request.bodyBytes = utf8.encode(jsonEncode({
    if (filter != null) 'filter': filter.toJson(),
    if (includeAllNetworks != null)
      'include_all_networks': includeAllNetworks,
    if (limit != null) 'limit': limit,
    if (since != null) 'since': since,
    if (thirdPartyInstanceId != null)
      'third_party_instance_id': thirdPartyInstanceId,
  }));
  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 QueryPublicRoomsResponse.fromJson(json as Map<String, Object?>);
}