[Room] Add getParticipants method
This commit is contained in:
parent
7b4c51aae9
commit
963866f408
2 changed files with 26 additions and 0 deletions
|
@ -515,6 +515,17 @@ class Room {
|
||||||
return await client.store.loadParticipants(this);
|
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
|
/// Request the full list of participants from the server. The local list
|
||||||
/// from the store is not complete if the client uses lazy loading.
|
/// from the store is not complete if the client uses lazy loading.
|
||||||
Future<List<User>> requestParticipants() async {
|
Future<List<User>> requestParticipants() async {
|
||||||
|
|
|
@ -225,6 +225,21 @@ void main() {
|
||||||
expect(resp, {});
|
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 {
|
test("addToDirectChat", () async {
|
||||||
final dynamic resp = await room.addToDirectChat("Testname");
|
final dynamic resp = await room.addToDirectChat("Testname");
|
||||||
expect(resp, {});
|
expect(resp, {});
|
||||||
|
|
Loading…
Add table
Reference in a new issue