diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-07-01 20:51:15 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-07-01 20:51:15 +0200 |
commit | 7978f08235ceca22eacae11a88a7703513238cb3 (patch) | |
tree | 6a7058f21f6040cc1e9396a85774bc16ea133c9e /MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs | |
parent | Todays progress (diff) | |
download | MatrixUtils-7978f08235ceca22eacae11a88a7703513238cb3.tar.xz |
Deduplicate some api calls
Diffstat (limited to 'MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs')
-rw-r--r-- | MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs | 17 |
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 |