@using MatrixRoomUtils.Web.Shared.RoomListComponents; @using MatrixRoomUtils.Core.StateEventTypes

@Rooms.Count rooms total, @RoomsWithTypes.Sum(x=>x.Value.Count) fetched so far...

@if(Rooms.Count != RoomsWithTypes.Sum(x=>x.Value.Count)) {

Fetching more rooms...

@foreach (var category in RoomsWithTypes.OrderBy(x => x.Value.Count)) {

@category.Key (@category.Value.Count)

} } else { @foreach (var category in RoomsWithTypes.OrderBy(x => x.Value.Count)) { } } @code { [Parameter] public List Rooms { get; set; } [Parameter] public ProfileResponse? GlobalProfile { get; set; } Dictionary> RoomsWithTypes = new(); protected override async Task OnInitializedAsync() { GlobalProfile ??= await (await MRUStorage.GetCurrentSession()!).GetProfile((await MRUStorage.GetCurrentSession()!).WhoAmI.UserId); 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(4, 4); private async Task AddRoom(GenericRoom room) { await _semaphoreSlim.WaitAsync(); string roomType; try { var createEvent = await room.GetCreateEventAsync(); roomType = GetRoomTypeName(createEvent.Type); if (roomType == "Room") { var shortcodeState = await room.GetStateAsync("org.matrix.mjolnir.shortcode"); if (shortcodeState is not null) roomType = "Legacy policy room"; } } catch (MatrixException e) { roomType = $"Error: {e.ErrorCode}"; } 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(); } }