postRoomKeysVersion method
Creates a new backup.
algorithm
The algorithm used for storing backups.
authData
Algorithm-dependent data. See the documentation for the backup
algorithms in Server-side key backups for more information on the
expected format of the data.
returns version
:
The backup version. This is an opaque string.
Implementation
Future<String> postRoomKeysVersion(
BackupAlgorithm algorithm,
Map<String, Object?> authData,
) async {
final requestUri = Uri(path: '_matrix/client/v3/room_keys/version');
final request = Request('POST', baseUri!.resolveUri(requestUri));
request.headers['authorization'] = 'Bearer ${bearerToken!}';
request.headers['content-type'] = 'application/json';
request.bodyBytes = utf8.encode(
jsonEncode({
'algorithm': algorithm.name,
'auth_data': authData,
}),
);
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['version'] as String;
}