putRoomKeysByRoomId method

Future<RoomKeysUpdateResponse> putRoomKeysByRoomId(
  1. String roomId,
  2. String version,
  3. RoomKeyBackup backupData
)
inherited

Store several keys in the backup for a given room.

roomId The ID of the room that the keys are for.

version The backup in which to store the keys. Must be the current backup.

backupData The backup data

Implementation

Future<RoomKeysUpdateResponse> putRoomKeysByRoomId(
    String roomId, String version, RoomKeyBackup backupData) async {
  final requestUri = Uri(
      path: '_api/client/v3/room_keys/keys/${Uri.encodeComponent(roomId)}',
      queryParameters: {
        'version': version,
      });
  final request = Request('PUT', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  request.headers['content-type'] = 'application/json';
  request.bodyBytes = utf8.encode(jsonEncode(backupData.toJson()));
  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 RoomKeysUpdateResponse.fromJson(json as Map<String, Object?>);
}