@using MatrixRoomUtils.Web.Shared.RoomListComponents;
@using MatrixRoomUtils.Core.StateEventTypes
@Rooms.Count rooms total, @RoomsWithTypes.Sum(x=>x.Value.Count) fetched so far...
@foreach (var category in RoomsWithTypes.OrderBy(x => x.Value.Count)) {
}
@code {
[Parameter]
public List Rooms { get; set; }
Dictionary> RoomsWithTypes = new();
protected override async Task OnInitializedAsync() {
if (RoomsWithTypes.Any()) return;
var tasks = Rooms.Select(AddRoom);
await Task.WhenAll(tasks);
await base.OnInitializedAsync();
}
private string GetRoomTypeName(string? roomType) => roomType switch {
"m.space" => "Space",
"msc3588.stories.stories-room" => "Story room",
null => "Room",
_ => roomType
};
private static SemaphoreSlim _semaphoreSlim = new SemaphoreSlim(8, 8);
private async Task AddRoom(GenericRoom room) {
await _semaphoreSlim.WaitAsync();
var roomType = GetRoomTypeName((await room.GetCreateEventAsync()).Type);
if (roomType == "Room") {
var shortcodeState = await room.GetStateAsync("org.matrix.mjolnir.shortcode");
if (shortcodeState is not null) roomType = "Legacy policy room";
}
if (!RoomsWithTypes.ContainsKey(roomType)) {
RoomsWithTypes.Add(roomType, new List());
}
RoomsWithTypes[roomType].Add(room);
// if (RoomsWithTypes.Count % 10 == 0)
StateHasChanged();
await Task.Delay(100);
_semaphoreSlim.Release();
}
private bool _isSpaceChildrenOpen = false;
}