getMembersByRoom method

Future<List<SDNEvent>?> getMembersByRoom(
  1. String roomId, {
  2. String? at,
  3. Membership? membership,
  4. Membership? notMembership,
})
inherited

Get the list of members for this room.

roomId The room to get the member events for.

at The point in time (pagination token) to return members for in the room. This token can be obtained from a prev_batch token returned for each room by the sync API. Defaults to the current state of the room, as determined by the server.

membership The kind of membership to filter for. Defaults to no filtering if unspecified. When specified alongside not_membership, the two parameters create an 'or' condition: either the membership is the same as membership or is not the same as not_membership.

notMembership The kind of membership to exclude from the results. Defaults to no filtering if unspecified.

returns chunk:

Implementation

Future<List<SDNEvent>?> getMembersByRoom(String roomId,
    {String? at, Membership? membership, Membership? notMembership}) async {
  final requestUri = Uri(
      path: '_api/client/v3/rooms/${Uri.encodeComponent(roomId)}/members',
      queryParameters: {
        if (at != null) 'at': at,
        if (membership != null) 'membership': membership.name,
        if (notMembership != null) 'not_membership': notMembership.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 ((v) => v != null
      ? (v as List)
          .map((v) => SDNEvent.fromJson(v as Map<String, Object?>))
          .toList()
      : null)(json['chunk']);
}