From dc3201d641a03e051c6f0db07612eb6b0bb506c3 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Thu, 4 May 2023 15:26:17 +0200 Subject: Dark theme, fancier room list --- MatrixRoomUtils.Web/Pages/DataExportPage.razor | 2 - MatrixRoomUtils.Web/Pages/Index.razor | 1 - MatrixRoomUtils.Web/Pages/LoginPage.razor | 1 - .../Pages/PolicyList/PolicyListEditorPage.razor | 228 ++++++++++++++++++++ .../Pages/PolicyList/PolicyListRoomList.razor | 158 ++++++++++++++ .../Pages/PolicyListEditorPage.razor | 229 --------------------- MatrixRoomUtils.Web/Pages/PolicyListRoomList.razor | 161 --------------- .../Pages/RoomState/RoomStateEditorPage.razor | 170 +++++++++++++++ .../Pages/RoomState/RoomStateRoomList.razor | 36 ++++ .../Pages/RoomState/RoomStateViewerPage.razor | 169 +++++++++++++++ .../Pages/RoomStateEditorPage.razor | 171 --------------- MatrixRoomUtils.Web/Pages/RoomStateRoomList.razor | 96 --------- .../Pages/RoomStateViewerPage.razor | 170 --------------- MatrixRoomUtils.Web/Pages/UserImportPage.razor | 1 - 14 files changed, 761 insertions(+), 832 deletions(-) create mode 100644 MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor create mode 100644 MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor delete mode 100644 MatrixRoomUtils.Web/Pages/PolicyListEditorPage.razor delete mode 100644 MatrixRoomUtils.Web/Pages/PolicyListRoomList.razor create mode 100644 MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor create mode 100644 MatrixRoomUtils.Web/Pages/RoomState/RoomStateRoomList.razor create mode 100644 MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor delete mode 100644 MatrixRoomUtils.Web/Pages/RoomStateEditorPage.razor delete mode 100644 MatrixRoomUtils.Web/Pages/RoomStateRoomList.razor delete mode 100644 MatrixRoomUtils.Web/Pages/RoomStateViewerPage.razor (limited to 'MatrixRoomUtils.Web/Pages') 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

Login

diff --git a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor new file mode 100644 index 0000000..5dfb2d6 --- /dev/null +++ b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor @@ -0,0 +1,228 @@ +@page "/PolicyListEditor/{RoomId}" +@using System.Text.Json +@using MatrixRoomUtils.Core.Extensions +@using MatrixRoomUtils.Core.StateEventTypes +@inject ILocalStorageService LocalStorage +@inject NavigationManager NavigationManager +

Policy list editor - Editing @RoomId

+
+ +

+ 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. +

