diff --git a/lib/src/Room.dart b/lib/src/Room.dart index a83a876..bb198d0 100644 --- a/lib/src/Room.dart +++ b/lib/src/Room.dart @@ -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 getParticipants() { + List 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> requestParticipants() async { diff --git a/test/Room_test.dart b/test/Room_test.dart index 19d1eb0..e016f6b 100644 --- a/test/Room_test.dart +++ b/test/Room_test.dart @@ -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 userList = room.getParticipants(); + expect(userList.length, 1); + expect(userList[0].displayName, "alice"); + }); + test("addToDirectChat", () async { final dynamic resp = await room.addToDirectChat("Testname"); expect(resp, {});