From e10fa389ce3c4d42deadfec8bf08c2fbb1a88d79 Mon Sep 17 00:00:00 2001 From: "Emma@Rory&" Date: Fri, 15 Sep 2023 09:55:36 +0200 Subject: Refactors --- MatrixRoomUtils.Web/Pages/About.razor | 1 - MatrixRoomUtils.Web/Pages/DebugTools.razor | 6 +- MatrixRoomUtils.Web/Pages/DevOptions.razor | 1 + MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor | 22 ++-- MatrixRoomUtils.Web/Pages/Index.razor | 55 ++++++---- MatrixRoomUtils.Web/Pages/Index.razor.css | 25 +++++ MatrixRoomUtils.Web/Pages/InvalidSession.razor | 7 +- .../Pages/KnownHomeserverList.razor | 8 +- MatrixRoomUtils.Web/Pages/LoginPage.razor | 56 ++++++---- MatrixRoomUtils.Web/Pages/MediaLocator.razor | 1 + MatrixRoomUtils.Web/Pages/ModalTest.razor | 4 +- MatrixRoomUtils.Web/Pages/Rooms/Create.razor | 22 ++-- MatrixRoomUtils.Web/Pages/Rooms/Index.razor | 10 +- MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor | 28 ++--- MatrixRoomUtils.Web/Pages/Rooms/Space.razor | 2 +- MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor | 3 +- MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor | 3 +- MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor | 8 +- MatrixRoomUtils.Web/Pages/SpaceDebug.razor | 114 +++++++++++++++++++++ 19 files changed, 277 insertions(+), 99 deletions(-) create mode 100644 MatrixRoomUtils.Web/Pages/Index.razor.css create mode 100644 MatrixRoomUtils.Web/Pages/SpaceDebug.razor (limited to 'MatrixRoomUtils.Web/Pages') diff --git a/MatrixRoomUtils.Web/Pages/About.razor b/MatrixRoomUtils.Web/Pages/About.razor index 48c7686..17ed04a 100644 --- a/MatrixRoomUtils.Web/Pages/About.razor +++ b/MatrixRoomUtils.Web/Pages/About.razor @@ -1,6 +1,5 @@ @page "/About" @using System.Net -@using System.Net.Sockets @inject NavigationManager NavigationManager @inject ILocalStorageService LocalStorage diff --git a/MatrixRoomUtils.Web/Pages/DebugTools.razor b/MatrixRoomUtils.Web/Pages/DebugTools.razor index afb1da2..5d47277 100644 --- a/MatrixRoomUtils.Web/Pages/DebugTools.razor +++ b/MatrixRoomUtils.Web/Pages/DebugTools.razor @@ -1,7 +1,9 @@ @page "/Debug" @using System.Reflection +@using ArcaneLibs.Extensions +@using LibMatrix @using LibMatrix.Extensions -@using LibMatrix.Interfaces +@using LibMatrix.Homeservers @inject ILocalStorageService LocalStorage @inject NavigationManager NavigationManager

Debug Tools

