diff --git a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor
deleted file mode 100644
index 8e2609f..0000000
--- a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor
+++ /dev/null
@@ -1,249 +0,0 @@
-@page "/PolicyListEditor/{RoomId}"
-@using MatrixRoomUtils.Core.StateEventTypes
-@using System.Text.Json
-@using MatrixRoomUtils.Core.Helpers
-@using MatrixRoomUtils.Core.Responses
-<h3>Policy list editor - Editing @RoomId</h3>
-<hr/>
-
-<p>
- This policy list contains @PolicyEvents.Count(x => x.Type == "m.policy.rule.server") server bans,
- @PolicyEvents.Count(x => x.Type == "m.policy.rule.room") room bans and
- @PolicyEvents.Count(x => x.Type == "m.policy.rule.user") user bans.
-</p>
-<InputCheckbox @bind-Value="_enableAvatars" @oninput="GetAllAvatars"></InputCheckbox><label>Enable avatars (WILL EXPOSE YOUR IP TO TARGET HOMESERVERS!)</label>
-
-
-@if (!PolicyEvents.Any(x => x.Type == "m.policy.rule.server")) {
- <p>No server policies</p>
-}
-else {
- <h3>Server policies</h3>
- <hr/>
- <table class="table table-striped table-hover" style="width: fit-Content;">
- <thead>
- <tr>
- <th scope="col" style="max-width: 50vw;">Server</th>
- <th scope="col">Reason</th>
- <th scope="col">Expires</th>
- <th scope="col">Actions</th>
- </tr>
- </thead>
- <tbody>
- @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.server" && (x.TypedContent as PolicyRuleStateEventData).Entity is not null)) {
- var policyData = policyEvent.TypedContent as PolicyRuleStateEventData;
- <tr>
- <td>Entity: @policyData.Entity<br/>State: @policyEvent.StateKey</td>
- <td>@policyData.Reason</td>
- <td>
- @policyData.ExpiryDateTime
- </td>
- <td>
- <button class="btn" @* @onclick="async () => await RemovePolicyAsync(policyEvent)" *@>Edit</button>
- @* <button class="btn btn-danger" $1$ @onclick="async () => await RemovePolicyAsync(policyEvent)" #1#>Remove</button> *@
- </td>
- </tr>
- }
- </tbody>
- </table>
- <details>
- <summary>Redacted events</summary>
- <table class="table table-striped table-hover" style="width: fit-Content;">
- <thead>
- <tr>
- <th scope="col" style="max-width: 50vw;">State key</th>
- <th scope="col">Serialised Contents</th>
- </tr>
- </thead>
- <tbody>
- @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.server" && (x.TypedContent as PolicyRuleStateEventData).Entity == null)) {
- var policyData = policyEvent.TypedContent as PolicyRuleStateEventData;
- <tr>
- <td>@policyEvent.StateKey</td>
- <td>@policyEvent.RawContent.ToJson(false, true)</td>
- </tr>
- }
- </tbody>
- </table>
- </details>
-}
-@if (!PolicyEvents.Any(x => x.Type == "m.policy.rule.room")) {
- <p>No room policies</p>
-}
-else {
- <h3>Room policies</h3>
- <hr/>
- <table class="table table-striped table-hover" style="width: fit-Content;">
- <thead>
- <tr>
- <th scope="col" style="max-width: 50vw;">Room</th>
- <th scope="col">Reason</th>
- <th scope="col">Expires</th>
- <th scope="col">Actions</th>
- </tr>
- </thead>
- <tbody>
- @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && (x.TypedContent as PolicyRuleStateEventData).Entity is not null)) {
- var policyData = policyEvent.TypedContent as PolicyRuleStateEventData;
- <tr>
- <td>Entity: @policyData.Entity<br/>State: @policyEvent.StateKey</td>
- <td>@policyData.Reason</td>
- <td>
- @policyData.ExpiryDateTime
- </td>
- <td>
- <button class="btn btn-danger" @* @onclick="async () => await RemovePolicyAsync(policyEvent)" *@>Remove</button>
- </td>
- </tr>
- }
- </tbody>
- </table>
- <details>
- <summary>Redacted events</summary>
- <table class="table table-striped table-hover" style="width: fit-Content;">
- <thead>
- <tr>
- <th scope="col" style="max-width: 50vw;">State key</th>
- <th scope="col">Serialised Contents</th>
- </tr>
- </thead>
- <tbody>
- @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && (x.TypedContent as PolicyRuleStateEventData).Entity == null)) {
- <tr>
- <td>@policyEvent.StateKey</td>
- <td>@policyEvent.RawContent.ToJson(false, true)</td>
- </tr>
- }
- </tbody>
- </table>
- </details>
-}
-@if (!PolicyEvents.Any(x => x.Type == "m.policy.rule.user")) {
- <p>No user policies</p>
-}
-else {
- <h3>User policies</h3>
- <hr/>
- <table class="table table-striped table-hover" style="width: fit-Content;">
- <thead>
- <tr>
- @if (_enableAvatars) {
- <th scope="col"></th>
- }
- <th scope="col" style="max-width: 0.2vw; word-wrap: anywhere;">User</th>
- <th scope="col">Reason</th>
- <th scope="col">Expires</th>
- <th scope="col">Actions</th>
- </tr>
- </thead>
- <tbody>
- @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && (x.TypedContent as PolicyRuleStateEventData).Entity is not null)) {
- var policyData = policyEvent.TypedContent as PolicyRuleStateEventData;
- <tr>
- @if (_enableAvatars) {
- <td scope="col">
- <img style="width: 48px; height: 48px; aspect-ratio: unset; border-radius: 50%;" src="@(avatars.ContainsKey(policyData.Entity) ? avatars[policyData.Entity] : "")"/>
- </td>
- }
- <td style="word-wrap: anywhere;">Entity: @string.Join("", policyData.Entity.Take(64))<br/>State: @string.Join("", policyEvent.StateKey.Take(64))</td>
- <td>@policyData.Reason</td>
- <td>
- @policyData.ExpiryDateTime
- </td>
- <td>
- <button class="btn btn-danger" @* @onclick="async () => await RemovePolicyAsync(policyEvent)" *@>Remove</button>
- </td>
- </tr>
- }
- </tbody>
- </table>
- <details>
- <summary>Redacted events</summary>
- <table class="table table-striped table-hover" style="width: fit-Content;">
- <thead>
- <tr>
- <th scope="col">State key</th>
- <th scope="col">Serialised Contents</th>
- </tr>
- </thead>
- <tbody>
- @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && (x.TypedContent as PolicyRuleStateEventData).Entity == null)) {
- <tr>
- <td>@policyEvent.StateKey</td>
- <td>@policyEvent.RawContent.ToJson(false, true)</td>
- </tr>
- }
- </tbody>
- </table>
- </details>
-}
-
-<LogView></LogView>
-
-@code {
- //get room list
- // - sync withroom list filter
- // Type = support.feline.msc3784
- //support.feline.policy.lists.msc.v1
-
- [Parameter]
- public string? RoomId { get; set; }
-
- private bool _enableAvatars;
-
- static readonly Dictionary<string, string?> avatars = new();
- static readonly Dictionary<string, RemoteHomeServer> servers = new();
-
- public static List<StateEventResponse> PolicyEvents { get; set; } = new();
-
- protected override async Task OnInitializedAsync() {
- await base.OnInitializedAsync();
- var hs = await MRUStorage.GetCurrentSessionOrNavigate();
- if (hs is null) return;
- RoomId = RoomId.Replace('~', '.');
- await LoadStatesAsync();
- Console.WriteLine("Policy list editor initialized!");
- }
-
- private async Task LoadStatesAsync() {
- var hs = await MRUStorage.GetCurrentSession();
- var room = await hs.GetRoom(RoomId);
-
- var states = room.GetFullStateAsync();
- await foreach (var state in states) {
- if (!state.Type.StartsWith("m.policy.rule")) continue;
- PolicyEvents.Add(state);
- }
-
-
- // var stateEventsQuery = await room.GetStateAsync("");
- // var stateEvents = stateEventsQuery.Value.Deserialize<List<StateEventResponse>>();
- // PolicyEvents = stateEvents.Where(x => x.Type.StartsWith("m.policy.rule"))
- // .Select(x => JsonSerializer.Deserialize<StateEventResponse>(JsonSerializer.Serialize(x))).ToList();
- StateHasChanged();
- }
-
- private async Task GetAvatar(string userId) {
- try {
- if (avatars.ContainsKey(userId)) return;
- var hs = userId.Split(':')[1];
- var server = servers.ContainsKey(hs) ? servers[hs] : new RemoteHomeServer(userId.Split(':')[1]);
- if (!servers.ContainsKey(hs)) servers.Add(hs, server);
- var profile = await server.GetProfile(userId);
- avatars.Add(userId, MediaResolver.ResolveMediaUri(server.FullHomeServerDomain, profile.AvatarUrl));
- servers.Add(userId, server);
- StateHasChanged();
- }
- catch {
- // ignored
- }
- }
-
- private async Task GetAllAvatars() {
- foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && (x.TypedContent as PolicyRuleStateEventData).Entity is not null)) {
- await GetAvatar((policyEvent.TypedContent as PolicyRuleStateEventData).Entity);
- }
- StateHasChanged();
- }
-
-}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor
deleted file mode 100644
index 4db2b5a..0000000
--- a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor
+++ /dev/null
@@ -1,107 +0,0 @@
-@page "/PolicyListEditor"
-@using System.Text.Json.Serialization
-@using MatrixRoomUtils.Core.Interfaces
-@using MatrixRoomUtils.Core.StateEventTypes
-@inject ILocalStorageService LocalStorage
-@inject NavigationManager NavigationManager
-<h3>Policy list editor - Room list</h3>
-<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 style="color: unset; text-decoration: unset;" href="/PolicyListEditor/@s.RoomId.Replace('.', '~')">
- <RoomListItem RoomId="@s.RoomId">
- <br/>
- <span>Shortcode: @s.Shortcode</span>
- </RoomListItem>
- </a>
- @* <a href="@(NavigationManager.Uri + "/" + s.RoomId.Replace('.', '~'))">[@s.Shortcode] @s.Name (@s.RoomId)</a> *@
- @* <br/> *@
- }
-}
-
-<div style="margin-bottom: 4em;"></div>
-<LogView></LogView>
-
-@code {
- //get room list
- // - sync withroom list filter
- // Type = support.feline.msc3784
- //support.feline.policy.lists.msc.v1
-
- public List<PolicyRoomInfo> 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<Task<PolicyRoomInfo?>>();
- 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<PolicyRoomInfo?> 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<MjolnirShortcodeEventData>("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; }
- }
-
-}
\ No newline at end of file
|