getRoomStateWithKey method

Future<Map<String, Object?>> getRoomStateWithKey(
  1. String roomId,
  2. String eventType,
  3. String stateKey
)
inherited

Looks up the contents of a state event in a room. If the user is joined to the room then the state is taken from the current state of the room. If the user has left the room then the state is taken from the state of the room when they left.

roomId The room to look up the state in.

eventType The type of state to look up.

stateKey The key of the state to look up. Defaults to an empty string. When an empty string, the trailing slash on this endpoint is optional.

Implementation

Future<Map<String, Object?>> getRoomStateWithKey(
    String roomId, String eventType, String stateKey) async {
  final requestUri = Uri(
      path:
          '_api/client/v3/rooms/${Uri.encodeComponent(roomId)}/state/${Uri.encodeComponent(eventType)}/${Uri.encodeComponent(stateKey)}');
  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 json as Map<String, Object?>;
}