putRoomKeyBySessionId method

Future<RoomKeysUpdateResponse> putRoomKeyBySessionId(
  1. String roomId,
  2. String sessionId,
  3. String version,
  4. KeyBackupData body,
)

Store a key in the backup.

roomId The ID of the room that the key is for.

sessionId The ID of the megolm session that the key is for.

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

body The key data.

Implementation

Future<RoomKeysUpdateResponse> putRoomKeyBySessionId(
  String roomId,
  String sessionId,
  String version,
  KeyBackupData body,
) async {
  final requestUri = Uri(
    path:
        '_matrix/client/v3/room_keys/keys/${Uri.encodeComponent(roomId)}/${Uri.encodeComponent(sessionId)}',
    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(body.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?>);
}