From 963866f4087f9898d6090c76e6e8e932007990bc Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Mon, 2 Sep 2019 12:09:30 +0200 Subject: [PATCH] [Room] Add getParticipants method --- lib/src/Room.dart | 11 +++++++++++ test/Room_test.dart | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/src/Room.dart b/lib/src/Room.dart index a83a876f..bb198d00 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 19d1eb06..e016f6be 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, {});