queryPublicRooms method
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. Case sensitive.
filter Filter to apply to the results.
includeAllNetworks Whether or not to include all known networks/protocols from
application services on the homeserver. 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
homeserver. Can only be used if include_all_networks is false.
This is the instance_id of a Protocol Instance returned by
GET /_matrix/client/v3/thirdparty/protocols.
Implementation
Future<QueryPublicRoomsResponse> queryPublicRooms({
String? server,
PublicRoomQueryFilter? filter,
bool? includeAllNetworks,
int? limit,
String? since,
String? thirdPartyInstanceId,
}) async {
final requestUri = Uri(
path: '_matrix/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?>);
}