about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Pages
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixRoomUtils.Web/Pages')
-rw-r--r--MatrixRoomUtils.Web/Pages/DataExportPage.razor4
-rw-r--r--MatrixRoomUtils.Web/Pages/DebugTools.razor87
-rw-r--r--MatrixRoomUtils.Web/Pages/Index.razor2
-rw-r--r--MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor40
-rw-r--r--MatrixRoomUtils.Web/Pages/RoomManager.razor40
5 files changed, 131 insertions, 42 deletions
diff --git a/MatrixRoomUtils.Web/Pages/DataExportPage.razor b/MatrixRoomUtils.Web/Pages/DataExportPage.razor
index 62d093b..6e1b5ec 100644
--- a/MatrixRoomUtils.Web/Pages/DataExportPage.razor
+++ b/MatrixRoomUtils.Web/Pages/DataExportPage.razor
@@ -1,4 +1,4 @@
-@page "/export"
+@page "/Export"
 @using MatrixRoomUtils.Web.Shared.IndexComponents
 @using System.Text.Json
 @inject NavigationManager NavigationManager
@@ -6,7 +6,7 @@
 
 <PageTitle>Export</PageTitle>
 
-<h1>Data export</h1>
+<h3>Data export</h3>
 
 <br/><br/>
 <h5>Signed in accounts - <a href="/Login">Add new account</a> or <a href="/ImportUsers">Import from TSV</a></h5>
diff --git a/MatrixRoomUtils.Web/Pages/DebugTools.razor b/MatrixRoomUtils.Web/Pages/DebugTools.razor
new file mode 100644
index 0000000..ffa2134
--- /dev/null
+++ b/MatrixRoomUtils.Web/Pages/DebugTools.razor
@@ -0,0 +1,87 @@
+@page "/Debug"
+@using MatrixRoomUtils.Core.Interfaces
+@using MatrixRoomUtils.Core.Extensions
+@using System.Reflection
+@inject ILocalStorageService LocalStorage
+@inject NavigationManager NavigationManager
+<h3>Debug Tools</h3>
+<hr/>
+@if (Rooms.Count == 0)
+{
+    <p>You are not in any rooms!</p>
+    @* <p>Loading progress: @checkedRoomCount/@totalRoomCount</p> *@
+}
+else
+{
+    <details>
+        <summary>Room List</summary>
+        @foreach (var room in Rooms)
+        {
+            <a style="color: unset; text-decoration: unset;" href="/RoomStateViewer/@room.Replace('.', '~')"><RoomListItem RoomId="@room"></RoomListItem></a>
+        }
+    </details>
+    
+}
+
+<details open>
+    <summary>Send GET request to URL</summary>
+    <div class="input-group">
+        <input type="text" class="form-control" @bind-value="get_request_url" placeholder="URL">
+        <button class="btn btn-outline-secondary" type="button" @onclick="SendGetRequest">Send</button>
+    </div>
+    <br/>
+    <pre>@get_request_result</pre>
+</details>
+
+<div style="margin-bottom: 4em;"></div>
+<LogView></LogView>
+
+@code {
+    public List<string> Rooms { get; set; } = new();
+    protected override async Task OnInitializedAsync()
+    {
+        if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+        await base.OnInitializedAsync();
+        if (RuntimeCache.CurrentHomeServer == null)
+        {
+            NavigationManager.NavigateTo("/Login");
+            return;
+        }
+        Rooms = (await RuntimeCache.CurrentHomeServer.GetJoinedRooms()).Select(x=>x.RoomId).ToList();
+        Console.WriteLine("Fetched joined rooms!");
+    }
+
+    
+    //send req
+    string get_request_url { get; set; } = "";
+    string get_request_result { get; set; } = "";
+    private async Task SendGetRequest()
+    {
+        var field = typeof(IHomeServer).GetRuntimeFields().First(x => x.ToString().Contains("<_httpClient>k__BackingField"));
+        var httpClient = field.GetValue(RuntimeCache.CurrentHomeServer) as HttpClient;
+        try
+        {
+            var res = await httpClient.GetAsync(get_request_url);
+            if (res.IsSuccessStatusCode)
+            {
+                if(res.Content.Headers.ContentType.MediaType == "application/json")
+                    get_request_result = (await res.Content.ReadFromJsonAsync<object>()).ToJson();
+                else
+                    get_request_result = await res.Content.ReadAsStringAsync();
+                StateHasChanged();
+                return;
+            }
+            if(res.Content.Headers.ContentType.MediaType == "application/json")
+                get_request_result = $"Error: {res.StatusCode}\n" + (await res.Content.ReadFromJsonAsync<object>()).ToJson();
+            else
+                get_request_result = $"Error: {res.StatusCode}\n" + await res.Content.ReadAsStringAsync();
+
+        }
+        catch (Exception e)
+        {
+            get_request_result = $"Error: {e}";
+        }
+        StateHasChanged();
+    }
+
+} 
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Pages/Index.razor b/MatrixRoomUtils.Web/Pages/Index.razor
index 5fb7e94..7be4149 100644
--- a/MatrixRoomUtils.Web/Pages/Index.razor
+++ b/MatrixRoomUtils.Web/Pages/Index.razor
@@ -5,7 +5,7 @@
 
 <PageTitle>Index</PageTitle>
 
