queryKeys method

Future<QueryKeysResponse> queryKeys(
  1. Map<String, List<String>> deviceKeys, {
  2. int? timeout,
})

Returns the current devices and identity keys for the given users.

deviceKeys The keys to be downloaded. A map from user ID, to a list of device IDs, or to an empty list to indicate all devices for the corresponding user.

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

Implementation

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