fix: Don't query /members over and over

This commit is contained in:
Sorunome 2020-09-18 10:01:03 +02:00
parent f6259efa59
commit 3187275ed7
No known key found for this signature in database
GPG key ID: B19471D07FC9BE9C

View file

@ -1044,6 +1044,8 @@ class Room {
return userList;
}
bool _requestedParticipants = 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.
Future<List<User>> requestParticipants() async {
@ -1054,13 +1056,16 @@ class Room {
setState(user);
}
}
if (participantListComplete) return getParticipants();
if (_requestedParticipants || participantListComplete) {
return getParticipants();
}
final matrixEvents = await client.requestMembers(id);
final users =
matrixEvents.map((e) => Event.fromMatrixEvent(e, this).asUser).toList();
for (final user in users) {
setState(user); // at *least* cache this in-memory
}
_requestedParticipants = true;
users.removeWhere(
(u) => [Membership.leave, Membership.ban].contains(u.membership));
return users;