updateAppserviceRoomDirectoryVisibility method

Future<Map<String, Object?>> updateAppserviceRoomDirectoryVisibility(
  1. String networkId,
  2. String roomId,
  3. Visibility visibility
)
inherited

Updates the visibility of a given room on the application service's room directory.

This API is similar to the room directory visibility API used by clients to update the node's more general room directory.

This API requires the use of an application service access token (as_token) instead of a typical client's access_token. This API cannot be invoked by users who are not identified as application services.

networkId The protocol (network) ID to update the room list for. This would have been provided by the application service as being listed as a supported protocol.

roomId The room ID to add to the directory.

visibility Whether the room should be visible (public) in the directory or not (private).

Implementation

Future<Map<String, Object?>> updateAppserviceRoomDirectoryVisibility(
    String networkId, String roomId, Visibility visibility) async {
  final requestUri = Uri(
      path:
          '_api/client/v3/directory/list/appservice/${Uri.encodeComponent(networkId)}/${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({
    '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 json as Map<String, Object?>;
}