[Room] Add getParticipants method

This commit is contained in:
Christian Pauly 2019-09-02 12:09:30 +02:00
parent 7b4c51aae9
commit 963866f408
2 changed files with 26 additions and 0 deletions

View file

@ -515,6 +515,17 @@ class Room {
return await client.store.loadParticipants(this);
}
/// Returns all participants for this room. With lazy loading this
/// list may not be complete. User [requestParticipants] in this
/// case.
List<User> getParticipants() {
List<User> userList = [];
for (var entry in states.entries)
if (entry.value.type == EventTypes.RoomMember)
userList.add(entry.value.asUser);
return userList;
}
/// 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 {

View file

@ -225,6 +225,21 @@ void main() {
expect(resp, {});
});
test("getParticipants", () async {
room.states["@alice:test.abc"] = RoomState(
senderId: "@alice:test.abc",
typeKey: "m.room.member",
roomId: room.id,
room: room,
eventId: "12345",
time: ChatTime.now(),
content: {"displayname": "alice"},
stateKey: "@alice:test.abc");
final List<User> userList = room.getParticipants();
expect(userList.length, 1);
expect(userList[0].displayName, "alice");
});
test("addToDirectChat", () async {
final dynamic resp = await room.addToDirectChat("Testname");
expect(resp, {});