queryKeys method

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

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.

token If the client is fetching keys as a result of a device update received in a sync request, this should be the 'since' token of that sync request, or any later sync token. This allows the server to ensure its response contains the keys advertised by the notification in that sync.

Implementation

Future<QueryKeysResponse> queryKeys(Map<String, List<String>> deviceKeys,
    {int? timeout, String? token}) 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,
    if (token != null) 'token': token,
  }));
  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?>);
}