getRoomStateWithKey method
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.
format
The format to use for the returned data. content
(the default) will
return only the content of the state event. event
will return the entire
event in the usual format suitable for clients, including fields like event
ID, sender and timestamp.
Implementation
Future<Map<String, Object?>> getRoomStateWithKey(
String roomId,
String eventType,
String stateKey, {
Format? format,
}) async {
final requestUri = Uri(
path:
'_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/state/${Uri.encodeComponent(eventType)}/${Uri.encodeComponent(stateKey)}',
queryParameters: {
if (format != null) 'format': format.name,
},
);
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?>;
}