@using MatrixRoomUtils.Web.Shared.RoomListComponents; @using LibMatrix.StateEventTypes @using LibMatrix.StateEventTypes.Spec @using LibMatrix @using LibMatrix.Extensions @if(Rooms.Count != RoomsWithTypes.Sum(x=>x.Value.Count)) {

Fetching room details... @RoomsWithTypes.Sum(x=>x.Value.Count) out of @Rooms.Count done!

@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 ProfileResponseEventData? GlobalProfile { get; set; } Dictionary> RoomsWithTypes = new(); protected override async Task OnInitializedAsync() { var hs = await MRUStorage.GetCurrentSessionOrNavigate(); if (hs is null) return; GlobalProfile ??= await hs.GetProfile(hs.WhoAmI.UserId); if (RoomsWithTypes.Any()) return; var tasks = Rooms.Select(ProcessRoom); await Task.WhenAll(tasks); await base.OnInitializedAsync(); } private string GetRoomTypeName(string? roomType) => roomType switch { "m.space" => "Space", "msc3588.stories.stories-room" => "Story room", "support.feline.policy.lists.msc.v1" => "MSC3784 Policy list (v1)", null => "Room", _ => roomType }; private static SemaphoreSlim _semaphoreSlim = new(8, 8); private async Task ProcessRoom(RoomInfo room) { await _semaphoreSlim.WaitAsync(); string roomType; try { RoomCreateEventData createEvent = (await room.GetStateEvent("m.room.create")).TypedContent as RoomCreateEventData; roomType = GetRoomTypeName(createEvent.Type); if (roomType == "Room") { var mjolnirData = await room.GetStateEvent("org.matrix.mjolnir.shortcode"); if(mjolnirData?.RawContent?.ToJson(ignoreNull: true) is not null and not "{}") roomType = "Legacy policy room"; } } catch (MatrixException e) { roomType = $"Error: {e.ErrorCode}"; } if (!RoomsWithTypes.ContainsKey(roomType)) { RoomsWithTypes.Add(roomType, new List()); } RoomsWithTypes[roomType].Add(room); StateHasChanged(); _semaphoreSlim.Release(); } }