requestParticipants method

Future<List<User>> requestParticipants([
  1. List<Membership> membershipFilter = const [Membership.join, Membership.invite, Membership.knock],
  2. bool suppressWarning = 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]

Implementation

Future<List<User>> requestParticipants(
    [List<Membership> membershipFilter = const [
      Membership.join,
      Membership.invite,
      Membership.knock,
    ],
    bool suppressWarning = false]) async {
  if (!participantListComplete && partial) {
    // we aren't fully loaded, maybe the users are in the database
    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 done it
  // in this session or have a complete list locally.
  if (_requestedParticipants || participantListComplete) {
    return getParticipants(membershipFilter);
  }

  final memberCount = summary.mJoinedMemberCount;
  if (!suppressWarning && 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 sdnEvents = await client.getMembersByRoom(id);
  final users =
      sdnEvents?.map((e) => Event.fromSDNEvent(e, this).asUser).toList() ??
          [];
  for (final user in users) {
    setState(user); // at *least* cache this in-memory
  }
  _requestedParticipants = true;
  users.removeWhere((u) => !membershipFilter.contains(u.membership));
  return users;
}