+ + +@if (!PolicyEvents.Any(x => x.type == "m.policy.rule.server")) +{ +

No server policies

+} +else +{ +

Server policies

+
+ + + + + + + + + + + @foreach (var policyEvent in PolicyEvents.Where(x => x.type == "m.policy.rule.server" && x.content.Entity != null)) + { + + + + + + + } + +
ServerReasonExpiresActions
Entity: @policyEvent.content.Entity
State: @policyEvent.state_key
@policyEvent.content.Reason + @policyEvent.content.ExpiryDateTime + + +
+
+ Invalid events + + + + + + + + + @foreach (var policyEvent in PolicyEvents.Where(x => x.type == "m.policy.rule.server" && x.content.Entity == null)) + { + + + + + } + +
State keySerialised contents
@policyEvent.state_key@policyEvent.content.ToJson(indent: false, ignoreNull: true)
+
+} +@if (!PolicyEvents.Any(x => x.type == "m.policy.rule.room")) +{ +

No room policies

+} +else +{ +

Room policies

+
+ + + + + + + + + + + @foreach (var policyEvent in PolicyEvents.Where(x => x.type == "m.policy.rule.room" && x.content.Entity != null)) + { + + + + + + + } + +
RoomReasonExpiresActions
Entity: @policyEvent.content.Entity
State: @policyEvent.state_key
@policyEvent.content.Reason + @policyEvent.content.ExpiryDateTime + + +
+
+ Invalid events + + + + + + + + + @foreach (var policyEvent in PolicyEvents.Where(x => x.type == "m.policy.rule.room" && x.content.Entity == null)) + { + + + + + } + +
State keySerialised contents
@policyEvent.state_key@policyEvent.content.ToJson(indent: false, ignoreNull: true)
+
+} +@if (!PolicyEvents.Any(x => x.type == "m.policy.rule.user")) +{ +

No user policies

+} +else +{ +

User policies

+
+ + + + + + + + + + + @foreach (var policyEvent in PolicyEvents.Where(x => x.type == "m.policy.rule.user" && x.content.Entity != null)) + { + + + + + + + } + +
UserReasonExpiresActions
Entity: @string.Join("", policyEvent.content.Entity.Take(64))
State: @string.Join("", policyEvent.state_key.Take(64))
@policyEvent.content.Reason + @policyEvent.content.ExpiryDateTime + + +
+
+ Invalid events + + + + + + + + + @foreach (var policyEvent in PolicyEvents.Where(x => x.type == "m.policy.rule.user" && x.content.Entity == null)) + { + + + + + } + +
State keySerialised contents
@policyEvent.state_key@policyEvent.content.ToJson(indent: false, ignoreNull: true)
+
+} + + + +@code { + //get room list + // - sync withroom list filter + // type = support.feline.msc3784 + //support.feline.policy.lists.msc.v1 + + [Parameter] + public string? RoomId { get; set; } + + public List> PolicyEvents { get; set; } = new(); + + protected override async Task OnInitializedAsync() + { + if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); + await base.OnInitializedAsync(); + // if(RuntimeCache.AccessToken == null || RuntimeCache.CurrentHomeserver == null) + if (RuntimeCache.CurrentHomeServer == null) + { + NavigationManager.NavigateTo("/Login"); + return; + } + RoomId = RoomId.Replace('~', '.'); + await LoadStatesAsync(); + Console.WriteLine("Policy list editor initialized!"); + } + + private async Task LoadStatesAsync() + { + // using var client = new HttpClient(); + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalStorageWrapper.AccessToken); + // var response = await client.GetAsync($"{LocalStorageWrapper.CurrentHomeserver}/_matrix/client/r0/rooms/{RoomId}/state"); + // var content = await response.Content.ReadAsStringAsync(); + // Console.WriteLine(JsonSerializer.Deserialize(content).ToJson()); + // var stateEvents = JsonSerializer.Deserialize>(content); + var room = await RuntimeCache.CurrentHomeServer.GetRoom(RoomId); + var stateEventsQuery = await room.GetStateAsync(""); + if (stateEventsQuery == null) + { + Console.WriteLine("state events query is null!!!"); + } + var stateEvents = stateEventsQuery.Value.Deserialize>(); + PolicyEvents = stateEvents.Where(x => x.type.StartsWith("m.policy.rule")) + .Select(x => JsonSerializer.Deserialize>(JsonSerializer.Serialize(x))).ToList(); + StateHasChanged(); + } + +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor new file mode 100644 index 0000000..5656af9 --- /dev/null +++ b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor @@ -0,0 +1,158 @@ +@page "/PolicyListEditor" +@using System.Text.Json +@using MatrixRoomUtils.Core.Extensions +@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) + { + [@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; } = 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 xxxrooms = await RuntimeCache.CurrentHomeServer.GetJoinedRooms(); + totalRoomCount = xxxrooms.Count; + StateHasChanged(); + + var xxxsemaphore = new SemaphoreSlim(256); + var xxxtasks = new List>(); + foreach (var room in xxxrooms) + { + xxxtasks.Add(GetPolicyRoomInfo(room.RoomId, xxxsemaphore)); + } + var xxxresults = await Task.WhenAll(xxxtasks); + PolicyRoomList.AddRange(xxxresults.Where(x => x != null).Select(x => x.Value)); + + 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(); + 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>(); + 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 GetPolicyRoomInfo(string room, SemaphoreSlim semaphore) + { + try + { + //TODO: refactor!!!!! + await semaphore.WaitAsync(); + PolicyRoomInfo roomInfo = new() + { + RoomId = room + }; + + + // --- // + var r = await RuntimeCache.CurrentHomeServer.GetRoom(room); + var shortcodeState = await r.GetStateAsync("org.matrix.mjolnir.shortcode"); + if(!shortcodeState.HasValue) return null; + roomInfo.Shortcode = shortcodeState.Value.TryGetProperty("shortcode", out JsonElement shortcode) ? shortcode.GetString() : null; + + if (roomInfo.Shortcode != 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 diff --git a/MatrixRoomUtils.Web/Pages/PolicyListEditorPage.razor b/MatrixRoomUtils.Web/Pages/PolicyListEditorPage.razor deleted file mode 100644 index 66a5c9f..0000000 --- a/MatrixRoomUtils.Web/Pages/PolicyListEditorPage.razor +++ /dev/null @@ -1,229 +0,0 @@ -@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 -

Policy list editor

- -

- 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. -

- - -@if (!PolicyEvents.Any(x => x.type == "m.policy.rule.server")) -{ -

No server policies

-} -else -{ -

Server policies

-
- - - - - - - - - - - @foreach (var policyEvent in PolicyEvents.Where(x => x.type == "m.policy.rule.server" && x.content.Entity != null)) - { - - - - - - - } - -
ServerReasonExpiresActions
Entity: @policyEvent.content.Entity
State: @policyEvent.state_key
@policyEvent.content.Reason - @policyEvent.content.ExpiryDateTime - - -
-
- Invalid events - - - - - - - - - @foreach (var policyEvent in PolicyEvents.Where(x => x.type == "m.policy.rule.server" && x.content.Entity == null)) - { - - - - - } - -
State keySerialised contents
@policyEvent.state_key@policyEvent.content.ToJson(indent: false, ignoreNull: true)
-
-} -@if (!PolicyEvents.Any(x => x.type == "m.policy.rule.room")) -{ -

No room policies

-} -else -{ -

Room policies

-
- - - - - - - - - - - @foreach (var policyEvent in PolicyEvents.Where(x => x.type == "m.policy.rule.room" && x.content.Entity != null)) - { - - - - - - - } - -
RoomReasonExpiresActions
Entity: @policyEvent.content.Entity
State: @policyEvent.state_key
@policyEvent.content.Reason - @policyEvent.content.ExpiryDateTime - - -
-
- Invalid events - - - - - - - - - @foreach (var policyEvent in PolicyEvents.Where(x => x.type == "m.policy.rule.room" && x.content.Entity == null)) - { - - - - - } - -
State keySerialised contents
@policyEvent.state_key@policyEvent.content.ToJson(indent: false, ignoreNull: true)
-
-} -@if (!PolicyEvents.Any(x => x.type == "m.policy.rule.user")) -{ -

No user policies

-} -else -{ -

User policies

-
- - - - - - - - - - - @foreach (var policyEvent in PolicyEvents.Where(x => x.type == "m.policy.rule.user" && x.content.Entity != null)) - { - - - - - - - } - -
UserReasonExpiresActions
Entity: @string.Join("", policyEvent.content.Entity.Take(64))
State: @string.Join("", policyEvent.state_key.Take(64))
@policyEvent.content.Reason - @policyEvent.content.ExpiryDateTime - - -
-
- Invalid events - - - - - - - - - @foreach (var policyEvent in PolicyEvents.Where(x => x.type == "m.policy.rule.user" && x.content.Entity == null)) - { - - - - - } - -
State keySerialised contents
@policyEvent.state_key@policyEvent.content.ToJson(indent: false, ignoreNull: true)
-
-} - - - -@code { - //get room list - // - sync withroom list filter - // type = support.feline.msc3784 - //support.feline.policy.lists.msc.v1 - - [Parameter] - public string? RoomId { get; set; } - - public List> PolicyEvents { get; set; } = new(); - - protected override async Task OnInitializedAsync() - { - if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); - await base.OnInitializedAsync(); - // if(RuntimeCache.AccessToken == null || RuntimeCache.CurrentHomeserver == null) - if (RuntimeCache.CurrentHomeServer == null) - { - NavigationManager.NavigateTo("/Login"); - return; - } - RoomId = RoomId.Replace('~', '.'); - await LoadStatesAsync(); - Console.WriteLine("Policy list editor initialized!"); - } - - private async Task LoadStatesAsync() - { - // using var client = new HttpClient(); - // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalStorageWrapper.AccessToken); - // var response = await client.GetAsync($"{LocalStorageWrapper.CurrentHomeserver}/_matrix/client/r0/rooms/{RoomId}/state"); - // var content = await response.Content.ReadAsStringAsync(); - // Console.WriteLine(JsonSerializer.Deserialize(content).ToJson()); - // var stateEvents = JsonSerializer.Deserialize>(content); - var room = await RuntimeCache.CurrentHomeServer.GetRoom(RoomId); - var stateEventsQuery = await room.GetStateAsync(""); - if (stateEventsQuery == null) - { - Console.WriteLine("state events query is null!!!"); - } - var stateEvents = stateEventsQuery.Value.Deserialize>(); - PolicyEvents = stateEvents.Where(x => x.type.StartsWith("m.policy.rule")) - .Select(x => JsonSerializer.Deserialize>(JsonSerializer.Serialize(x))).ToList(); - StateHasChanged(); - } - -} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Pages/PolicyListRoomList.razor b/MatrixRoomUtils.Web/Pages/PolicyListRoomList.razor deleted file mode 100644 index 3af60b7..0000000 --- a/MatrixRoomUtils.Web/Pages/PolicyListRoomList.razor +++ /dev/null @@ -1,161 +0,0 @@ -@page "/PolicyListEditor" -@using System.Net.Http.Headers -@using System.Text.Json -@using MatrixRoomUtils.Core -@using MatrixRoomUtils.Core.Extensions -@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) - { - [@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; } = 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 xxxrooms = await RuntimeCache.CurrentHomeServer.GetJoinedRooms(); - totalRoomCount = xxxrooms.Count; - StateHasChanged(); - - var xxxsemaphore = new SemaphoreSlim(256); - var xxxtasks = new List>(); - foreach (var room in xxxrooms) - { - xxxtasks.Add(GetPolicyRoomInfo(room.RoomId, xxxsemaphore)); - } - var xxxresults = await Task.WhenAll(xxxtasks); - PolicyRoomList.AddRange(xxxresults.Where(x => x != null).Select(x => x.Value)); - - 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(); - 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>(); - 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 GetPolicyRoomInfo(string room, SemaphoreSlim semaphore) - { - try - { - //TODO: refactor!!!!! - await semaphore.WaitAsync(); - PolicyRoomInfo roomInfo = new() - { - RoomId = room - }; - - - // --- // - var r = await RuntimeCache.CurrentHomeServer.GetRoom(room); - var shortcodeState = await r.GetStateAsync("org.matrix.mjolnir.shortcode"); - if(!shortcodeState.HasValue) return null; - roomInfo.Shortcode = shortcodeState.Value.TryGetProperty("shortcode", out JsonElement shortcode) ? shortcode.GetString() : null; - - if (roomInfo.Shortcode != 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 diff --git a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor new file mode 100644 index 0000000..638d728 --- /dev/null +++ b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor @@ -0,0 +1,170 @@ +@page "/RoomStateViewer/{RoomId}/Edit" +@using System.Net.Http.Headers +@using System.Text.Json +@inject ILocalStorageService LocalStorage +@inject NavigationManager NavigationManager +

Room state editor - Editing @RoomId

+
+ +

@status

+ + Show member events +
+ + + @foreach (var stateEvent in FilteredEvents.Where(x => x.state_key != "").Select(x => x.state_key).Distinct().OrderBy(x => x)) + { + + Console.WriteLine(stateEvent); + } + +
+ + + @foreach (var stateEvent in FilteredEvents.Where(x => x.state_key != shownStateKey).Select(x => x.type).Distinct().OrderBy(x => x)) + { + + } + +
+ + + + + +@code { + //get room list + // - sync withroom list filter + // type = support.feline.msc3784 + //support.feline.policy.lists.msc.v1 + + [Parameter] + public string? RoomId { get; set; } + + public List FilteredEvents { get; set; } = new(); + public List Events { get; set; } = new(); + public string status = ""; + + protected override async Task OnInitializedAsync() + { + if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); + await base.OnInitializedAsync(); + if (RuntimeCache.CurrentHomeServer != null) + { + NavigationManager.NavigateTo("/Login"); + return; + } + RoomId = RoomId.Replace('~', '.'); + await LoadStatesAsync(); + Console.WriteLine("Policy list editor initialized!"); + } + + private DateTime _lastUpdate = DateTime.Now; + + private async Task LoadStatesAsync() + { + int StateLoaded = 0; + using var client = new HttpClient(); + //TODO: can this be improved? + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", RuntimeCache.CurrentHomeServer.AccessToken); + var response = await client.GetAsync($"{RuntimeCache.CurrentHomeServer.FullHomeServerDomain}/_matrix/client/r0/rooms/{RoomId}/state"); + // var response = await client.GetAsync($"http://localhost:5117/matrix-hq-state.json"); + //var _events = await response.Content.ReadFromJsonAsync>(); + var _data = await response.Content.ReadAsStreamAsync(); + var __events = JsonSerializer.DeserializeAsyncEnumerable(_data); + await foreach (var _ev in __events) + { + var e = new StateEvent() + { + type = _ev.type, + state_key = _ev.state_key, + origin_server_ts = _ev.origin_server_ts, + content = _ev.content + }; + Events.Add(e); + if (string.IsNullOrEmpty(e.state_key)) + { + FilteredEvents.Add(e); + } + StateLoaded++; + if ((DateTime.Now - _lastUpdate).TotalMilliseconds > 100) + { + _lastUpdate = DateTime.Now; + status = $"Loaded {StateLoaded} state events"; + StateHasChanged(); + await Task.Delay(0); + } + } + + StateHasChanged(); + } + + private async Task RebuildFilteredData() + { + status = "Rebuilding filtered data..."; + StateHasChanged(); + await Task.Delay(1); + var _FilteredEvents = Events; + if (!ShowMembershipEvents) + _FilteredEvents = _FilteredEvents.Where(x => x.type != "m.room.member").ToList(); + + status = "Done, rerendering!"; + StateHasChanged(); + await Task.Delay(1); + FilteredEvents = _FilteredEvents; + + if(_shownType != null) + shownEventJson = _FilteredEvents.Where(x => x.type == _shownType).First().content.ToJson(indent: true, ignoreNull: true); + + StateHasChanged(); + } + + + public struct PreRenderedStateEvent + { + public string content { get; set; } + public long origin_server_ts { get; set; } + public string state_key { get; set; } + public string type { get; set; } + // public string sender { get; set; } + // public string event_id { get; set; } + // public string user_id { get; set; } + // public string replaces_state { get; set; } + } + + public bool ShowMembershipEvents + { + get => _showMembershipEvents; + set + { + _showMembershipEvents = value; + RebuildFilteredData(); + } + } + + private bool _showMembershipEvents; + private string _shownStateKey; + private string _shownType; + + private string shownStateKey + { + get => _shownStateKey; + set + { + _shownStateKey = value; + RebuildFilteredData(); + } + } + + private string shownType + { + get => _shownType; + set + { + _shownType = value; + RebuildFilteredData(); + } + } + + private string shownEventJson { get; set; } +} \ No newline at end of file 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 +

Room state viewer - Room list

+
+@if (Rooms.Count == 0) +{ +

You are not in any rooms!

+ @*

Loading progress: @checkedRoomCount/@totalRoomCount

*@ +} +else +{ + @foreach (var room in Rooms) + { + + } +
+} + + + +@code { + public List 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/RoomState/RoomStateViewerPage.razor b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor new file mode 100644 index 0000000..0f40cb9 --- /dev/null +++ b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor @@ -0,0 +1,169 @@ +@page "/RoomStateViewer/{RoomId}" +@using System.Net.Http.Headers +@using System.Text.Json +@using MatrixRoomUtils.Core.Extensions +@inject ILocalStorageService LocalStorage +@inject NavigationManager NavigationManager +

Room state viewer - Viewing @RoomId

+
+ +

@status

+ + Show member events + + + + + + + + + + @foreach (var stateEvent in FilteredEvents.Where(x => x.state_key == "").OrderBy(x => x.origin_server_ts)) + { + + + + + } + +
TypeContent
@stateEvent.type +
@stateEvent.content
+
+ +@foreach (var group in FilteredEvents.GroupBy(x => x.state_key).OrderBy(x => x.Key).Where(x => x.Key != "")) +{ +
+ @group.Key + + + + + + + + + @foreach (var stateEvent in group.OrderBy(x => x.origin_server_ts)) + { + + + + + } + +
TypeContent
@stateEvent.type +
@stateEvent.content
+
+
+} + + + +@code { + //get room list + // - sync withroom list filter + // type = support.feline.msc3784 + //support.feline.policy.lists.msc.v1 + + [Parameter] + public string? RoomId { get; set; } + + public List FilteredEvents { get; set; } = new(); + public List Events { get; set; } = new(); + public string status = ""; + + protected override async Task OnInitializedAsync() + { + if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); + await base.OnInitializedAsync(); + if (RuntimeCache.CurrentHomeServer == null) + { + NavigationManager.NavigateTo("/Login"); + return; + } + RoomId = RoomId.Replace('~', '.'); + await LoadStatesAsync(); + Console.WriteLine("Policy list editor initialized!"); + } + private DateTime _lastUpdate = DateTime.Now; + + private async Task LoadStatesAsync() + { + int StateLoaded = 0; + //TODO: can we improve this? + using var client = new HttpClient(); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", RuntimeCache.CurrentHomeServer.AccessToken); + var response = await client.GetAsync($"{RuntimeCache.CurrentHomeServer.FullHomeServerDomain}/_matrix/client/r0/rooms/{RoomId}/state"); + // var response = await client.GetAsync($"http://localhost:5117/matrix-hq-state.json"); + //var _events = await response.Content.ReadFromJsonAsync>(); + var _data = await response.Content.ReadAsStreamAsync(); + var __events = JsonSerializer.DeserializeAsyncEnumerable(_data); + await foreach (var _ev in __events) + { + var e = new PreRenderedStateEvent() + { + type = _ev.type, + state_key = _ev.state_key, + origin_server_ts = _ev.origin_server_ts, + content = _ev.content.ToJson(indent: true, ignoreNull: true), + }; + Events.Add(e); + if (string.IsNullOrEmpty(e.state_key)) + { + FilteredEvents.Add(e); + } + StateLoaded++; + if ((DateTime.Now - _lastUpdate).TotalMilliseconds > 100) + { + _lastUpdate = DateTime.Now; + status = $"Loaded {StateLoaded} state events"; + StateHasChanged(); + await Task.Delay(0); + } + + } + + StateHasChanged(); + } + + private async Task RebuildFilteredData() + { + status = "Rebuilding filtered data..."; + StateHasChanged(); + await Task.Delay(1); + var _FilteredEvents = Events; + if (!ShowMembershipEvents) + _FilteredEvents = _FilteredEvents.Where(x => x.type != "m.room.member").ToList(); + + status = "Done, rerendering!"; + StateHasChanged(); + await Task.Delay(1); + FilteredEvents = _FilteredEvents; + StateHasChanged(); + } + + + public struct PreRenderedStateEvent + { + public string content { get; set; } + public long origin_server_ts { get; set; } + public string state_key { get; set; } + public string type { get; set; } + // public string sender { get; set; } + // public string event_id { get; set; } + // public string user_id { get; set; } + // public string replaces_state { get; set; } + } + + public bool ShowMembershipEvents + { + get => _showMembershipEvents; + set + { + _showMembershipEvents = value; + RebuildFilteredData(); + } + } + + private bool _showMembershipEvents; +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Pages/RoomStateEditorPage.razor b/MatrixRoomUtils.Web/Pages/RoomStateEditorPage.razor deleted file mode 100644 index 47f2aba..0000000 --- a/MatrixRoomUtils.Web/Pages/RoomStateEditorPage.razor +++ /dev/null @@ -1,171 +0,0 @@ -@page "/RoomStateViewer/{RoomId}/Edit" -@using System.Net.Http.Headers -@using System.Text.Json -@using MatrixRoomUtils.Core -@inject ILocalStorageService LocalStorage -@inject NavigationManager NavigationManager -

Room state editor

-

Room ID: @RoomId

- -

@status

- - Show member events -
- - - @foreach (var stateEvent in FilteredEvents.Where(x => x.state_key != "").Select(x => x.state_key).Distinct().OrderBy(x => x)) - { - - Console.WriteLine(stateEvent); - } - -
- - - @foreach (var stateEvent in FilteredEvents.Where(x => x.state_key != shownStateKey).Select(x => x.type).Distinct().OrderBy(x => x)) - { - - } - -
- - - - - -@code { - //get room list - // - sync withroom list filter - // type = support.feline.msc3784 - //support.feline.policy.lists.msc.v1 - - [Parameter] - public string? RoomId { get; set; } - - public List FilteredEvents { get; set; } = new(); - public List Events { get; set; } = new(); - public string status = ""; - - protected override async Task OnInitializedAsync() - { - if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); - await base.OnInitializedAsync(); - if (RuntimeCache.CurrentHomeServer != null) - { - NavigationManager.NavigateTo("/Login"); - return; - } - RoomId = RoomId.Replace('~', '.'); - await LoadStatesAsync(); - Console.WriteLine("Policy list editor initialized!"); - } - - private DateTime _lastUpdate = DateTime.Now; - - private async Task LoadStatesAsync() - { - int StateLoaded = 0; - using var client = new HttpClient(); - //TODO: can this be improved? - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", RuntimeCache.CurrentHomeServer.AccessToken); - var response = await client.GetAsync($"{RuntimeCache.CurrentHomeServer.FullHomeServerDomain}/_matrix/client/r0/rooms/{RoomId}/state"); - // var response = await client.GetAsync($"http://localhost:5117/matrix-hq-state.json"); - //var _events = await response.Content.ReadFromJsonAsync>(); - var _data = await response.Content.ReadAsStreamAsync(); - var __events = JsonSerializer.DeserializeAsyncEnumerable(_data); - await foreach (var _ev in __events) - { - var e = new StateEvent() - { - type = _ev.type, - state_key = _ev.state_key, - origin_server_ts = _ev.origin_server_ts, - content = _ev.content - }; - Events.Add(e); - if (string.IsNullOrEmpty(e.state_key)) - { - FilteredEvents.Add(e); - } - StateLoaded++; - if ((DateTime.Now - _lastUpdate).TotalMilliseconds > 100) - { - _lastUpdate = DateTime.Now; - status = $"Loaded {StateLoaded} state events"; - StateHasChanged(); - await Task.Delay(0); - } - } - - StateHasChanged(); - } - - private async Task RebuildFilteredData() - { - status = "Rebuilding filtered data..."; - StateHasChanged(); - await Task.Delay(1); - var _FilteredEvents = Events; - if (!ShowMembershipEvents) - _FilteredEvents = _FilteredEvents.Where(x => x.type != "m.room.member").ToList(); - - status = "Done, rerendering!"; - StateHasChanged(); - await Task.Delay(1); - FilteredEvents = _FilteredEvents; - - if(_shownType != null) - shownEventJson = _FilteredEvents.Where(x => x.type == _shownType).First().content.ToJson(indent: true, ignoreNull: true); - - StateHasChanged(); - } - - - public struct PreRenderedStateEvent - { - public string content { get; set; } - public long origin_server_ts { get; set; } - public string state_key { get; set; } - public string type { get; set; } - // public string sender { get; set; } - // public string event_id { get; set; } - // public string user_id { get; set; } - // public string replaces_state { get; set; } - } - - public bool ShowMembershipEvents - { - get => _showMembershipEvents; - set - { - _showMembershipEvents = value; - RebuildFilteredData(); - } - } - - private bool _showMembershipEvents; - private string _shownStateKey; - private string _shownType; - - private string shownStateKey - { - get => _shownStateKey; - set - { - _shownStateKey = value; - RebuildFilteredData(); - } - } - - private string shownType - { - get => _shownType; - set - { - _shownType = value; - RebuildFilteredData(); - } - } - - private string shownEventJson { get; set; } -} \ No newline at end of file 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 -

Room state viewer

- -
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) - { - @s.Name (@s.RoomId) -
- } -
-} - - - -@code { - - public List 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>(); - 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 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/RoomStateViewerPage.razor b/MatrixRoomUtils.Web/Pages/RoomStateViewerPage.razor deleted file mode 100644 index 199c75b..0000000 --- a/MatrixRoomUtils.Web/Pages/RoomStateViewerPage.razor +++ /dev/null @@ -1,170 +0,0 @@ -@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 -

Room state viewer

-

Room ID: @RoomId

- -

@status

- - Show member events - - - - - - - - - - @foreach (var stateEvent in FilteredEvents.Where(x => x.state_key == "").OrderBy(x => x.origin_server_ts)) - { - - - - - } - -
TypeContent
@stateEvent.type -
@stateEvent.content
-
- -@foreach (var group in FilteredEvents.GroupBy(x => x.state_key).OrderBy(x => x.Key).Where(x => x.Key != "")) -{ -
- @group.Key - - - - - - - - - @foreach (var stateEvent in group.OrderBy(x => x.origin_server_ts)) - { - - - - - } - -
TypeContent
@stateEvent.type -
@stateEvent.content
-
-
-} - - - -@code { - //get room list - // - sync withroom list filter - // type = support.feline.msc3784 - //support.feline.policy.lists.msc.v1 - - [Parameter] - public string? RoomId { get; set; } - - public List FilteredEvents { get; set; } = new(); - public List Events { get; set; } = new(); - public string status = ""; - - protected override async Task OnInitializedAsync() - { - if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); - await base.OnInitializedAsync(); - if (RuntimeCache.CurrentHomeServer == null) - { - NavigationManager.NavigateTo("/Login"); - return; - } - RoomId = RoomId.Replace('~', '.'); - await LoadStatesAsync(); - Console.WriteLine("Policy list editor initialized!"); - } - private DateTime _lastUpdate = DateTime.Now; - - private async Task LoadStatesAsync() - { - int StateLoaded = 0; - //TODO: can we improve this? - using var client = new HttpClient(); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", RuntimeCache.CurrentHomeServer.AccessToken); - var response = await client.GetAsync($"{RuntimeCache.CurrentHomeServer.FullHomeServerDomain}/_matrix/client/r0/rooms/{RoomId}/state"); - // var response = await client.GetAsync($"http://localhost:5117/matrix-hq-state.json"); - //var _events = await response.Content.ReadFromJsonAsync>(); - var _data = await response.Content.ReadAsStreamAsync(); - var __events = JsonSerializer.DeserializeAsyncEnumerable(_data); - await foreach (var _ev in __events) - { - var e = new PreRenderedStateEvent() - { - type = _ev.type, - state_key = _ev.state_key, - origin_server_ts = _ev.origin_server_ts, - content = _ev.content.ToJson(indent: true, ignoreNull: true), - }; - Events.Add(e); - if (string.IsNullOrEmpty(e.state_key)) - { - FilteredEvents.Add(e); - } - StateLoaded++; - if ((DateTime.Now - _lastUpdate).TotalMilliseconds > 100) - { - _lastUpdate = DateTime.Now; - status = $"Loaded {StateLoaded} state events"; - StateHasChanged(); - await Task.Delay(0); - } - - } - - StateHasChanged(); - } - - private async Task RebuildFilteredData() - { - status = "Rebuilding filtered data..."; - StateHasChanged(); - await Task.Delay(1); - var _FilteredEvents = Events; - if (!ShowMembershipEvents) - _FilteredEvents = _FilteredEvents.Where(x => x.type != "m.room.member").ToList(); - - status = "Done, rerendering!"; - StateHasChanged(); - await Task.Delay(1); - FilteredEvents = _FilteredEvents; - StateHasChanged(); - } - - - public struct PreRenderedStateEvent - { - public string content { get; set; } - public long origin_server_ts { get; set; } - public string state_key { get; set; } - public string type { get; set; } - // public string sender { get; set; } - // public string event_id { get; set; } - // public string user_id { get; set; } - // public string replaces_state { get; set; } - } - - public bool ShowMembershipEvents - { - get => _showMembershipEvents; - set - { - _showMembershipEvents = value; - RebuildFilteredData(); - } - } - - private bool _showMembershipEvents; -} \ 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

Login

-- cgit 1.5.1