@page "/PolicyListEditor" @inject ILocalStorageService LocalStorage @inject NavigationManager NavigationManager

Policy list editor - Room list


@if (PolicyRoomList.Count == 0) {

No policy rooms found.

Loading progress: @checkedRoomCount/@totalRoomCount

} else { @if (checkedRoomCount != totalRoomCount) {

Loading progress: @checkedRoomCount/@totalRoomCount

} foreach (var s in PolicyRoomList) {
Shortcode: @s.Shortcode
@* [@s.Shortcode] @s.Name (@s.RoomId) *@ @*
*@ } }
@code { //get room list // - sync withroom list filter // Type = support.feline.msc3784 //support.feline.policy.lists.msc.v1 public List PolicyRoomList { get; set; } = new(); private int checkedRoomCount { get; set; } private int totalRoomCount { get; set; } protected override async Task OnInitializedAsync() { await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); await base.OnInitializedAsync(); if (RuntimeCache.CurrentHomeServer == null) { NavigationManager.NavigateTo("/Login"); return; } await EnumeratePolicyRooms(); Console.WriteLine("Policy list editor initialized!"); } private async Task EnumeratePolicyRooms() { var xxxrooms = await RuntimeCache.CurrentHomeServer.GetJoinedRooms(); totalRoomCount = xxxrooms.Count; StateHasChanged(); var xxxsemaphore = new SemaphoreSlim(1000); var xxxtasks = new List>(); foreach (var room in xxxrooms) { xxxtasks.Add(GetPolicyRoomInfo(room.RoomId, xxxsemaphore)); } var xxxresults = await Task.WhenAll(xxxtasks); PolicyRoomList.AddRange(xxxresults.Where(x => x != null).Select(x => x.Value)); Console.WriteLine($"Detected policy lists: {PolicyRoomList.ToJson()}"); } private async Task GetPolicyRoomInfo(string room, SemaphoreSlim semaphore) { try { await semaphore.WaitAsync(); PolicyRoomInfo roomInfo = new() { RoomId = room }; var r = await RuntimeCache.CurrentHomeServer.GetRoom(room); var shortcodeState = await r.GetStateAsync("org.matrix.mjolnir.shortcode"); if (!shortcodeState.HasValue) return null; roomInfo.Shortcode = shortcodeState.Value.TryGetProperty("shortcode", out var shortcode) ? shortcode.GetString() : null; if (roomInfo.Shortcode != null) { roomInfo.Name = await r.GetNameAsync(); return roomInfo; } return null; } finally { checkedRoomCount++; StateHasChanged(); semaphore.Release(); } } public struct PolicyRoomInfo { public string RoomId { get; set; } public string? Shortcode { get; set; } public string? Name { get; set; } } }