getJoinedMembersByRoom method
This API returns a map of MXIDs to member info objects for members of the room. The current user must be in the room for it to work, unless it is an Application Service in which case any of the AS's users must be in the room. This API is primarily for Application Services and should be faster to respond than /members
as it can be implemented more efficiently on the server.
roomId
The room to get the members of.
returns joined
:
A map from user ID to a RoomMember object.
Implementation
Future<Map<String, RoomMember>?> getJoinedMembersByRoom(String roomId) async {
final requestUri = Uri(
path:
'_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/joined_members',
);
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 Map<String, Object?>).map(
(k, v) =>
MapEntry(k, RoomMember.fromJson(v as Map<String, Object?>)),
)
: null)(json['joined']);
}