getPresence method

Future<GetPresenceResponse> getPresence(
  1. String userId
)

Get the given user's presence state.

userId The user whose presence state to get.

Implementation

Future<GetPresenceResponse> getPresence(String userId) async {
  final requestUri = Uri(
    path: '_matrix/client/v3/presence/${Uri.encodeComponent(userId)}/status',
  );
  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 GetPresenceResponse.fromJson(json as Map<String, Object?>);
}