From f866946fbbe962c712049327ade9dcbd43900295 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Sun, 25 Jun 2023 03:07:05 +0200 Subject: Working state, refactored Rory&::LibMatrix --- MatrixRoomUtils.Web/Pages/DebugTools.razor | 1 - MatrixRoomUtils.Web/Pages/DevOptions.razor | 1 - MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor | 1 - .../Pages/KnownHomeserverList.razor | 1 - MatrixRoomUtils.Web/Pages/LoginPage.razor | 2 +- MatrixRoomUtils.Web/Pages/MediaLocator.razor | 2 +- .../Pages/PolicyList/PolicyListEditorPage.razor | 3 +- .../Pages/PolicyList/PolicyListRoomList.razor | 1 - .../Pages/RoomManager/RoomManagerCreateRoom.razor | 38 ++++++++-------------- .../Pages/RoomManager/RoomManagerSpace.razor | 1 - .../Pages/RoomState/RoomStateEditorPage.razor | 2 +- .../Pages/RoomState/RoomStateViewerPage.razor | 3 +- 12 files changed, 19 insertions(+), 37 deletions(-) (limited to 'MatrixRoomUtils.Web/Pages') diff --git a/MatrixRoomUtils.Web/Pages/DebugTools.razor b/MatrixRoomUtils.Web/Pages/DebugTools.razor index da5c172..4e4cec8 100644 --- a/MatrixRoomUtils.Web/Pages/DebugTools.razor +++ b/MatrixRoomUtils.Web/Pages/DebugTools.razor @@ -1,6 +1,5 @@ @page "/Debug" @using System.Reflection -@using MatrixRoomUtils.Core.Extensions @using MatrixRoomUtils.Core.Interfaces @inject ILocalStorageService LocalStorage @inject NavigationManager NavigationManager diff --git a/MatrixRoomUtils.Web/Pages/DevOptions.razor b/MatrixRoomUtils.Web/Pages/DevOptions.razor index 0843d5f..cdb5693 100644 --- a/MatrixRoomUtils.Web/Pages/DevOptions.razor +++ b/MatrixRoomUtils.Web/Pages/DevOptions.razor @@ -1,5 +1,4 @@ @page "/DevOptions" -@using MatrixRoomUtils.Core.Extensions @inject NavigationManager NavigationManager @inject ILocalStorageService LocalStorage diff --git a/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor b/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor index 1fe13bd..858fad9 100644 --- a/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor +++ b/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor @@ -1,5 +1,4 @@ @page "/HSAdmin/RoomQuery" -@using MatrixRoomUtils.Core.Extensions @using MatrixRoomUtils.Core.Filters @using MatrixRoomUtils.Core.Responses.Admin @using MatrixRoomUtils.Web.Shared.SimpleComponents diff --git a/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor b/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor index 8031146..80dbfd1 100644 --- a/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor +++ b/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor @@ -1,6 +1,5 @@ @page "/KnownHomeserverList" @using System.Text.Json -@using MatrixRoomUtils.Core.Extensions @using System.Diagnostics @using MatrixRoomUtils.Core.Responses

Known Homeserver List

