about summary refs log tree commit diff
path: root/MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-07-01 20:51:15 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-07-01 20:51:15 +0200
commit7978f08235ceca22eacae11a88a7703513238cb3 (patch)
tree6a7058f21f6040cc1e9396a85774bc16ea133c9e /MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs
parentTodays progress (diff)
downloadMatrixUtils-7978f08235ceca22eacae11a88a7703513238cb3.tar.xz
Deduplicate some api calls
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