claimKeys method

Future<ClaimKeysResponse> claimKeys(
  1. Map<String, Map<String, String>> oneTimeKeys, {
  2. int? timeout,
})

Claims one-time keys for use in pre-key messages.

oneTimeKeys The keys to be claimed. A map from user ID, to a map from device ID to algorithm name.

timeout The time (in milliseconds) to wait when downloading keys from remote servers. 10 seconds is the recommended default.

Implementation

Future<ClaimKeysResponse> claimKeys(
  Map<String, Map<String, String>> oneTimeKeys, {
  int? timeout,
}) async {
  final requestUri = Uri(path: '_matrix/client/v3/keys/claim');
  final request = Request('POST', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  request.headers['content-type'] = 'application/json';
  request.bodyBytes = utf8.encode(
    jsonEncode({
      'one_time_keys': oneTimeKeys
          .map((k, v) => MapEntry(k, v.map((k, v) => MapEntry(k, v)))),
      if (timeout != null) 'timeout': timeout,
    }),
  );
  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 ClaimKeysResponse.fromJson(json as Map<String, Object?>);
}