about summary refs log tree commit diff
path: root/MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs')
-rw-r--r--MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs17
1 files changed, 9 insertions, 8 deletions
diff --git a/MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs b/MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs
index 3be3130..1b93064 100644
--- a/MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs
+++ b/MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs
@@ -13,15 +13,16 @@ public class SpaceRoom : GenericRoom {
         _homeServer = homeServer;
     }
 
-    public async Task<List<GenericRoom>> GetRoomsAsync(bool includeRemoved = false) {
+    private static SemaphoreSlim _semaphore = new(1, 1);
+    public async IAsyncEnumerable<GenericRoom> GetRoomsAsync(bool includeRemoved = false) {
+        await _semaphore.WaitAsync();
         var rooms = new List<GenericRoom>();
-        var state = GetFullStateAsync().ToBlockingEnumerable().ToList();
-        var childStates = state.Where(x => x.Type == "m.space.child");
-        foreach (var stateEvent in childStates) {
-            if (stateEvent.TypedContent.ToJson() != "{}" || includeRemoved)
-                rooms.Add(await _homeServer.GetRoom(stateEvent.StateKey));
+        var state = GetFullStateAsync();
+        await foreach (var stateEvent in state) {
+            if (stateEvent.Type != "m.space.child") continue;
+            if (stateEvent.RawContent.ToJson() != "{}" || includeRemoved)
+                yield return await _homeServer.GetRoom(stateEvent.StateKey);
         }
-
-        return rooms;
+        _semaphore.Release();
     }
 }
\ No newline at end of file