getDevices method

Future<List<Device>?> getDevices()

Gets information about all devices for the current user.

returns devices: A list of all registered devices for this user.

Implementation

Future<List<Device>?> getDevices() async {
  final requestUri = Uri(path: '_matrix/client/v3/devices');
  final request = Request('GET', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  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 ((v) => v != null
      ? (v as List)
          .map((v) => Device.fromJson(v as Map<String, Object?>))
          .toList()
      : null)(json['devices']);
}