@@ -50,7 +52,7 @@ else { string get_request_result { get; set; } = ""; private async Task SendGetRequest() { - var field = typeof(IHomeServer).GetRuntimeFields().First(x => x.ToString().Contains("<_httpClient>k__BackingField")); + var field = typeof(RemoteHomeServer).GetRuntimeFields().First(x => x.ToString().Contains("<_httpClient>k__BackingField")); var hs = await MRUStorage.GetCurrentSessionOrNavigate(); if (hs == null) return; var httpClient = field.GetValue(hs) as MatrixHttpClient; diff --git a/MatrixRoomUtils.Web/Pages/DevOptions.razor b/MatrixRoomUtils.Web/Pages/DevOptions.razor index bf499a3..8511a26 100644 --- a/MatrixRoomUtils.Web/Pages/DevOptions.razor +++ b/MatrixRoomUtils.Web/Pages/DevOptions.razor @@ -1,5 +1,6 @@ @page "/DevOptions" @using LibMatrix.Extensions +@using ArcaneLibs.Extensions @inject NavigationManager NavigationManager @inject ILocalStorageService LocalStorage diff --git a/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor b/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor index 679f324..a4f9d97 100644 --- a/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor +++ b/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor @@ -1,8 +1,10 @@ @page "/HSAdmin/RoomQuery" -@using MatrixRoomUtils.Web.Shared.SimpleComponents @using LibMatrix.Responses.Admin @using LibMatrix.Filters @using LibMatrix.Extensions +@using LibMatrix +@using LibMatrix.Homeservers +@using ArcaneLibs.Extensions

Homeserver Administration - Room Query

@@ -168,15 +170,17 @@ private async Task Search() { Results.Clear(); var hs = await MRUStorage.GetCurrentSessionOrNavigate(); - if (hs is null) return; - var searchRooms = hs.Admin.SearchRoomsAsync(orderBy: OrderBy!, dir: Ascending ? "f" : "b", searchTerm: SearchTerm, localFilter: Filter).GetAsyncEnumerator(); - while (await searchRooms.MoveNextAsync()) { - var room = searchRooms.Current; - Console.WriteLine("Hit: " + room.ToJson(false)); - Results.Add(room); - if (Results.Count % 10 == 0) - StateHasChanged(); + if (hs is AuthenticatedHomeserverSynapse synapse) { + var searchRooms = synapse.Admin.SearchRoomsAsync(orderBy: OrderBy!, dir: Ascending ? "f" : "b", searchTerm: SearchTerm, localFilter: Filter).GetAsyncEnumerator(); + while (await searchRooms.MoveNextAsync()) { + var room = searchRooms.Current; + Console.WriteLine("Hit: " + room.ToJson(false)); + Results.Add(room); + if (Results.Count % 10 == 0) + StateHasChanged(); + } } + } private readonly Dictionary validOrderBy = new() { diff --git a/MatrixRoomUtils.Web/Pages/Index.razor b/MatrixRoomUtils.Web/Pages/Index.razor index 1004ee3..e02c733 100644 --- a/MatrixRoomUtils.Web/Pages/Index.razor +++ b/MatrixRoomUtils.Web/Pages/Index.razor @@ -1,8 +1,9 @@ @page "/" -@using MatrixRoomUtils.Web.Shared.SimpleComponents @using LibMatrix.Responses @using LibMatrix @using LibMatrix.Helpers +@using LibMatrix.Homeservers +@using ArcaneLibs.Extensions Index @@ -13,25 +14,38 @@ Small collection of tools to do not-so-everyday things.
Signed in accounts - Add new account

- @foreach (var (auth, user) in _users.OrderByDescending(x=>x.Value.RoomCount)) { - var _auth = auth; -
- -

- - @user.DisplayName on @_auth.Homeserver - Remove + + @foreach (var (auth, user) in _users.OrderByDescending(x => x.Value.RoomCount)) { + var _auth = auth; + + + + + @* *@ + + } +
+ + +

+ Manage + Remove +

+

@code { - private Dictionary _users = new(); + private Dictionary _users = new(); protected override async Task OnInitializedAsync() { _currentSession = await MRUStorage.GetCurrentToken(); @@ -39,13 +53,13 @@ Small collection of tools to do not-so-everyday things. var tokens = await MRUStorage.GetAllTokens(); var profileTasks = tokens.Select(async token => { UserInfo userInfo = new(); - AuthenticatedHomeServer hs; + AuthenticatedHomeserverGeneric hs; try { hs = await HomeserverProvider.GetAuthenticatedWithToken(token.Homeserver, token.AccessToken); } catch (MatrixException e) { if (e.ErrorCode == "M_UNKNOWN_TOKEN") { - NavigationManager.NavigateTo("/InvalidSession?ctx="+token.AccessToken); + NavigationManager.NavigateTo("/InvalidSession?ctx=" + token.AccessToken); return; } throw; @@ -53,6 +67,7 @@ Small collection of tools to do not-so-everyday things. var roomCountTask = hs.GetJoinedRooms(); var profile = await hs.GetProfile(hs.WhoAmI.UserId); userInfo.DisplayName = profile.DisplayName ?? hs.WhoAmI.UserId; + Console.WriteLine(profile.ToJson()); userInfo.AvatarUrl = MediaResolver.ResolveMediaUri(hs.FullHomeServerDomain, profile.AvatarUrl ?? "https://api.dicebear.com/6.x/identicon/svg?seed=" + hs.WhoAmI.UserId @@ -71,7 +86,7 @@ Small collection of tools to do not-so-everyday things. internal int RoomCount { get; set; } } - private async Task RemoveUser(LoginResponse auth) { + private async Task RemoveUser(UserAuth auth) { await MRUStorage.RemoveToken(auth); if ((await MRUStorage.GetCurrentToken()).AccessToken == auth.AccessToken) MRUStorage.SetCurrentToken((await MRUStorage.GetAllTokens()).FirstOrDefault()); @@ -80,8 +95,8 @@ Small collection of tools to do not-so-everyday things. private LoginResponse _currentSession; - private async Task SwitchSession(LoginResponse auth) { - Console.WriteLine($"Switching to {auth.Homeserver} {auth.AccessToken} {auth.UserId}"); + private async Task SwitchSession(UserAuth auth) { + Console.WriteLine($"Switching to {auth.Homeserver} {auth.UserId} via {auth.Proxy}"); await MRUStorage.SetCurrentToken(auth); await OnInitializedAsync(); } diff --git a/MatrixRoomUtils.Web/Pages/Index.razor.css b/MatrixRoomUtils.Web/Pages/Index.razor.css new file mode 100644 index 0000000..c6b7bd7 --- /dev/null +++ b/MatrixRoomUtils.Web/Pages/Index.razor.css @@ -0,0 +1,25 @@ +.user-entry { + margin-bottom: 1em; +} + +.avatar { + width: 4em; + height: 4em; + border-radius: 50%; + margin-right: 0.5em; + vertical-align: middle; +} + +.user-entry > td { + margin-right: 0.5em; + vertical-align: middle; +} + +.user-info { + margin-bottom: 0.5em; + display: inline-block; + vertical-align: middle; +} +.user-info > p { + margin: 0; +} diff --git a/MatrixRoomUtils.Web/Pages/InvalidSession.razor b/MatrixRoomUtils.Web/Pages/InvalidSession.razor index f555be5..310abb1 100644 --- a/MatrixRoomUtils.Web/Pages/InvalidSession.razor +++ b/MatrixRoomUtils.Web/Pages/InvalidSession.razor @@ -1,5 +1,4 @@ @page "/InvalidSession" -@using MatrixRoomUtils.Web.Shared.SimpleComponents @using LibMatrix.Responses @using LibMatrix @@ -33,7 +32,7 @@ else { [SupplyParameterFromQuery(Name = "ctx")] public string Context { get; set; } - private LoginResponse? _login { get; set; } + private UserAuth? _login { get; set; } private bool _showRefreshDialog { get; set; } @@ -70,7 +69,7 @@ else { await Task.CompletedTask; } - private async Task SwitchSession(LoginResponse auth) { + private async Task SwitchSession(UserAuth auth) { Console.WriteLine($"Switching to {auth.Homeserver} {auth.AccessToken} {auth.UserId}"); await MRUStorage.SetCurrentToken(auth); await OnInitializedAsync(); @@ -79,7 +78,7 @@ else { private async Task TryLogin() { if(_login is null) throw new NullReferenceException("Login is null!"); try { - var result = await HomeserverProvider.Login(_login.Homeserver, _login.UserId, _password); + var result = new UserAuth(await HomeserverProvider.Login(_login.Homeserver, _login.UserId, _password)); if (result is null) { Console.WriteLine($"Failed to login to {_login.Homeserver} as {_login.UserId}!"); return; diff --git a/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor b/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor index 22a004d..4cd2032 100644 --- a/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor +++ b/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor @@ -1,10 +1,10 @@ @page "/KnownHomeserverList" -@using System.Text.Json @using System.Diagnostics +@using ArcaneLibs.Extensions @using LibMatrix @using LibMatrix.Extensions +@using LibMatrix.Homeservers @using LibMatrix.RoomTypes -@using LibMatrix.StateEventTypes

Known Homeserver List


@@ -36,7 +36,7 @@ else { List HomeServers = new(); bool IsFinished { get; set; } HomeServerInfoQueryProgress QueryProgress { get; set; } = new(); - AuthenticatedHomeServer hs { get; set; } + AuthenticatedHomeserverGeneric hs { get; set; } protected override async Task OnInitializedAsync() { hs = await MRUStorage.GetCurrentSessionOrNavigate(); if (hs is null) return; @@ -91,7 +91,7 @@ else { - // states.RemoveAll(x => x.Type != "m.room.member" || (x.TypedContent as RoomMemberEventData).Membership != "join"); + // states.RemoveAll(x => x.Type != "m.room.member" || (x.TypedContent as RoomMemberEventContent).Membership != "join"); // Console.WriteLine($"Room {room.RoomId} has {states.Count} members"); // if (states.Count > memberLimit) { // Console.WriteLine("Skipping!"); diff --git a/MatrixRoomUtils.Web/Pages/LoginPage.razor b/MatrixRoomUtils.Web/Pages/LoginPage.razor index 9730cbe..a6ce469 100644 --- a/MatrixRoomUtils.Web/Pages/LoginPage.razor +++ b/MatrixRoomUtils.Web/Pages/LoginPage.razor @@ -1,7 +1,6 @@ @page "/Login" @using System.Text.Json @using LibMatrix.Responses -@using MatrixRoomUtils.Web.Shared.SimpleComponents @inject ILocalStorageService LocalStorage @inject IJSRuntime JsRuntime

Login

@@ -12,6 +11,8 @@ -->: + via + @@ -29,13 +30,27 @@ Username Homeserver + Password + Proxy - @foreach (var (homeserver, username, password) in records) { - var record = (homeserver, username, password); - - @username - @homeserver - Remove + @foreach (var record in records) { + var r = record; + + + + + + + + + + + + + + + Remove + } @@ -45,17 +60,19 @@ @code { - readonly List<(string homeserver, string username, string password)> records = new(); - (string homeserver, string username, string password) newRecordInput = ("", "", ""); + readonly List<(string homeserver, string username, string password, string? proxy)> records = new(); + (string homeserver, string username, string password, string? proxy) newRecordInput = ("", "", "", null); - List LoggedInSessions { get; set; } = new(); + List? LoggedInSessions { get; set; } = new(); async Task Login() { var loginTasks = records.Select(async record => { - var (homeserver, username, password) = record; - if (LoggedInSessions.Any(x => x.UserId == $"@{username}:{homeserver}")) return; + var (homeserver, username, password, proxy) = record; + if (LoggedInSessions.Any(x => x.UserId == $"@{username}:{homeserver}" && x.Proxy == proxy)) return; try { - var result = await HomeserverProvider.Login(homeserver, username, password); + var result = new UserAuth(await HomeserverProvider.Login(homeserver, username, password, proxy)) { + Proxy = proxy + }; if (result == null) { Console.WriteLine($"Failed to login to {homeserver} as {username}!"); return; @@ -81,20 +98,21 @@ })); await using var rs = obj.File.OpenReadStream(); using var sr = new StreamReader(rs); - var TsvData = await sr.ReadToEndAsync(); + var tsvData = await sr.ReadToEndAsync(); records.Clear(); - foreach (var line in TsvData.Split('\n')) { - var parts = line.Split('\t'); - if (parts.Length != 3) + foreach (var line in tsvData.Split('\n')) { + string?[] parts = line.Split('\t'); + if (parts.Length < 3) continue; - records.Add((parts[0], parts[1], parts[2])); + string? via = parts.Length > 3 ? parts[3] : null; + records.Add((parts[0], parts[1], parts[2], via)); } } private async Task AddRecord() { LoggedInSessions = await MRUStorage.GetAllTokens(); records.Add(newRecordInput); - newRecordInput = ("", "", ""); + newRecordInput = ("", "", "", null); } } diff --git a/MatrixRoomUtils.Web/Pages/MediaLocator.razor b/MatrixRoomUtils.Web/Pages/MediaLocator.razor index af6e67a..42c7b8e 100644 --- a/MatrixRoomUtils.Web/Pages/MediaLocator.razor +++ b/MatrixRoomUtils.Web/Pages/MediaLocator.razor @@ -1,5 +1,6 @@ @page "/MediaLocator" @using LibMatrix +@using LibMatrix.Homeservers @inject HttpClient Http

Media locator


diff --git a/MatrixRoomUtils.Web/Pages/ModalTest.razor b/MatrixRoomUtils.Web/Pages/ModalTest.razor index 2b1c9bc..1d14005 100644 --- a/MatrixRoomUtils.Web/Pages/ModalTest.razor +++ b/MatrixRoomUtils.Web/Pages/ModalTest.razor @@ -10,7 +10,7 @@ @for (var j = 0; j < i1; j++) {

@j

- } + }
} @@ -70,7 +70,7 @@ } if(_windowInfos.Count > 750) multiplier = 2; if(_windowInfos.Count > 1500) multiplier = 3; - + } await base.OnInitializedAsync(); diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Create.razor b/MatrixRoomUtils.Web/Pages/Rooms/Create.razor index 3b7d000..c6fd5b6 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/Create.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/Create.razor @@ -1,15 +1,15 @@ @page "/Rooms/Create" @using System.Text.Json @using System.Reflection +@using ArcaneLibs.Extensions @using LibMatrix @using LibMatrix.Extensions @using LibMatrix.Helpers +@using LibMatrix.Homeservers @using LibMatrix.Responses @using LibMatrix.StateEventTypes.Spec -@using LibMatrix.StateEventTypes @using MatrixRoomUtils.Web.Classes.RoomCreationTemplates @* @* ReSharper disable once RedundantUsingDirective - Must not remove this, Rider marks this as "unused" when it's not */ *@ -@using MatrixRoomUtils.Web.Shared.SimpleComponents

Room Manager - Create Room

@@ -135,7 +135,7 @@ } else {
- @((creationEvent["m.room.server_acls"].TypedContent as ServerACLEventData).Allow.Count) allow rules + @((creationEvent["m.room.server_acls"].TypedContent as ServerACLEventContent).Allow.Count) allow rules @* *@
} @@ -145,7 +145,7 @@ } else {
- @((creationEvent["m.room.server_acls"].TypedContent as ServerACLEventData).Deny.Count) deny rules + @((creationEvent["m.room.server_acls"].TypedContent as ServerACLEventContent).Deny.Count) deny rules @* *@
} @@ -251,14 +251,14 @@ private CreateRoomRequest? creationEvent { get; set; } private Dictionary? Presets { get; set; } = new(); - private AuthenticatedHomeServer? HomeServer { get; set; } + private AuthenticatedHomeserverGeneric? HomeServer { get; set; } private MatrixException? _matrixException { get; set; } - private HistoryVisibilityEventData? historyVisibility => creationEvent?["m.room.history_visibility"].TypedContent as HistoryVisibilityEventData; - private GuestAccessEventData? guestAccessEvent => creationEvent?["m.room.guest_access"].TypedContent as GuestAccessEventData; - private ServerACLEventData? serverAcl => creationEvent?["m.room.server_acls"].TypedContent as ServerACLEventData; - private RoomAvatarEventData? roomAvatarEvent => creationEvent?["m.room.avatar"].TypedContent as RoomAvatarEventData; + private HistoryVisibilityEventContent? historyVisibility => creationEvent?["m.room.history_visibility"].TypedContent as HistoryVisibilityEventContent; + private GuestAccessEventContent? guestAccessEvent => creationEvent?["m.room.guest_access"].TypedContent as GuestAccessEventContent; + private ServerACLEventContent? serverAcl => creationEvent?["m.room.server_acls"].TypedContent as ServerACLEventContent; + private RoomAvatarEventContent? roomAvatarEvent => creationEvent?["m.room.avatar"].TypedContent as RoomAvatarEventContent; protected override async Task OnInitializedAsync() { HomeServer = await MRUStorage.GetCurrentSessionOrNavigate(); @@ -284,7 +284,7 @@ private async Task RoomIconFilePicked(InputFileChangeEventArgs obj) { var res = await HomeServer.UploadFile(obj.File.Name, obj.File.OpenReadStream(), obj.File.ContentType); Console.WriteLine(res); - (creationEvent["m.room.avatar"].TypedContent as RoomAvatarEventData).Url = res; + (creationEvent["m.room.avatar"].TypedContent as RoomAvatarEventContent).Url = res; StateHasChanged(); } @@ -305,7 +305,7 @@ creationEvent.InitialState.Add(new StateEvent { Type = "m.room.member", StateKey = mxid, - TypedContent = new RoomMemberEventData { + TypedContent = new RoomMemberEventContent { Membership = "invite", Reason = "Automatically invited at room creation time." } diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor index ad3a714..c2daba7 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor @@ -1,10 +1,10 @@ @page "/Rooms" -@using LibMatrix.StateEventTypes @using LibMatrix.StateEventTypes.Spec @using LibMatrix.Filters @using LibMatrix.Helpers @using LibMatrix.Responses

Room list

+

@Status

@if (RenderContents) { @@ -16,7 +16,7 @@ public List KnownRooms { get; set; } = new(); private List Rooms { get; set; } = new(); - private ProfileResponseEventData GlobalProfile { get; set; } + private ProfileResponseEventContent GlobalProfile { get; set; } private SyncFilter filter = new() { AccountData = new SyncFilter.EventFilter { @@ -93,7 +93,7 @@ if (!roomInfo.StateEvents.Any(x => x.Type == "m.room.name")) { roomInfo.StateEvents.Add(new StateEventResponse { Type = "m.room.name", - TypedContent = new RoomNameEventData { + TypedContent = new RoomNameEventContent { Name = roomInfo.Room.RoomId } }); @@ -101,7 +101,7 @@ if (!roomInfo.StateEvents.Any(x => x.Type == "m.room.avatar")) { roomInfo.StateEvents.Add(new StateEventResponse { Type = "m.room.avatar", - TypedContent = new RoomAvatarEventData { + TypedContent = new RoomAvatarEventContent { } }); @@ -121,7 +121,7 @@ roomInfo.StateEvents.Add(new StateEventResponse { Type = "m.room.member", StateKey = hs.WhoAmI.UserId, - TypedContent = await roomInfo.Room.GetStateAsync("m.room.member", hs.WhoAmI.UserId) ?? new RoomMemberEventData { + TypedContent = await roomInfo.Room.GetStateAsync("m.room.member", hs.WhoAmI.UserId) ?? new RoomMemberEventContent { Membership = "unknown" } }); diff --git a/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor b/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor index 2b31389..d2b8360 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor @@ -1,11 +1,11 @@ @page "/Rooms/{RoomId}/Policies" -@using LibMatrix.StateEventTypes -@using System.Text.Json @using LibMatrix @using LibMatrix.Extensions @using LibMatrix.Helpers +@using LibMatrix.Homeservers @using LibMatrix.Responses @using LibMatrix.StateEventTypes.Spec +@using ArcaneLibs.Extensions

Policy list editor - Editing @RoomId


@@ -33,8 +33,8 @@ else { - @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; + @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.server" && (x.TypedContent as PolicyRuleEventContent).Entity is not null)) { + var policyData = policyEvent.TypedContent as PolicyRuleEventContent; Entity: @policyData.Entity
State: @policyEvent.StateKey @policyData.Reason @@ -59,8 +59,8 @@ else { - @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; + @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.server" && (x.TypedContent as PolicyRuleEventContent).Entity == null)) { + var policyData = policyEvent.TypedContent as PolicyRuleEventContent; @policyEvent.StateKey @policyEvent.RawContent.ToJson(false, true) @@ -86,8 +86,8 @@ else { - @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; + @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && (x.TypedContent as PolicyRuleEventContent).Entity is not null)) { + var policyData = policyEvent.TypedContent as PolicyRuleEventContent; Entity: @policyData.Entity
State: @policyEvent.StateKey @policyData.Reason @@ -111,7 +111,7 @@ else { - @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && (x.TypedContent as PolicyRuleStateEventData).Entity == null)) { + @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && (x.TypedContent as PolicyRuleEventContent).Entity == null)) { @policyEvent.StateKey @policyEvent.RawContent!.ToJson(false, true) @@ -140,8 +140,8 @@ else { - @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; + @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && (x.TypedContent as PolicyRuleEventContent).Entity is not null)) { + var policyData = policyEvent.TypedContent as PolicyRuleEventContent; @if (_enableAvatars) { @@ -170,7 +170,7 @@ else { - @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && (x.TypedContent as PolicyRuleStateEventData).Entity == null)) { + @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && (x.TypedContent as PolicyRuleEventContent).Entity == null)) { @policyEvent.StateKey @policyEvent.RawContent.ToJson(false, true) @@ -245,8 +245,8 @@ else { } 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); + foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && (x.TypedContent as PolicyRuleEventContent).Entity is not null)) { + await GetAvatar((policyEvent.TypedContent as PolicyRuleEventContent).Entity); } StateHasChanged(); } diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Space.razor b/MatrixRoomUtils.Web/Pages/Rooms/Space.razor index c37b8ab..ef0ea5a 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/Space.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/Space.razor @@ -1,8 +1,8 @@ @page "/Rooms/{RoomId}/Space" -@using System.Text.Json @using LibMatrix.Extensions @using LibMatrix.Responses @using LibMatrix.RoomTypes +@using ArcaneLibs.Extensions

Room manager - Viewing Space

diff --git a/MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor b/MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor index ef7cd51..fefcabc 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor @@ -1,8 +1,7 @@ @page "/Rooms/{RoomId}/State/Edit" -@using System.Net.Http.Headers -@using System.Text.Json @using LibMatrix.Extensions @using LibMatrix.Responses +@using ArcaneLibs.Extensions @inject ILocalStorageService LocalStorage @inject NavigationManager NavigationManager

Room state editor - Editing @RoomId

diff --git a/MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor b/MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor index 5a48b32..1c3f28b 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor @@ -1,8 +1,7 @@ @page "/Rooms/{RoomId}/State/View" -@using System.Net.Http.Headers -@using System.Text.Json @using LibMatrix.Extensions @using LibMatrix.Responses +@using ArcaneLibs.Extensions @inject ILocalStorageService LocalStorage @inject NavigationManager NavigationManager

Room state viewer - Viewing @RoomId

diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor b/MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor index 4a5298b..2c95c99 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor @@ -1,6 +1,7 @@ @page "/Rooms/{RoomId}/Timeline" @using MatrixRoomUtils.Web.Shared.TimelineComponents @using LibMatrix +@using LibMatrix.Homeservers @using LibMatrix.Responses @using LibMatrix.StateEventTypes.Spec

RoomManagerTimeline

@@ -23,7 +24,7 @@ private List Messages { get; } = new(); private List Events { get; } = new(); - private AuthenticatedHomeServer? HomeServer { get; set; } + private AuthenticatedHomeserverGeneric? HomeServer { get; set; } protected override async Task OnInitializedAsync() { Console.WriteLine("RoomId: " + RoomId); @@ -46,8 +47,9 @@ private StateEventResponse GetProfileEventBefore(StateEventResponse Event) => Events.TakeWhile(x => x != Event).Last(e => e.Type == "m.room.member" && e.StateKey == Event.Sender); private Type ComponentType(StateEvent Event) => Event.TypedContent switch { - RoomMessageEventData => typeof(TimelineMessageItem), - RoomMemberEventData => typeof(TimelineMemberItem), + RoomMessageEventContent => typeof(TimelineMessageItem), + RoomMemberEventContent => typeof(TimelineMemberItem), + RoomCreateEventContent => typeof(TimelineRoomCreateItem), _ => typeof(TimelineUnknownItem) }; diff --git a/MatrixRoomUtils.Web/Pages/SpaceDebug.razor b/MatrixRoomUtils.Web/Pages/SpaceDebug.razor new file mode 100644 index 0000000..c4c4ce8 --- /dev/null +++ b/MatrixRoomUtils.Web/Pages/SpaceDebug.razor @@ -0,0 +1,114 @@ +@page "/SpaceDebug" +@using LibMatrix.StateEventTypes.Spec +@using LibMatrix.RoomTypes +@using LibMatrix.Filters +

SpaceDebug

+
+ +

@Status

+ +Has parent: +
+ +@foreach (var (roomId, parents) in SpaceParents) { +

@roomId's parents

+
    + @foreach (var parent in parents) { +
  • @parent
  • + } +
+} + +Space children: + +@foreach (var (roomId, children) in SpaceChildren) { +

@roomId's children

+
    + @foreach (var child in children) { +
  • @child
  • + } +
+} + +@code { + private string _status = "Loading..."; + + public string Status { + get => _status; + set { + _status = value; + StateHasChanged(); + } + } + + public Dictionary> SpaceChildren { get; set; } = new(); + public Dictionary> SpaceParents { get; set; } = new(); + + protected override async Task OnInitializedAsync() { + Status = "Getting homeserver..."; + var hs = await MRUStorage.GetCurrentSessionOrNavigate(); + if (hs is null) return; + + Status = "Syncing..."; + string nextBatch = null; + while (nextBatch != "end") { + var sync = await hs.SyncHelper.Sync(since: nextBatch, filter: new SyncFilter() { + Presence = new(0), + Room = new() { + AccountData = new(limit: 0), + Ephemeral = new(limit: 0), + State = new(limit: 1000, types: new() { "m.space.child", "m.space.parent" }), + Timeline = new(limit: 0) + }, + AccountData = new(limit: 0) + }); + + if (sync is null) { + Status = "Sync failed"; + continue; + } + + if (sync.Rooms is null) { + Status = "No rooms in sync..."; + nextBatch = "end"; + continue; + } + + if (sync.Rooms.Join is null) { + Status = "No joined rooms in sync..."; + nextBatch = "end"; + continue; + } + + if (sync.Rooms.Join.Count == 0) { + Status = "Joined rooms list was empty..."; + nextBatch = "end"; + continue; + } + + nextBatch = sync.NextBatch; + foreach (var (roomId, data) in sync.Rooms!.Join!) { + data.State?.Events?.ForEach(e => { + if (e.Type == "m.space.child") { + if (!SpaceChildren.ContainsKey(roomId)) SpaceChildren[roomId] = new(); + if (e.RawContent is null) e.StateKey += " (null)"; + else if (e.RawContent.Count == 0) e.StateKey += " (empty)"; + SpaceChildren[roomId].Add(e.StateKey); + } + if (e.Type == "m.space.parent") { + if (!SpaceParents.ContainsKey(roomId)) SpaceParents[roomId] = new(); + if (e.RawContent is null) e.StateKey += " (null)"; + else if (e.RawContent.Count == 0) e.StateKey += " (empty)"; + SpaceParents[roomId].Add(e.StateKey); + } + }); + } + Status = $"Synced {sync.Rooms.Join.Count} rooms, found {SpaceChildren.Count} spaces, {SpaceParents.Count} parents"; + } + Status = $"Synced: found {SpaceChildren.Count}->{SpaceChildren.Sum(x => x.Value.Count)} spaces, {SpaceParents.Count}->{SpaceParents.Sum(x => x.Value.Count)} parents!"; + + await base.OnInitializedAsync(); + } + + +} -- cgit 1.5.1