setRoomAlias method

Future<void> setRoomAlias(
  1. String roomAlias,
  2. String roomId
)

roomAlias The room alias to set. Its format is defined in the appendices.

roomId The room ID to set.

Implementation

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