diff options
Diffstat (limited to 'MatrixRoomUtils.Web/Pages/RoomStateRoomList.razor')
-rw-r--r-- | MatrixRoomUtils.Web/Pages/RoomStateRoomList.razor | 96 |
1 files changed, 0 insertions, 96 deletions
diff --git a/MatrixRoomUtils.Web/Pages/RoomStateRoomList.razor b/MatrixRoomUtils.Web/Pages/RoomStateRoomList.razor deleted file mode 100644 index 92e7955..0000000 --- a/MatrixRoomUtils.Web/Pages/RoomStateRoomList.razor +++ /dev/null @@ -1,96 +0,0 @@ -@page "/RoomStateViewer" -@using System.Net.Http.Headers -@using System.Text.Json -@using MatrixRoomUtils.Core -@inject ILocalStorageService LocalStorage -@inject NavigationManager NavigationManager -<h3>Room state viewer</h3> - -<h5>Room list</h5> -<hr/> -@if (PolicyRoomList.Count == 0) -{ - <p>No policy rooms found.</p> - <p>Loading progress: @checkedRoomCount/@totalRoomCount</p> -} -else -{ - @if (checkedRoomCount != totalRoomCount) - { - <p>Loading progress: @checkedRoomCount/@totalRoomCount</p> - } - foreach (var s in PolicyRoomList) - { - <a href="@(NavigationManager.Uri + "/" + s.RoomId.Replace('.', '~'))">@s.Name (@s.RoomId)</a> - <br/> - } - <div style="margin-bottom: 4em;"></div> -} - -<LogView></LogView> - -@code { - - public List<PolicyRoomInfo> PolicyRoomList { get; set; } = new(); - - private int checkedRoomCount { get; set; } = 0; - private int totalRoomCount { get; set; } = 0; - - protected override async Task OnInitializedAsync() - { - if (!RuntimeCache.WasLoaded) 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 rooms = (await RuntimeCache.CurrentHomeServer.GetJoinedRooms()).Select(x=>x.RoomId).ToList(); - - totalRoomCount = rooms.Count; - StateHasChanged(); - - var semaphore = new SemaphoreSlim(128); - var tasks = new List<Task<PolicyRoomInfo?>>(); - foreach (string room in rooms) - { - tasks.Add(GetPolicyRoomInfo(room, semaphore)); - } - var results = await Task.WhenAll(tasks); - PolicyRoomList.AddRange(results.Where(x => x != null).Select(x=>x.Value)); - - StateHasChanged(); - } - - private async Task<PolicyRoomInfo?> GetPolicyRoomInfo(string room, SemaphoreSlim semaphore) - { - try - { - await semaphore.WaitAsync(); - return new PolicyRoomInfo() - { - RoomId = room, - Name = await (await RuntimeCache.CurrentHomeServer.GetRoom(room)).GetNameAsync() - }; - } - finally - { - checkedRoomCount++; - StateHasChanged(); - semaphore.Release(); - } - } - - - public struct PolicyRoomInfo - { - public string RoomId { get; set; } - public string Name { get; set; } - } -} \ No newline at end of file |