@page "/PolicyListEditor" @using System.Text.Json.Serialization @using MatrixRoomUtils.Core.Interfaces @using MatrixRoomUtils.Core.StateEventTypes @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 base.OnInitializedAsync(); var hs = await MRUStorage.GetCurrentSessionOrNavigate(); if (hs is null) return; await EnumeratePolicyRooms(); Console.WriteLine("Policy list editor initialized!"); } private async Task EnumeratePolicyRooms() { var hs = await MRUStorage.GetCurrentSession(); var rooms = await hs.GetJoinedRooms(); totalRoomCount = rooms.Count; StateHasChanged(); var semaphore = new SemaphoreSlim(8); var tasks = new List>(); foreach (var room in rooms) { tasks.Add(GetPolicyRoomInfo(room.RoomId, semaphore)); } var results = await Task.WhenAll(tasks); PolicyRoomList.AddRange(results.Where(x => x is not null).Select(x => x.Value)); Console.WriteLine($"Detected policy lists: {PolicyRoomList.ToJson()}"); } private async Task GetPolicyRoomInfo(string room, SemaphoreSlim semaphore) { try { await semaphore.WaitAsync(); var hs = await MRUStorage.GetCurrentSession(); PolicyRoomInfo roomInfo = new() { RoomId = room }; var r = await hs.GetRoom(room); var shortcodeState = await r.GetStateAsync("org.matrix.mjolnir.shortcode"); roomInfo.Shortcode = shortcodeState.Shortcode; if (roomInfo.Shortcode is not 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; } } }