-<h1>Rory&::MatrixUtils</h1>
+<h3>Rory&::MatrixUtils</h3>
 Small collection of tools to do not-so-everyday things.
 
 <br/><br/>
diff --git a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor
index 5656af9..e9d1be4 100644
--- a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor
+++ b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor
@@ -57,7 +57,7 @@ else
         totalRoomCount = xxxrooms.Count;
         StateHasChanged();
 
-        var xxxsemaphore = new SemaphoreSlim(256);
+        var xxxsemaphore = new SemaphoreSlim(1000);
         var xxxtasks = new List<Task<PolicyRoomInfo?>>();
         foreach (var room in xxxrooms)
         {
@@ -68,44 +68,6 @@ else
 
         Console.WriteLine($"Detected policy lists: {PolicyRoomList.ToJson()}");
         return;
-    /*
-        using HttpClient wc = new();
-        wc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalStorageWrapper.AccessToken);
-
-        
-        
-    //get room list
-    //temporary hack until rooms get enumerated...
-        string[] rooms = { "!fTjMjIzNKEsFlUIiru:neko.dev" };
-        var _rooms = await wc.GetAsync($"{LocalStorageWrapper.CurrentHomeserver}/_matrix/client/v3/joined_rooms");
-        Console.WriteLine($"Got {_rooms.StatusCode}...");
-        if (!_rooms.IsSuccessStatusCode)
-        {
-            Console.WriteLine($"Failed to get rooms: {await _rooms.Content.ReadAsStringAsync()}");
-            return;
-        }
-        var _rooms_o = await _rooms.Content.ReadFromJsonAsync<JsonElement>();
-        if (_rooms_o.TryGetProperty("joined_rooms", out JsonElement _rooms_j))
-        {
-            rooms = _rooms_j.EnumerateArray().Select(x => x.GetString()).ToArray();
-        }
-
-        totalRoomCount = rooms.Length;
-        StateHasChanged();
-
-        var semaphore = new SemaphoreSlim(256);
-        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));
-
-
-    //print to console
-        Console.WriteLine($"Detected policy lists: {PolicyRoomList.ToJson()}");
-        */
     }
 
     private async Task<PolicyRoomInfo?> GetPolicyRoomInfo(string room, SemaphoreSlim semaphore)
diff --git a/MatrixRoomUtils.Web/Pages/RoomManager.razor b/MatrixRoomUtils.Web/Pages/RoomManager.razor
new file mode 100644
index 0000000..deb6fd5
--- /dev/null
+++ b/MatrixRoomUtils.Web/Pages/RoomManager.razor
@@ -0,0 +1,40 @@
+@page "/RoomManager"
+@inject ILocalStorageService LocalStorage
+@inject NavigationManager NavigationManager
+<h3>Room manager</h3>
+<hr/>
+@if (Rooms.Count == 0)
+{
+    <p>You are not in any rooms!</p>
+    @* <p>Loading progress: @checkedRoomCount/@totalRoomCount</p> *@
+}
+else
+{
+    <details open>
+        <summary>Room List</summary>
+        @foreach (var room in Rooms)
+        {
+            <a style="color: unset; text-decoration: unset;" href="/RoomStateViewer/@room.Replace('.', '~')"><RoomListItem RoomId="@room" ShowOwnProfile="true"></RoomListItem></a>
+        }
+    </details>
+    
+}
+
+<div style="margin-bottom: 4em;"></div>
+<LogView></LogView>
+
+@code {
+    public List<string> Rooms { get; set; } = new();
+    protected override async Task OnInitializedAsync()
+    {
+        if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+        await base.OnInitializedAsync();
+        if (RuntimeCache.CurrentHomeServer == null)
+        {
+            NavigationManager.NavigateTo("/Login");
+            return;
+        }
+        Rooms = (await RuntimeCache.CurrentHomeServer.GetJoinedRooms()).Select(x=>x.RoomId).ToList();
+        Console.WriteLine("Fetched joined rooms!");
+    }
+} 
\ No newline at end of file