diff --git a/MatrixRoomUtils.Web/Pages/LoginPage.razor b/MatrixRoomUtils.Web/Pages/LoginPage.razor index 3b78817..9df7fa6 100644 --- a/MatrixRoomUtils.Web/Pages/LoginPage.razor +++ b/MatrixRoomUtils.Web/Pages/LoginPage.razor @@ -52,7 +52,7 @@ var userinfo = new UserInfo { LoginResponse = result }; - userinfo.Profile = await (await new AuthenticatedHomeServer(result.HomeServer, result.AccessToken, TODO).Configure()).GetProfile(result.UserId); + userinfo.Profile = await RuntimeCache.CurrentHomeServer.GetProfile(result.UserId); RuntimeCache.LastUsedToken = result.AccessToken; RuntimeCache.LoginSessions.Add(result.AccessToken, userinfo); diff --git a/MatrixRoomUtils.Web/Pages/MediaLocator.razor b/MatrixRoomUtils.Web/Pages/MediaLocator.razor index 36cd8e6..38d1514 100644 --- a/MatrixRoomUtils.Web/Pages/MediaLocator.razor +++ b/MatrixRoomUtils.Web/Pages/MediaLocator.razor @@ -61,7 +61,7 @@ await sem.WaitAsync(); var httpClient = new HttpClient { BaseAddress = new Uri(hs) }; httpClient.Timeout = TimeSpan.FromSeconds(5); - var rmu = mxcUrl.Replace("mxc://", $"{hs}/_matrix/media/r0/download/"); + var rmu = mxcUrl.Replace("mxc://", $"{hs}/_matrix/media/v3/download/"); try { var res = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Head, rmu)); if (res.IsSuccessStatusCode) { diff --git a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor index 76b4384..0840ebf 100644 --- a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor +++ b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor @@ -1,5 +1,4 @@ @page "/PolicyListEditor/{RoomId}" -@using MatrixRoomUtils.Core.Extensions @using MatrixRoomUtils.Core.StateEventTypes @using System.Text.Json @using MatrixRoomUtils.Core.Responses @@ -210,7 +209,7 @@ else { 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 response = await client.GetAsync($"{LocalStorageWrapper.CurrentHomeserver}/_matrix/client/v3/rooms/{RoomId}/state"); // var Content = await response.Content.ReadAsStringAsync(); // Console.WriteLine(JsonSerializer.Deserialize(Content).ToJson()); // var stateEvents = JsonSerializer.Deserialize>(Content); diff --git a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor index 20eab7a..8f711b5 100644 --- a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor +++ b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor @@ -1,5 +1,4 @@ @page "/PolicyListEditor" -@using MatrixRoomUtils.Core.Extensions @inject ILocalStorageService LocalStorage @inject NavigationManager NavigationManager

Policy list editor - Room list

diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerCreateRoom.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerCreateRoom.razor index 5cfda77..80d852a 100644 --- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerCreateRoom.razor +++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerCreateRoom.razor @@ -1,9 +1,8 @@ @page "/RoomManagerCreateRoom" -@using MatrixRoomUtils.Core.Extensions @using MatrixRoomUtils.Core.Responses @using System.Text.Json -@using System.Text.Json.Serialization @using System.Reflection +@using MatrixRoomUtils.Core.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 @@ -53,12 +52,12 @@ History visibility: - - - - - - + @* *@ + @* *@ + @* *@ + @* *@ + @* *@ + @* *@ @@ -220,15 +219,15 @@ OverwriteWrappedPropertiesFromEvent(); creationEvent.PowerLevelContentOverride.Events = creationEvent.PowerLevelContentOverride.Events.OrderByDescending(x => x.Value).ThenBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value); creationEvent.PowerLevelContentOverride.Users = creationEvent.PowerLevelContentOverride.Users.OrderByDescending(x => x.Value).ThenBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value); - guestAccessEvent = creationEvent["m.room.guest_access"].As().Content; + guestAccessEvent = creationEvent["m.room.guest_access"].As().Content; Console.WriteLine($"Creation event uncasted: {creationEvent["m.room.guest_access"].ToJson()}"); - Console.WriteLine($"Creation event casted: {creationEvent["m.room.guest_access"].As().ToJson()}"); - creationEvent["m.room.guest_access"].As().Content.IsGuestAccessEnabled = true; + Console.WriteLine($"Creation event casted: {creationEvent["m.room.guest_access"].As().ToJson()}"); + creationEvent["m.room.guest_access"].As().Content.IsGuestAccessEnabled = true; Console.WriteLine("-- Created new guest access content --"); Console.WriteLine($"Creation event uncasted: {creationEvent["m.room.guest_access"].ToJson()}"); - Console.WriteLine($"Creation event casted: {creationEvent["m.room.guest_access"].As().ToJson()}"); - Console.WriteLine($"Creation event casted back: {creationEvent["m.room.guest_access"].As().ToJson()}"); + Console.WriteLine($"Creation event casted: {creationEvent["m.room.guest_access"].As().ToJson()}"); + Console.WriteLine($"Creation event casted back: {creationEvent["m.room.guest_access"].As().ToJson()}"); StateHasChanged(); } } @@ -236,7 +235,7 @@ private Dictionary creationEventValidationErrors { get; set; } = new(); private CreateRoomRequest creationEvent { get; set; } - GuestAccessContent guestAccessEvent { get; set; } + GuestAccessData guestAccessEvent { get; set; } private Dictionary Presets { get; set; } = new(); @@ -275,7 +274,7 @@ Console.WriteLine("Overwriting wrapped properties"); Console.WriteLine($"Allow: {ServerACLAllowRules.Count}: {string.Join(", ", ServerACLAllowRules)}"); Console.WriteLine($"Deny: {ServerACLDenyRules.Count}: {string.Join(", ", ServerACLDenyRules)}"); - creationEvent.ServerACLs = new ServerACL { + creationEvent.ServerACLs = new ServerACLData { Allow = ServerACLAllowRules, Deny = ServerACLDenyRules, AllowIpLiterals = creationEvent.ServerACLs.AllowIpLiterals @@ -336,14 +335,5 @@ _ => key }; - public class GuestAccessContent { - [JsonPropertyName("guest_access")] - public string GuestAccess { get; set; } - - public bool IsGuestAccessEnabled { - get => GuestAccess == "can_join"; - set => GuestAccess = value ? "can_join" : "forbidden"; - } - } } diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor index ab650d1..a9c71c4 100644 --- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor +++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor @@ -1,5 +1,4 @@ @page "/RoomManager/Space/{RoomId}" -@using MatrixRoomUtils.Core.Extensions @using System.Text.Json @using MatrixRoomUtils.Core.Responses

Room manager - Viewing Space

diff --git a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor index fa5b6a8..296514c 100644 --- a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor +++ b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor @@ -63,7 +63,7 @@ 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($"{RuntimeCache.CurrentHomeServer.FullHomeServerDomain}/_matrix/client/v3/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(); diff --git a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor index bfd4d10..ff1d9ac 100644 --- a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor +++ b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor @@ -1,5 +1,4 @@ @page "/RoomStateViewer/{RoomId}" -@using MatrixRoomUtils.Core.Extensions @using System.Net.Http.Headers @using System.Text.Json @inject ILocalStorageService LocalStorage @@ -88,7 +87,7 @@ //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($"{RuntimeCache.CurrentHomeServer.FullHomeServerDomain}/_matrix/client/v3/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(); -- cgit 1.5.1