diff --git a/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs b/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs
index 031b6b6..6f5df39 100644
--- a/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs
+++ b/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs
@@ -1,7 +1,6 @@
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;
-using MatrixRoomUtils.Core.Extensions;
using MatrixRoomUtils.Core.Interfaces;
namespace MatrixRoomUtils.Core;
diff --git a/MatrixRoomUtils.Core/Extensions/StringExtensions.cs b/MatrixRoomUtils.Core/Extensions/StringExtensions.cs
index 7bed7a3..8fadc6d 100644
--- a/MatrixRoomUtils.Core/Extensions/StringExtensions.cs
+++ b/MatrixRoomUtils.Core/Extensions/StringExtensions.cs
@@ -1,5 +1,3 @@
-using MatrixRoomUtils.Core.Authentication;
-
namespace MatrixRoomUtils.Core.Extensions;
public static class StringExtensions
diff --git a/MatrixRoomUtils.Core/RemoteHomeServer.cs b/MatrixRoomUtils.Core/RemoteHomeServer.cs
index 6bd2251..1acea89 100644
--- a/MatrixRoomUtils.Core/RemoteHomeServer.cs
+++ b/MatrixRoomUtils.Core/RemoteHomeServer.cs
@@ -1,7 +1,5 @@
-using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;
-using MatrixRoomUtils.Core.Extensions;
using MatrixRoomUtils.Core.Interfaces;
using MatrixRoomUtils.Core.Responses;
diff --git a/MatrixRoomUtils.Core/Responses/LoginResponse.cs b/MatrixRoomUtils.Core/Responses/LoginResponse.cs
index 4012d32..34b42d1 100644
--- a/MatrixRoomUtils.Core/Responses/LoginResponse.cs
+++ b/MatrixRoomUtils.Core/Responses/LoginResponse.cs
@@ -1,7 +1,6 @@
using System.Net.Http.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
-using MatrixRoomUtils.Core.Authentication;
namespace MatrixRoomUtils.Core.Responses;
diff --git a/MatrixRoomUtils.Core/Room.cs b/MatrixRoomUtils.Core/Room.cs
index fff5013..d5eee2b 100644
--- a/MatrixRoomUtils.Core/Room.cs
+++ b/MatrixRoomUtils.Core/Room.cs
@@ -14,9 +14,8 @@ public class Room
RoomId = roomId;
}
- public async Task<JsonElement?> GetStateAsync(string type, string state_key="")
+ public async Task<JsonElement?> GetStateAsync(string type, string state_key="", bool logOnFailure = false)
{
- Console.WriteLine($"{RoomId}::_qry[{type}::{state_key}]");
var url = $"/_matrix/client/r0/rooms/{RoomId}/state";
if (!string.IsNullOrEmpty(state_key)) url += $"/{type}/{state_key}";
else if (!string.IsNullOrEmpty(type)) url += $"/{type}";
@@ -24,21 +23,18 @@ public class Room
var res = await _httpClient.GetAsync(url);
if (!res.IsSuccessStatusCode)
{
- Console.WriteLine($"{RoomId}::_qry[{type}::{state_key}]->status=={res.StatusCode}");
+ if(logOnFailure) Console.WriteLine($"{RoomId}/{state_key}/{type} - got status: {res.StatusCode}");
return null;
}
return await res.Content.ReadFromJsonAsync<JsonElement>();
}
public async Task<string?> GetNameAsync()
- {
- Console.WriteLine($"{RoomId}::_qry_name");
+ {
var res = await GetStateAsync("m.room.name");
if (!res.HasValue)
{
- Console.WriteLine($"{RoomId}::_qry_name->null");
return null;
}
- Console.WriteLine($"{RoomId}::_qry_name->{res.Value.ToString()}");
var resn = res?.TryGetProperty("name", out var name) ?? false ? name.GetString() : null;
Console.WriteLine($"Got name: {resn}");
return resn;
diff --git a/MatrixRoomUtils.Web/App.razor b/MatrixRoomUtils.Web/App.razor
index e2a241d..4e2789d 100644
--- a/MatrixRoomUtils.Web/App.razor
+++ b/MatrixRoomUtils.Web/App.razor
@@ -1,5 +1,4 @@
-@using MatrixRoomUtils.Core
-<Router AppAssembly="@typeof(App).Assembly">
+<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/>
<FocusOnNavigate RouteData="@routeData" Selector="h1"/>
diff --git a/MatrixRoomUtils.Web/Pages/DataExportPage.razor b/MatrixRoomUtils.Web/Pages/DataExportPage.razor
index 58d49fc..62d093b 100644
--- a/MatrixRoomUtils.Web/Pages/DataExportPage.razor
+++ b/MatrixRoomUtils.Web/Pages/DataExportPage.razor
@@ -1,8 +1,6 @@
@page "/export"
@using MatrixRoomUtils.Web.Shared.IndexComponents
@using System.Text.Json
-@using MatrixRoomUtils.Core
-@using MatrixRoomUtils.Core.Authentication
@inject NavigationManager NavigationManager
@inject ILocalStorageService LocalStorage
diff --git a/MatrixRoomUtils.Web/Pages/Index.razor b/MatrixRoomUtils.Web/Pages/Index.razor
index 67cefed..5fb7e94 100644
--- a/MatrixRoomUtils.Web/Pages/Index.razor
+++ b/MatrixRoomUtils.Web/Pages/Index.razor
@@ -1,6 +1,5 @@
@page "/"
@using MatrixRoomUtils.Web.Shared.IndexComponents
-@using MatrixRoomUtils.Core
@inject NavigationManager NavigationManager
@inject ILocalStorageService LocalStorage
diff --git a/MatrixRoomUtils.Web/Pages/LoginPage.razor b/MatrixRoomUtils.Web/Pages/LoginPage.razor
index f318646..c986d40 100644
--- a/MatrixRoomUtils.Web/Pages/LoginPage.razor
+++ b/MatrixRoomUtils.Web/Pages/LoginPage.razor
@@ -1,5 +1,4 @@
@page "/Login"
-@using MatrixRoomUtils.Core
@using MatrixRoomUtils.Core.Authentication
@inject ILocalStorageService LocalStorage
<h3>Login</h3>
diff --git a/MatrixRoomUtils.Web/Pages/PolicyListEditorPage.razor b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor
index 66a5c9f..5dfb2d6 100644
--- a/MatrixRoomUtils.Web/Pages/PolicyListEditorPage.razor
+++ b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor
@@ -1,12 +1,11 @@
@page "/PolicyListEditor/{RoomId}"
-@using System.Net.Http.Headers
@using System.Text.Json
-@using MatrixRoomUtils.Core
@using MatrixRoomUtils.Core.Extensions
@using MatrixRoomUtils.Core.StateEventTypes
@inject ILocalStorageService LocalStorage
@inject NavigationManager NavigationManager
-<h3>Policy list editor</h3>
+<h3>Policy list editor - Editing @RoomId</h3>
+<hr/>
<p>
This policy list contains @PolicyEvents.Count(x => x.type == "m.policy.rule.server") server bans,
diff --git a/MatrixRoomUtils.Web/Pages/PolicyListRoomList.razor b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor
index 3af60b7..5656af9 100644
--- a/MatrixRoomUtils.Web/Pages/PolicyListRoomList.razor
+++ b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor
@@ -1,14 +1,11 @@
@page "/PolicyListEditor"
-@using System.Net.Http.Headers
@using System.Text.Json
-@using MatrixRoomUtils.Core
@using MatrixRoomUtils.Core.Extensions
@inject ILocalStorageService LocalStorage
@inject NavigationManager NavigationManager
-<h3>Policy list editor</h3>
-
-<h5>Room list</h5>
+<h3>Policy list editor - Room list</h3>
<hr/>
+
@if (PolicyRoomList.Count == 0)
{
<p>No policy rooms found.</p>
diff --git a/MatrixRoomUtils.Web/Pages/RoomStateEditorPage.razor b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor
index 47f2aba..638d728 100644
--- a/MatrixRoomUtils.Web/Pages/RoomStateEditorPage.razor
+++ b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor
@@ -1,11 +1,10 @@
@page "/RoomStateViewer/{RoomId}/Edit"
@using System.Net.Http.Headers
@using System.Text.Json
-@using MatrixRoomUtils.Core
@inject ILocalStorageService LocalStorage
@inject NavigationManager NavigationManager
-<h3>Room state editor</h3>
-<p>Room ID: @RoomId</p>
+<h3>Room state editor - Editing @RoomId</h3>
+<hr/>
<p>@status</p>
diff --git a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateRoomList.razor b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateRoomList.razor
new file mode 100644
index 0000000..ba1b0ec
--- /dev/null
+++ b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateRoomList.razor
@@ -0,0 +1,36 @@
+@page "/RoomStateViewer"
+@inject ILocalStorageService LocalStorage
+@inject NavigationManager NavigationManager
+<h3>Room state viewer - Room list</h3>
+<hr/>
+@if (Rooms.Count == 0)
+{
+ <p>You are not in any rooms!</p>
+ @* <p>Loading progress: @checkedRoomCount/@totalRoomCount</p> *@
+}
+else
+{
+ @foreach (var room in Rooms)
+ {
+ <a style="color: unset; text-decoration: unset;" href="/RoomStateViewer/@room.Replace('.','~')"><RoomListItem RoomId="@room"></RoomListItem></a>
+ }
+ <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
diff --git a/MatrixRoomUtils.Web/Pages/RoomStateViewerPage.razor b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor
index 199c75b..0f40cb9 100644
--- a/MatrixRoomUtils.Web/Pages/RoomStateViewerPage.razor
+++ b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor
@@ -1,12 +1,11 @@
@page "/RoomStateViewer/{RoomId}"
@using System.Net.Http.Headers
@using System.Text.Json
-@using MatrixRoomUtils.Core
@using MatrixRoomUtils.Core.Extensions
@inject ILocalStorageService LocalStorage
@inject NavigationManager NavigationManager
-<h3>Room state viewer</h3>
-<p>Room ID: @RoomId</p>
+<h3>Room state viewer - Viewing @RoomId</h3>
+<hr/>
<p>@status</p>
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
diff --git a/MatrixRoomUtils.Web/Pages/UserImportPage.razor b/MatrixRoomUtils.Web/Pages/UserImportPage.razor
index 97a1c44..6f3045e 100644
--- a/MatrixRoomUtils.Web/Pages/UserImportPage.razor
+++ b/MatrixRoomUtils.Web/Pages/UserImportPage.razor
@@ -1,6 +1,5 @@
@page "/ImportUsers"
@using System.Text.Json
-@using MatrixRoomUtils.Core
@using MatrixRoomUtils.Core.Authentication
@inject ILocalStorageService LocalStorage
<h3>Login</h3>
diff --git a/MatrixRoomUtils.Web/Program.cs b/MatrixRoomUtils.Web/Program.cs
index f83f008..15c18f7 100644
--- a/MatrixRoomUtils.Web/Program.cs
+++ b/MatrixRoomUtils.Web/Program.cs
@@ -1,6 +1,6 @@
using System.Text.Json;
using System.Text.Json.Serialization;
-using Blazored.LocalStorage;using MatrixRoomUtils;
+using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using MatrixRoomUtils.Web;
diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
new file mode 100644
index 0000000..31fca4c
--- /dev/null
+++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
@@ -0,0 +1,45 @@
+<div style="background-color: #ffffff11; border-radius: 25px; margin: 8px; width: fit-content;">
+ <img style="width: 32px; height: 32px; border-radius: 50%;" src="@roomIcon"/>
+ <span style="vertical-align: middle; padding-right: 8px;">@roomName</span>
+</div>
+
+@code {
+ [Parameter]
+ public Room Room { get; set; }
+ [Parameter]
+ public string RoomId { get; set; }
+
+ private string roomName { get; set; } = "Loading...";
+ private string roomIcon { get; set; } = "/icon-192.png";
+
+ protected override async Task OnInitializedAsync()
+ {
+ await base.OnInitializedAsync();
+ if (Room == null)
+ {
+ if (RoomId == null)
+ {
+ throw new ArgumentNullException(nameof(RoomId));
+ }
+ Room = await RuntimeCache.CurrentHomeServer.GetRoom(RoomId);
+ }
+
+ roomName = await Room.GetNameAsync();
+ if (roomName == null)
+ {
+ roomName = "Unnamed room: " + RoomId;
+ }
+
+ var state = await Room.GetStateAsync("m.room.avatar");
+ if (state != null)
+ {
+ var url = state.Value.GetProperty("url").GetString();
+ if (url != null)
+ {
+ roomIcon = await RuntimeCache.CurrentHomeServer.ResolveMediaUri(url);
+ }
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/wwwroot/css/app.css b/MatrixRoomUtils.Web/wwwroot/css/app.css
index 8034dcc..acbbfce 100644
--- a/MatrixRoomUtils.Web/wwwroot/css/app.css
+++ b/MatrixRoomUtils.Web/wwwroot/css/app.css
@@ -2,6 +2,17 @@
html, body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
+ background-color: #222;
+ color: #aaa;
+}
+
+#app > div > main > div {
+ background-color: #333;
+ border-bottom: none;
+}
+
+.table, .table-striped>tbody>tr:nth-of-type(odd), .table-hover>tbody>tr:hover {
+ color: unset;
}
h1:focus {
|