setRoomVisibilityOnDirectory method

Future<void> setRoomVisibilityOnDirectory(
  1. String roomId, {
  2. Visibility? visibility,
})

Sets the visibility of a given room in the server's public room directory.

Servers may choose to implement additional access control checks here, for instance that room visibility can only be changed by the room creator or a server administrator.

roomId The room ID.

visibility The new visibility setting for the room. Defaults to 'public'.

Implementation

Future<void> setRoomVisibilityOnDirectory(
  String roomId, {
  Visibility? visibility,
}) async {
  final requestUri = Uri(
    path:
        '_matrix/client/v3/directory/list/room/${Uri.encodeComponent(roomId)}',
  );
  final request = Request('PUT', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  request.headers['content-type'] = 'application/json';
  request.bodyBytes = utf8.encode(
    jsonEncode({
      if (visibility != null) 'visibility': visibility.name,
    }),
  );
  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 ignore(json);
}