requestParticipants method

Future<List<User>> requestParticipants([
  1. List<Membership> membershipFilter = const [Membership.join, Membership.invite, Membership.knock],
  2. bool suppressWarning = false,
  3. bool? cache,
  4. bool enforceFetchFromServer = false,
])

Request the full list of participants from the server. The local list from the store is not complete if the client uses lazy loading. List membershipFilter defines with what membership do you want the participants, default set to [Membership.join, Membership.invite, Membership.knock] Set cache to false if you do not want to cache the users in memory for this session which is highly recommended for large public rooms. By default users are only cached in encrypted rooms as encrypted rooms need a full member list.

Implementation

Future<List<User>> requestParticipants([
  List<Membership> membershipFilter = const [
    Membership.join,
    Membership.invite,
    Membership.knock,
  ],
  bool suppressWarning = false,
  bool? cache,
  bool enforceFetchFromServer = false,
]) async {
  if (!participantListComplete || partial) {
    // we aren't fully loaded, maybe the users are in the database
    // We always need to check the database in the partial case, since state
    // events won't get written to memory in this case and someone new could
    // have joined, while someone else left, which might lead to the same
    // count in the completeness check.
    final users = await client.database.getUsers(this);
    for (final user in users) {
      setState(user);
    }
  }

  // Do not request users from the server if we have already have a complete list locally.
  if (participantListComplete && !enforceFetchFromServer) {
    return getParticipants(membershipFilter);
  }

  cache ??= encrypted;

  final memberCount = summary.mJoinedMemberCount;
  if (!suppressWarning && cache && memberCount != null && memberCount > 100) {
    Logs().w('''
      Loading a list of $memberCount participants for the room $id.
      This may affect the performance. Please make sure to not unnecessary
      request so many participants or suppress this warning.
    ''');
  }

  final matrixEvents = await client.getMembersByRoom(id);
  final users =
      matrixEvents
          ?.map((e) => Event.fromMatrixEvent(e, this).asUser)
          .toList() ??
      [];

  if (cache) {
    for (final user in users) {
      setState(user); // at *least* cache this in-memory
      await client.database.storeEventUpdate(
        id,
        user,
        EventUpdateType.state,
        client,
      );
    }
  }

  users.removeWhere((u) => !membershipFilter.contains(u.membership));
  return users;
}