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/Classes/MRUStorageWrapper.cs | 27 ++--- .../DefaultRoomCreationTemplate.cs | 27 +++-- MatrixRoomUtils.Web/Classes/RoomInfo.cs | 3 +- MatrixRoomUtils.Web/Classes/UserAuth.cs | 15 +++ MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj | 10 +- 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 +++++++++++++++++++++ MatrixRoomUtils.Web/Shared/InlineUserItem.razor | 9 +- MatrixRoomUtils.Web/Shared/ModalWindow.razor | 86 ---------------- MatrixRoomUtils.Web/Shared/ModalWindow.razor.css | 70 ------------- MatrixRoomUtils.Web/Shared/RoomList.razor | 5 +- .../RoomListComponents/RoomListCategory.razor | 15 +-- .../Shared/RoomListComponents/RoomListSpace.razor | 2 +- MatrixRoomUtils.Web/Shared/RoomListItem.razor | 15 +-- .../Shared/SimpleComponents/DictionaryEditor.razor | 38 ------- .../Shared/SimpleComponents/FancyTextBox.razor | 29 ------ .../Shared/SimpleComponents/FancyTextBox.razor.css | 5 - .../Shared/SimpleComponents/LinkButton.razor | 20 ---- .../Shared/SimpleComponents/StringListEditor.razor | 29 ------ .../Shared/SimpleComponents/ToggleSlider.razor | 72 ------------- .../TimelineComponents/BaseTimelineItem.razor | 3 +- .../TimelineComponents/TimelineMemberItem.razor | 10 +- .../TimelineComponents/TimelineMessageItem.razor | 1 + .../TimelineRoomCreateItem.razor | 5 +- .../TimelineComponents/TimelineUnknownItem.razor | 1 + MatrixRoomUtils.Web/Shared/UserListItem.razor | 2 +- MatrixRoomUtils.Web/_Imports.razor | 2 +- 44 files changed, 368 insertions(+), 509 deletions(-) create mode 100644 MatrixRoomUtils.Web/Classes/UserAuth.cs create mode 100644 MatrixRoomUtils.Web/Pages/Index.razor.css create mode 100644 MatrixRoomUtils.Web/Pages/SpaceDebug.razor delete mode 100644 MatrixRoomUtils.Web/Shared/ModalWindow.razor delete mode 100644 MatrixRoomUtils.Web/Shared/ModalWindow.razor.css delete mode 100644 MatrixRoomUtils.Web/Shared/SimpleComponents/DictionaryEditor.razor delete mode 100644 MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor delete mode 100644 MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor.css delete mode 100644 MatrixRoomUtils.Web/Shared/SimpleComponents/LinkButton.razor delete mode 100644 MatrixRoomUtils.Web/Shared/SimpleComponents/StringListEditor.razor delete mode 100644 MatrixRoomUtils.Web/Shared/SimpleComponents/ToggleSlider.razor (limited to 'MatrixRoomUtils.Web') diff --git a/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs b/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs index 14625fd..8ea85e9 100644 --- a/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs +++ b/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs @@ -1,4 +1,5 @@ using LibMatrix; +using LibMatrix.Homeservers; using LibMatrix.Responses; using LibMatrix.Services; using Microsoft.AspNetCore.Components; @@ -20,13 +21,13 @@ public class MRUStorageWrapper { _navigationManager = navigationManager; } - public async Task?> GetAllTokens() { - return await _storageService.DataStorageProvider.LoadObjectAsync>("mru.tokens") ?? - new List(); + public async Task?> GetAllTokens() { + return await _storageService.DataStorageProvider.LoadObjectAsync>("mru.tokens") ?? + new List(); } - public async Task GetCurrentToken() { - var currentToken = await _storageService.DataStorageProvider.LoadObjectAsync("token"); + public async Task GetCurrentToken() { + var currentToken = await _storageService.DataStorageProvider.LoadObjectAsync("token"); var allTokens = await GetAllTokens(); if (allTokens is null or { Count: 0 }) { await SetCurrentToken(null); @@ -44,14 +45,14 @@ public class MRUStorageWrapper { return currentToken; } - public async Task AddToken(LoginResponse loginResponse) { - var tokens = await GetAllTokens() ?? new List(); + public async Task AddToken(UserAuth UserAuth) { + var tokens = await GetAllTokens() ?? new List(); - tokens.Add(loginResponse); + tokens.Add(UserAuth); await _storageService.DataStorageProvider.SaveObjectAsync("mru.tokens", tokens); } - private async Task GetCurrentSession() { + private async Task GetCurrentSession() { var token = await GetCurrentToken(); if (token == null) { return null; @@ -60,8 +61,8 @@ public class MRUStorageWrapper { return await _homeserverProviderService.GetAuthenticatedWithToken(token.Homeserver, token.AccessToken); } - public async Task GetCurrentSessionOrNavigate() { - AuthenticatedHomeServer? session = null; + public async Task GetCurrentSessionOrNavigate() { + AuthenticatedHomeserverGeneric? session = null; try { //catch if the token is invalid @@ -94,7 +95,7 @@ public class MRUStorageWrapper { public bool EnablePortableDevtools { get; set; } } - public async Task RemoveToken(LoginResponse auth) { + public async Task RemoveToken(UserAuth auth) { var tokens = await GetAllTokens(); if (tokens == null) { return; @@ -104,5 +105,5 @@ public class MRUStorageWrapper { await _storageService.DataStorageProvider.SaveObjectAsync("mru.tokens", tokens); } - public async Task SetCurrentToken(LoginResponse? auth) => await _storageService.DataStorageProvider.SaveObjectAsync("token", auth); + public async Task SetCurrentToken(UserAuth? auth) => await _storageService.DataStorageProvider.SaveObjectAsync("token", auth); } diff --git a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs index bb2eab9..3f67f33 100644 --- a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs +++ b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs @@ -2,7 +2,6 @@ using System.Text.Json.Nodes; using LibMatrix; using LibMatrix.Responses; using LibMatrix.StateEventTypes.Spec; -using LibMatrix.StateEventTypes; namespace MatrixRoomUtils.Web.Classes.RoomCreationTemplates; @@ -16,39 +15,39 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate { InitialState = new List { new() { Type = "m.room.history_visibility", - TypedContent = new { - history_visibility = "world_readable" + TypedContent = new HistoryVisibilityEventContent() { + HistoryVisibility = "world_readable" } }, new() { Type = "m.room.guest_access", - TypedContent = new GuestAccessEventData { + TypedContent = new GuestAccessEventContent { GuestAccess = "can_join" } }, new() { Type = "m.room.join_rules", - TypedContent = new JoinRulesEventData { + TypedContent = new JoinRulesEventContent { JoinRule = "public" } }, new() { Type = "m.room.server_acl", - TypedContent = new { - allow = new[] { "*" }, - deny = Array.Empty(), - allow_ip_literals = false + TypedContent = new ServerACLEventContent() { + Allow = new List() { "*" }, + Deny = new List(), + AllowIpLiterals = false } }, new() { Type = "m.room.avatar", - TypedContent = new RoomAvatarEventData { + TypedContent = new RoomAvatarEventContent { Url = "mxc://feline.support/UKNhEyrVsrAbYteVvZloZcFj" } } }, Visibility = "public", - PowerLevelContentOverride = new RoomPowerLevelEventData { + PowerLevelContentOverride = new RoomPowerLevelEventContent { UsersDefault = 0, EventsDefault = 100, StateDefault = 50, @@ -56,10 +55,10 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate { Redact = 50, Kick = 50, Ban = 50, - NotificationsPl = new RoomPowerLevelEventData.NotificationsPL { + NotificationsPl = new RoomPowerLevelEventContent.NotificationsPL { Room = 50 }, - Events = new Dictionary { + Events = new() { { "im.vector.modular.widgets", 50 }, { "io.element.voice_broadcast_info", 50 }, { "m.reaction", 100 }, @@ -78,7 +77,7 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate { { "org.matrix.msc3401.call", 50 }, { "org.matrix.msc3401.call.member", 50 } }, - Users = new Dictionary { + Users = new() { // { RuntimeCache.CurrentHomeServer.UserId, 100 } //TODO: re-implement this } diff --git a/MatrixRoomUtils.Web/Classes/RoomInfo.cs b/MatrixRoomUtils.Web/Classes/RoomInfo.cs index 111bfe0..0e21871 100644 --- a/MatrixRoomUtils.Web/Classes/RoomInfo.cs +++ b/MatrixRoomUtils.Web/Classes/RoomInfo.cs @@ -1,4 +1,5 @@ using LibMatrix; +using LibMatrix.Interfaces; using LibMatrix.Responses; using LibMatrix.RoomTypes; @@ -17,7 +18,7 @@ public class RoomInfo { StateKey = stateKey }; try { - @event.TypedContent = await Room.GetStateAsync(type, stateKey); + @event.TypedContent = await Room.GetStateAsync(type, stateKey); } catch (MatrixException e) { if (e is { ErrorCode: "M_NOT_FOUND" }) @event.TypedContent = default!; diff --git a/MatrixRoomUtils.Web/Classes/UserAuth.cs b/MatrixRoomUtils.Web/Classes/UserAuth.cs new file mode 100644 index 0000000..e6f0954 --- /dev/null +++ b/MatrixRoomUtils.Web/Classes/UserAuth.cs @@ -0,0 +1,15 @@ +using LibMatrix.Responses; + +namespace MatrixRoomUtils.Web.Classes; + +public class UserAuth : LoginResponse { + public UserAuth() { } + public UserAuth(LoginResponse login) { + Homeserver = login.Homeserver; + UserId = login.UserId; + AccessToken = login.AccessToken; + DeviceId = login.DeviceId; + } + + public string? Proxy { get; set; } +} diff --git a/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj b/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj index fce3cfd..3c8d362 100644 --- a/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj +++ b/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj @@ -5,17 +5,23 @@ enable enable true + true + preview - - + + + + + + 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(); + } + + +} diff --git a/MatrixRoomUtils.Web/Shared/InlineUserItem.razor b/MatrixRoomUtils.Web/Shared/InlineUserItem.razor index db66309..af2fa29 100644 --- a/MatrixRoomUtils.Web/Shared/InlineUserItem.razor +++ b/MatrixRoomUtils.Web/Shared/InlineUserItem.razor @@ -2,6 +2,7 @@ @using LibMatrix.StateEventTypes.Spec @using LibMatrix @using LibMatrix.Helpers +@using LibMatrix.Homeservers
@ProfileName @@ -20,10 +21,10 @@ public RenderFragment? ChildContent { get; set; } [Parameter] - public ProfileResponseEventData User { get; set; } + public ProfileResponseEventContent User { get; set; } [Parameter] - public ProfileResponseEventData MemberEvent { get; set; } + public ProfileResponseEventContent MemberEvent { get; set; } [Parameter] public string? UserId { get; set; } @@ -35,7 +36,7 @@ public string? ProfileName { get; set; } = null; [Parameter] - public AuthenticatedHomeServer? HomeServer { get; set; } + public AuthenticatedHomeserverGeneric? HomeServer { get; set; } private static SemaphoreSlim _semaphoreSlim = new(128); @@ -50,7 +51,7 @@ throw new ArgumentNullException(nameof(UserId)); if (MemberEvent != null) { - User = new ProfileResponseEventData { + User = new ProfileResponseEventContent { AvatarUrl = MemberEvent.AvatarUrl, DisplayName = MemberEvent.DisplayName }; diff --git a/MatrixRoomUtils.Web/Shared/ModalWindow.razor b/MatrixRoomUtils.Web/Shared/ModalWindow.razor deleted file mode 100644 index beb7198..0000000 --- a/MatrixRoomUtils.Web/Shared/ModalWindow.razor +++ /dev/null @@ -1,86 +0,0 @@ -@using LibMatrix.Extensions -
-
- @Title - - -
-
- @ChildContent -
-
- -@code { - - [Parameter] - public RenderFragment? ChildContent { get; set; } - - [Parameter] - public string Title { get; set; } = "Untitled window"; - - [Parameter] - public double X { get; set; } = 60; - - [Parameter] - public double Y { get; set; } = 60; - - [Parameter] - public double MinWidth { get; set; } = 100; - - [Parameter] - public Action OnCloseClicked { get; set; } - - [Parameter] - public bool Collapsed { get; set; } = false; - - private ElementReference _titleRef; - - private double _x = 60; - private double _y = 60; - - protected override async Task OnInitializedAsync() { - _x = X; - _y = Y; - await base.OnInitializedAsync(); - } - - protected override async Task OnAfterRenderAsync(bool firstRender) { - //set minwidth to title width - MinWidth = await JSRuntime.InvokeAsync("getWidth", _titleRef) + 75; - await base.OnAfterRenderAsync(firstRender); - } - - private void WindowDrag(DragEventArgs obj) { - Console.WriteLine("Drag: " + obj.ToJson()); - - _x += obj.MovementX; - _y += obj.MovementY; - - StateHasChanged(); - } - - private bool isDragging = false; - private double dragX = 0; - private double dragY = 0; - - private void MouseDown(MouseEventArgs obj) { - isDragging = true; - dragX = obj.ClientX; - dragY = obj.ClientY; - } - - private void MouseUp(MouseEventArgs obj) { - isDragging = false; - } - - private void MouseMove(MouseEventArgs obj) { - if (!isDragging) return; - - _x += obj.ClientX - dragX; - _y += obj.ClientY - dragY; - dragX = obj.ClientX; - dragY = obj.ClientY; - StateHasChanged(); - } - -} diff --git a/MatrixRoomUtils.Web/Shared/ModalWindow.razor.css b/MatrixRoomUtils.Web/Shared/ModalWindow.razor.css deleted file mode 100644 index 6d08114..0000000 --- a/MatrixRoomUtils.Web/Shared/ModalWindow.razor.css +++ /dev/null @@ -1,70 +0,0 @@ -.r-modal { - position: absolute; - width: fit-content; - height: fit-content; - z-index: 1000; -} -.r-modal:hover { - z-index: 1001; -} - -.r-modal > .titlebar { - position: absolute; - display: block; - top: 0; - left: 0; - width: 100%; - height: 25px; - background-color: #000; - user-select: none; -} - -.r-modal > .titlebar > .title { - position: relative; - top: 0; - left: 0; - width: fit-content; - text-wrap: nowrap; - height: 100%; - line-height: 25px; - padding-left: 10px; - color: #fff; -} - -.r-modal > .titlebar > .btnclose { - position: absolute; - top: 0; - right: 0; - width: 25px; - height: 100%; - line-height: 25px; - text-align: center; - color: #fff; - background-color: #111; - cursor: pointer; -} -.r-modal > .titlebar > .btncollapse { - position: absolute; - top: 0; - right: 25px; - width: 25px; - height: 100%; - line-height: 25px; - text-align: center; - color: #fff; - background-color: #111; - cursor: pointer; -} - -.r-modal > .r-modal-content { - position: relative; - top: 25px; - left: 0; - width: fit-content; - height: fit-content; - min-width: 150px; - max-width: 75vw; - max-height: 75vh; - overflow: auto; - background-color: #111; -} diff --git a/MatrixRoomUtils.Web/Shared/RoomList.razor b/MatrixRoomUtils.Web/Shared/RoomList.razor index 3b057a4..b0548cb 100644 --- a/MatrixRoomUtils.Web/Shared/RoomList.razor +++ b/MatrixRoomUtils.Web/Shared/RoomList.razor @@ -3,6 +3,7 @@ @using LibMatrix.StateEventTypes.Spec @using LibMatrix @using LibMatrix.Extensions +@using ArcaneLibs.Extensions @if(Rooms.Count != RoomsWithTypes.Sum(x=>x.Value.Count)) {

Fetching room details... @RoomsWithTypes.Sum(x=>x.Value.Count) out of @Rooms.Count done!

@foreach (var category in RoomsWithTypes.OrderBy(x => x.Value.Count)) { @@ -20,7 +21,7 @@ else { [Parameter] public List Rooms { get; set; } [Parameter] - public ProfileResponseEventData? GlobalProfile { get; set; } + public ProfileResponseEventContent? GlobalProfile { get; set; } Dictionary> RoomsWithTypes = new(); @@ -51,7 +52,7 @@ else { await _semaphoreSlim.WaitAsync(); string roomType; try { - var createEvent = (await room.GetStateEvent("m.room.create")).TypedContent as RoomCreateEventData; + var createEvent = (await room.GetStateEvent("m.room.create")).TypedContent as RoomCreateEventContent; roomType = GetRoomTypeName(createEvent.Type); if (roomType == "Room") { diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor index 381ecd1..d717186 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor @@ -2,18 +2,19 @@ @using MatrixRoomUtils.Web.Classes.Constants @using LibMatrix.StateEventTypes.Spec @using LibMatrix +@using LibMatrix.Homeservers
@roomType (@rooms.Count) @foreach (var room in rooms) {
@* @if (RoomVersionDangerLevel(room) != 0 && *@ - @* (room.StateEvents.FirstOrDefault(x=>x.Type == "m.room.power_levels")?.TypedContent is RoomPowerLevelEventData powerLevels && powerLevels.UserHasPermission(HomeServer.UserId, "m.room.tombstone"))) { *@ + @* (room.StateEvents.FirstOrDefault(x=>x.Type == "m.room.power_levels")?.TypedContent is RoomPowerLevelEventContent powerLevels && powerLevels.UserHasPermission(HomeServer.UserId, "m.room.tombstone"))) { *@ @* Upgrade room *@ @* } *@ - View timeline - View state - Edit state + View timeline + View state + Edit state @if (roomType == "Space") { @@ -29,10 +30,10 @@ public KeyValuePair> Category { get; set; } [Parameter] - public ProfileResponseEventData? GlobalProfile { get; set; } + public ProfileResponseEventContent? GlobalProfile { get; set; } [CascadingParameter] - public AuthenticatedHomeServer HomeServer { get; set; } = null!; + public AuthenticatedHomeserverGeneric Homeserver { get; set; } = null!; private string roomType => Category.Key; private List rooms => Category.Value; @@ -40,7 +41,7 @@ private int RoomVersionDangerLevel(RoomInfo room) { var roomVersion = room.StateEvents.FirstOrDefault(x => x.Type == "m.room.create"); if (roomVersion is null) return 0; - return roomVersion.TypedContent is not RoomCreateEventData roomVersionContent ? 0 + return roomVersion.TypedContent is not RoomCreateEventContent roomVersionContent ? 0 : RoomConstants.DangerousRoomVersions.Contains(roomVersionContent.RoomVersion) ? 2 : roomVersionContent.RoomVersion != RoomConstants.RecommendedRoomVersion ? 1 : 0; } diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor index 0867b48..1b54577 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor @@ -30,7 +30,7 @@ protected override async Task OnInitializedAsync() { if (Breadcrumbs == null) throw new ArgumentNullException(nameof(Breadcrumbs)); await Task.Delay(Random.Shared.Next(1000, 10000)); - var rooms = Space.Room.AsSpace.GetRoomsAsync(); + var rooms = Space.Room.AsSpace.GetChildrenAsync(); await foreach (var room in rooms) { if (Breadcrumbs.Contains(room.RoomId)) continue; var roomInfo = KnownRooms.FirstOrDefault(x => x.Room.RoomId == room.RoomId); diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor index 79844ef..b74643b 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor @@ -1,6 +1,7 @@ @using System.Text.Json @using LibMatrix @using LibMatrix.Helpers +@using LibMatrix.Homeservers @using LibMatrix.RoomTypes @using LibMatrix.StateEventTypes.Spec @using LibMatrix.StateEventTypes @@ -44,10 +45,10 @@ public bool ShowOwnProfile { get; set; } = false; [Parameter] - public RoomMemberEventData? OwnMemberState { get; set; } + public RoomMemberEventContent? OwnMemberState { get; set; } [CascadingParameter] - public ProfileResponseEventData? GlobalProfile { get; set; } + public ProfileResponseEventContent? GlobalProfile { get; set; } private string? roomName { get; set; } @@ -57,7 +58,7 @@ private bool hasDangerousRoomVersion { get; set; } = false; private static SemaphoreSlim _semaphoreSlim = new(8); - private static AuthenticatedHomeServer? hs { get; set; } + private static AuthenticatedHomeserverGeneric? hs { get; set; } protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); @@ -102,7 +103,7 @@ private async Task LoadOwnProfile() { if (!ShowOwnProfile) return; try { - OwnMemberState ??= (await RoomInfo.GetStateEvent("m.room.member", hs.UserId)).TypedContent as RoomMemberEventData; + OwnMemberState ??= (await RoomInfo.GetStateEvent("m.room.member", hs.UserId)).TypedContent as RoomMemberEventContent; GlobalProfile ??= await hs.GetProfile(hs.UserId); } catch (MatrixException e) { @@ -117,7 +118,7 @@ } private async Task CheckRoomVersion() { - var ce = (await RoomInfo.GetStateEvent("m.room.create")).TypedContent as RoomCreateEventData; + var ce = (await RoomInfo.GetStateEvent("m.room.create")).TypedContent as RoomCreateEventContent; if (int.TryParse(ce.RoomVersion, out var rv)) { if (rv < 10) hasOldRoomVersion = true; @@ -133,9 +134,9 @@ private async Task GetRoomInfo() { try { - roomName ??= ((await RoomInfo.GetStateEvent("m.room.name"))?.TypedContent as RoomNameEventData)?.Name ?? RoomId; + roomName ??= ((await RoomInfo.GetStateEvent("m.room.name"))?.TypedContent as RoomNameEventContent)?.Name ?? RoomId; - var state = (await RoomInfo.GetStateEvent("m.room.avatar")).TypedContent as RoomAvatarEventData; + var state = (await RoomInfo.GetStateEvent("m.room.avatar")).TypedContent as RoomAvatarEventContent; if (state?.Url is { } url) { roomIcon = MediaResolver.ResolveMediaUri(hs.FullHomeServerDomain, url); // Console.WriteLine($"Got avatar for room {RoomId}: {roomIcon} ({url})"); diff --git a/MatrixRoomUtils.Web/Shared/SimpleComponents/DictionaryEditor.razor b/MatrixRoomUtils.Web/Shared/SimpleComponents/DictionaryEditor.razor deleted file mode 100644 index afd1fdc..0000000 --- a/MatrixRoomUtils.Web/Shared/SimpleComponents/DictionaryEditor.razor +++ /dev/null @@ -1,38 +0,0 @@ -@using LibMatrix.Extensions - - @foreach (var i in Items.Keys) { - var key = i; - - -
- } -
- - -@code { - - [Parameter] - public Dictionary Items { get; set; } = new(); - - [Parameter] - [EditorRequired] - public EventCallback ItemsChanged { get; set; } - - [Parameter] - public Func? KeyFormatter { get; set; } - - [Parameter] - public Action? OnFocusLost { get; set; } - - protected override Task OnInitializedAsync() { - Console.WriteLine($"DictionaryEditor initialized with {Items.Count} items: {Items.ToJson()}"); - return base.OnInitializedAsync(); - } - - private void inputChanged(ChangeEventArgs obj, string key) { - Console.WriteLine($"StringListEditor inputChanged {key} {obj.Value}"); - Items[key] = obj.Value.ToString(); - ItemsChanged.InvokeAsync(); - } - -} diff --git a/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor b/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor deleted file mode 100644 index 966c44d..0000000 --- a/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor +++ /dev/null @@ -1,29 +0,0 @@ -@inject IJSRuntime JsRuntime -@if (isVisible) { - -} -else { - @(Formatter?.Invoke(Value) ?? (IsPassword ? string.Join("", Value.Select(x => '*')) : Value)) -} - -@code { - - [Parameter] - public string Value { get; set; } - - [Parameter] - public bool IsPassword { get; set; } = false; - - [Parameter] - public EventCallback ValueChanged { get; set; } - - [Parameter] - public Func? Formatter { get; set; } - - private bool isVisible { get; set; } = false; - - private ElementReference elementToFocus; - - protected override async Task OnAfterRenderAsync(bool firstRender) => await JsRuntime.InvokeVoidAsync("BlazorFocusElement", elementToFocus); - -} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor.css b/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor.css deleted file mode 100644 index 01b2c6f..0000000 --- a/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor.css +++ /dev/null @@ -1,5 +0,0 @@ -.fancy-textbox-inline { - border-bottom: #ccc solid 1px; - height: 1.4em; - display: inline-block; -} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/SimpleComponents/LinkButton.razor b/MatrixRoomUtils.Web/Shared/SimpleComponents/LinkButton.razor deleted file mode 100644 index b800989..0000000 --- a/MatrixRoomUtils.Web/Shared/SimpleComponents/LinkButton.razor +++ /dev/null @@ -1,20 +0,0 @@ - - @ChildContent - - -@code { - - [Parameter] - public string? href { get; set; } - - [Parameter] - public RenderFragment ChildContent { get; set; } - - [Parameter] - public string? Color { get; set; } - - [Parameter] - public Func? OnClick { get; set; } - -} diff --git a/MatrixRoomUtils.Web/Shared/SimpleComponents/StringListEditor.razor b/MatrixRoomUtils.Web/Shared/SimpleComponents/StringListEditor.razor deleted file mode 100644 index 2bd6ed5..0000000 --- a/MatrixRoomUtils.Web/Shared/SimpleComponents/StringListEditor.razor +++ /dev/null @@ -1,29 +0,0 @@ -@for (var i = 0; i < Items.Count; i++) { - var self = i; - - -
-} - - -@code { - - [Parameter] - public List Items { get; set; } = new(); - - [Parameter] - [EditorRequired] - public EventCallback ItemsChanged { get; set; } - - protected override Task OnInitializedAsync() { - Console.WriteLine($"StringListEditor initialized with {Items.Count} items: {string.Join(",", Items)}"); - return base.OnInitializedAsync(); - } - - private void inputChanged(string obj, int i) { - Console.WriteLine($"StringListEditor inputChanged {i} {obj}"); - Items[i] = obj; - ItemsChanged.InvokeAsync(); - } - -} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/SimpleComponents/ToggleSlider.razor b/MatrixRoomUtils.Web/Shared/SimpleComponents/ToggleSlider.razor deleted file mode 100644 index 1a38e26..0000000 --- a/MatrixRoomUtils.Web/Shared/SimpleComponents/ToggleSlider.razor +++ /dev/null @@ -1,72 +0,0 @@ -@ChildContent - -
- -
- - - -@code { - - [Parameter] - public RenderFragment? ChildContent { get; set; } - - [Parameter] - public bool Value { get; set; } - - [Parameter] - public EventCallback ValueChanged { get; set; } - -} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/BaseTimelineItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/BaseTimelineItem.razor index 5172fa4..e4ee873 100644 --- a/MatrixRoomUtils.Web/Shared/TimelineComponents/BaseTimelineItem.razor +++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/BaseTimelineItem.razor @@ -1,5 +1,6 @@ @using LibMatrix.Responses @using LibMatrix +@using LibMatrix.Homeservers

BaseTimelineItem

@code { @@ -11,6 +12,6 @@ public List Events { get; set; } [Parameter] - public AuthenticatedHomeServer HomeServer { get; set; } + public AuthenticatedHomeserverGeneric Homeserver { get; set; } } diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor index d67fdab..c450211 100644 --- a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor +++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor @@ -1,6 +1,6 @@ -@using LibMatrix.StateEventTypes @using LibMatrix.StateEventTypes.Spec @using LibMatrix.Extensions +@using ArcaneLibs.Extensions @inherits BaseTimelineItem @if (roomMemberData is not null) { @@ -15,7 +15,7 @@ @Event.StateKey changed their display name to @(roomMemberData.Displayname ?? Event.Sender) break; case "join": - joined + joined break; case "leave": @Event.StateKey left @@ -26,8 +26,8 @@ default: @Event.StateKey has an unknown state:
-        @Event.ToJson()
-    
+ @Event.ToJson() + break; } } @@ -42,6 +42,6 @@ else { @code { - private RoomMemberEventData? roomMemberData => Event.TypedContent as RoomMemberEventData; + private RoomMemberEventContent? roomMemberData => Event.TypedContent as RoomMemberEventContent; } diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor index 13cce88..5dd87e0 100644 --- a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor +++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor @@ -1,4 +1,5 @@ @using LibMatrix.Extensions +@using ArcaneLibs.Extensions @inherits BaseTimelineItem
diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineRoomCreateItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineRoomCreateItem.razor
index 8053a47..9c48455 100644
--- a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineRoomCreateItem.razor
+++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineRoomCreateItem.razor
@@ -1,10 +1,11 @@
 @using LibMatrix.StateEventTypes.Spec
 @using LibMatrix.Extensions
+@using ArcaneLibs.Extensions
 @inherits BaseTimelineItem
 
 

@Event.Sender created the room with room version @CreationEventContent.RoomVersion - @CreationEventContent.Federate ? "and" : "without" federating with other servers.
+ @(CreationEventContent.Federate ?? false ? "and" : "without") federating with other servers.
This room is of type @(CreationEventContent.Type ?? "Untyped room (usually a chat room)")

@@ -13,6 +14,6 @@
 
 @code {
 
-    private RoomCreateEventData CreationEventContent => Event.TypedContent as RoomCreateEventData;
+    private RoomCreateEventContent CreationEventContent => Event.TypedContent as RoomCreateEventContent;
 
 }
diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineUnknownItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineUnknownItem.razor
index 8166f8a..69845d9 100644
--- a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineUnknownItem.razor
+++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineUnknownItem.razor
@@ -1,4 +1,5 @@
 @using LibMatrix.Extensions
+@using ArcaneLibs.Extensions
 @inherits BaseTimelineItem
 
 
diff --git a/MatrixRoomUtils.Web/Shared/UserListItem.razor b/MatrixRoomUtils.Web/Shared/UserListItem.razor index a85a68d..7a55380 100644 --- a/MatrixRoomUtils.Web/Shared/UserListItem.razor +++ b/MatrixRoomUtils.Web/Shared/UserListItem.razor @@ -19,7 +19,7 @@ public RenderFragment? ChildContent { get; set; } [Parameter] - public ProfileResponseEventData User { get; set; } + public ProfileResponseEventContent User { get; set; } [Parameter] public string UserId { get; set; } diff --git a/MatrixRoomUtils.Web/_Imports.razor b/MatrixRoomUtils.Web/_Imports.razor index cb08515..a92153d 100644 --- a/MatrixRoomUtils.Web/_Imports.razor +++ b/MatrixRoomUtils.Web/_Imports.razor @@ -12,7 +12,7 @@ @using MatrixRoomUtils.Web.Classes @using MatrixRoomUtils.Web.Shared -@using LinkButton = MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton +@using ArcaneLibs.Blazor.Components @inject NavigationManager NavigationManager @inject MRUStorageWrapper MRUStorage -- cgit 1.5.1