From 0e43e947ca8be0e529f2505a66143cb8b1fcbb8e Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Wed, 12 Jul 2023 00:18:56 +0200 Subject: Changes --- .../Responses/CreateRoomRequest.cs | 22 +- MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj | 1 + MatrixRoomUtils.Web/Pages/About.razor | 32 +- MatrixRoomUtils.Web/Pages/Rooms/Create.razor | 450 +++++++++++---------- MatrixRoomUtils.Web/Shared/ModalWindow.razor | 93 +---- MatrixRoomUtils.Web/Shared/ModalWindow.razor.css | 70 ++++ MatrixRoomUtils.Web/wwwroot/index.html | 2 + MatrixRoomUtils.sln.DotSettings.user | 3 +- 8 files changed, 378 insertions(+), 295 deletions(-) create mode 100644 MatrixRoomUtils.Web/Shared/ModalWindow.razor.css diff --git a/MatrixRoomUtils.Core/Responses/CreateRoomRequest.cs b/MatrixRoomUtils.Core/Responses/CreateRoomRequest.cs index 334c05c..be78a97 100644 --- a/MatrixRoomUtils.Core/Responses/CreateRoomRequest.cs +++ b/MatrixRoomUtils.Core/Responses/CreateRoomRequest.cs @@ -1,6 +1,8 @@ +using System.Reflection; using System.Text.Json.Nodes; using System.Text.Json.Serialization; using System.Text.RegularExpressions; +using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; using MatrixRoomUtils.Core.StateEventTypes; using MatrixRoomUtils.Core.StateEventTypes.Spec; @@ -21,7 +23,7 @@ public class CreateRoomRequest { //we dont want to use this, we want more control // [JsonPropertyName("preset")] // public string Preset { get; set; } = null!; - + [JsonPropertyName("initial_state")] public List InitialState { get; set; } = null!; @@ -39,7 +41,21 @@ public class CreateRoomRequest { /// public StateEvent this[string event_type, string event_key = ""] { - get => InitialState.First(x => x.Type == event_type && x.StateKey == event_key); + get { + var stateEvent = InitialState.FirstOrDefault(x => x.Type == event_type && x.StateKey == event_key); + if (stateEvent == null) { + InitialState.Add(stateEvent = new StateEvent { + Type = event_type, + StateKey = event_key, + TypedContent = Activator.CreateInstance( + StateEvent.KnownStateEventTypes.FirstOrDefault(x => + x.GetCustomAttributes()? + .Any(y => y.EventName == event_type) ?? false) ?? typeof(object) + ) + }); + } + return stateEvent; + } set { var stateEvent = InitialState.FirstOrDefault(x => x.Type == event_type && x.StateKey == event_key); if (stateEvent == null) @@ -57,4 +73,4 @@ public class CreateRoomRequest { return errors; } -} \ No newline at end of file +} diff --git a/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj b/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj index 4bb7aeb..5e72471 100644 --- a/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj +++ b/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj @@ -11,6 +11,7 @@ + diff --git a/MatrixRoomUtils.Web/Pages/About.razor b/MatrixRoomUtils.Web/Pages/About.razor index cf43c4f..b8d9c4a 100644 --- a/MatrixRoomUtils.Web/Pages/About.razor +++ b/MatrixRoomUtils.Web/Pages/About.razor @@ -1,7 +1,9 @@ @page "/About" @using System.Net +@using System.Net.Sockets @inject NavigationManager NavigationManager @inject ILocalStorageService LocalStorage +@using XtermBlazor About @@ -20,6 +22,9 @@

This deployment also serves a copy of the compiled, hosting-ready binaries at /MRU-SRC.tar.xz!

} + + + @code { private bool showBinDownload { get; set; } @@ -34,4 +39,29 @@ await base.OnInitializedAsync(); } -} \ No newline at end of file + + private Xterm _terminal; + + private TerminalOptions _options = new TerminalOptions + { + CursorBlink = true, + CursorStyle = CursorStyle.Block, + Theme = + { + Background = "#17615e", + }, + }; + + private async Task OnFirstRender() { + var message = "Hello, World!\nThis is a terminal emulator!\n\nYou can type stuff here, and it will be sent to the server!\n\nThis is a test of the emergency broadcast system.\n\nThis is only a t"; + _terminal.Options.RendererType = RendererType.Dom; + _terminal.Options.ScreenReaderMode = true; + TcpClient. + for (var i = 0; i < message.Length; i++) { + await _terminal.Write(message[i].ToString()); + + await Task.Delay(50); + _terminal.Options.Theme.Background = $"#{(i * 2):X6}"; + } + } +} diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Create.razor b/MatrixRoomUtils.Web/Pages/Rooms/Create.razor index 4255424..3a98801 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/Create.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/Create.razor @@ -12,213 +12,228 @@

Room Manager - Create Room

@*
@JsonString
*@ - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - -
- @creationEvent.PowerLevelContentOverride.Users.Count members - @foreach (var user in creationEvent.PowerLevelContentOverride.Events.Keys) { - var _event = user; -
- - - - } - @foreach (var user in creationEvent.PowerLevelContentOverride.Users.Keys) { - var _user = user; - - - - - } - - - - - + @if (creationEvent is not null) { + + + + + + + + + + + + + + + + - - - + + + + +
- @creationEvent.InitialState.Count(x => x.Type == "m.room.member") members - @* *@ - @foreach (var member in creationEvent.InitialState.Where(x => x.Type == "m.room.member" && x.StateKey != HomeServer.UserId)) { - + @creationEvent.PowerLevelContentOverride.Users.Count members + @foreach (var user in creationEvent.PowerLevelContentOverride.Events.Keys) { + var _event = user; +
+ + + + } + @foreach (var user in creationEvent.PowerLevelContentOverride.Users.Keys) { + var _user = user; + + + + } - - - @* Initial states, should remain at bottom *@ - - - + + + + - @creationEvent.InitialState.Count(x => !ImplementedStates.Contains(x.Type)) custom states -
Preset: - - @foreach (var createRoomRequest in Presets) { - - } - -
Room name: - -
Room alias (localpart): - -
Room type: - - - - - -
History visibility: - @{ - var historyVisibility = creationEvent["m.room.history_visibility"].TypedContent as HistoryVisibilityEventData; - } - - - - - - -
Guest access:
Preset: - @{ - var guestAccessEvent = creationEvent["m.room.guest_access"].TypedContent as GuestAccessEventData; + @if (Presets is null) { +

Presets is null!

} - - @(guestAccessEvent.IsGuestAccessEnabled ? "Guests can join" : "Guests cannot join") (@guestAccessEvent.GuestAccess) - - - - - -
Room icon: - @{ - var roomAvatarEvent = creationEvent["m.room.avatar"].TypedContent as RoomAvatarEventData; + else { + + @foreach (var createRoomRequest in Presets) { + + } + } - -
-
- -
- -
Permissions:
- - : - - -
: - -
Server ACLs: - @{ - var serverAcl = creationEvent["m.room.server_acls"].TypedContent as ServerACLEventData; - } -
- @((creationEvent["m.room.server_acls"].TypedContent as ServerACLEventData).Allow.Count) allow rules - -
-
- @(creationEvent["m.room.server_acls"].TypedContent as ServerACLEventData).Deny.Count deny rules - -
Room name: + @if (creationEvent.Name is null) { +

creationEvent.Name is null!

+ } + else { + +

(#:@HomeServer.WhoAmI.UserId.Split(':').Last())

+ } +
Room type: + @if (creationEvent._creationContentBaseType is null) { +

creationEvent._creationContentBaseType is null!

+ } + else { + + + + + + } +
History visibility: + + + + + + +
Guest access: + + @(guestAccessEvent.IsGuestAccessEnabled ? "Guests can join" : "Guests cannot join") (@guestAccessEvent.GuestAccess) + + + + + +
Invited members: +
Room icon: + +
+
+ +
+
Permissions:
+ + : + + +
: + +
Initial states: -
- - @code - { - private static readonly string[] ImplementedStates = { "m.room.avatar", "m.room.history_visibility", "m.room.guest_access", "m.room.server_acl" }; +
Server ACLs: + @if (serverAcl?.Allow is null) { +

No allow rules exist!

+ } + else { +
+ @((creationEvent["m.room.server_acls"].TypedContent as ServerACLEventData).Allow.Count) allow rules + @* *@ +
+ } + @if (serverAcl?.Deny is null) { +

No deny rules exist!

+ + } + else { +
+ @((creationEvent["m.room.server_acls"].TypedContent as ServerACLEventData).Deny.Count) deny rules + @* *@ +
+ } +
- @foreach (var initialState in creationEvent.InitialState.Where(x => !ImplementedStates.Contains(x.Type))) { - - - - + + +
- @(initialState.Type): - @if (!string.IsNullOrEmpty(initialState.StateKey)) { -
- (@initialState.StateKey) - } - -
-
@JsonSerializer.Serialize(initialState.RawContent, new JsonSerializerOptions { WriteIndented = true })
-
Invited members: +
+ @creationEvent.InitialState.Count(x => x.Type == "m.room.member") members + @* *@ + @foreach (var member in creationEvent.InitialState.Where(x => x.Type == "m.room.member" && x.StateKey != HomeServer.UserId)) { + } -
- -
- @creationEvent.InitialState.Count initial states - - @foreach (var initialState in creationEvent.InitialState) { - var _state = initialState; - - + + + + @* Initial states, should remain at bottom *@ + + + - + @code + { + private static readonly string[] ImplementedStates = { "m.room.avatar", "m.room.history_visibility", "m.room.guest_access", "m.room.server_acl" }; } -
- @(_state.Type):
- -
Initial states: +
-
-
@JsonSerializer.Serialize(_state.RawContent, new JsonSerializerOptions { WriteIndented = true })
-
-
- - + + @creationEvent.InitialState.Count(x => !ImplementedStates.Contains(x.Type)) custom states + + @foreach (var initialState in creationEvent.InitialState.Where(x => !ImplementedStates.Contains(x.Type))) { + + + + + } +
+ @(initialState.Type): + @if (!string.IsNullOrEmpty(initialState.StateKey)) { +
+ (@initialState.StateKey) + } + +
+
@JsonSerializer.Serialize(initialState.RawContent, new JsonSerializerOptions { WriteIndented = true })
+
+ +
+ @creationEvent.InitialState.Count initial states + + @foreach (var initialState in creationEvent.InitialState) { + var _state = initialState; + + + + + + } +
+ @(_state.Type):
+ +
+
@JsonSerializer.Serialize(_state.RawContent, new JsonSerializerOptions { WriteIndented = true })
+
+
+ + }
-
- Creation JSON +
-         @creationEvent.ToJson(ignoreNull: true) 
-     
-
-
- Creation JSON (with null values) + @creationEvent.ToJson(ignoreNull: true) + + +
-     @creationEvent.ToJson()
-     
-
+ @creationEvent.ToJson() + + +@if (_matrixException is not null) { + +
+            @_matrixException.Message
+        
+
+} @code { @@ -232,22 +247,22 @@ set { creationEvent = Presets[value]; JsonChanged(); - - 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"].TypedContent as GuestAccessEventData; StateHasChanged(); } } - private Dictionary creationEventValidationErrors { get; set; } = new(); + private CreateRoomRequest? creationEvent { get; set; } - private CreateRoomRequest creationEvent { get; set; } - GuestAccessEventData guestAccessEvent { get; set; } - - private Dictionary Presets { get; set; } = new(); + private Dictionary? Presets { get; set; } = new(); private AuthenticatedHomeServer? 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; + protected override async Task OnInitializedAsync() { HomeServer = await MRUStorage.GetCurrentSessionOrNavigate(); if (HomeServer is null) return; @@ -280,7 +295,12 @@ Console.WriteLine("Create room"); Console.WriteLine(creationEvent.ToJson()); creationEvent.CreationContent.Add("rory.gay.created_using", "Rory&::MatrixRoomUtils (https://mru.rory.gay)"); - var id = await HomeServer.CreateRoom(creationEvent); + try { + var id = await HomeServer.CreateRoom(creationEvent); + } + catch (MatrixException e) { + _matrixException = e; + } } private void InviteMember(string mxid) { @@ -295,28 +315,28 @@ }); } - private string GetStateFriendlyName(string key) => key switch { - "m.room.history_visibility" => "History visibility", - "m.room.guest_access" => "Guest access", - "m.room.join_rules" => "Join rules", - "m.room.server_acl" => "Server ACL", - "m.room.avatar" => "Avatar", - _ => key + private string GetStateFriendlyName(string key) => key switch { + "m.room.history_visibility" => "History visibility", + "m.room.guest_access" => "Guest access", + "m.room.join_rules" => "Join rules", + "m.room.server_acl" => "Server ACL", + "m.room.avatar" => "Avatar", + _ => key }; - private string GetPermissionFriendlyName(string key) => key switch { - "m.reaction" => "Send reaction", - "m.room.avatar" => "Change room icon", - "m.room.canonical_alias" => "Change room alias", - "m.room.encryption" => "Enable encryption", - "m.room.history_visibility" => "Change history visibility", - "m.room.name" => "Change room name", - "m.room.power_levels" => "Change power levels", - "m.room.tombstone" => "Upgrade room", - "m.room.topic" => "Change room topic", - "m.room.pinned_events" => "Pin events", - "m.room.server_acl" => "Change server ACLs", - _ => key + private string GetPermissionFriendlyName(string key) => key switch { + "m.reaction" => "Send reaction", + "m.room.avatar" => "Change room icon", + "m.room.canonical_alias" => "Change room alias", + "m.room.encryption" => "Enable encryption", + "m.room.history_visibility" => "Change history visibility", + "m.room.name" => "Change room name", + "m.room.power_levels" => "Change power levels", + "m.room.tombstone" => "Upgrade room", + "m.room.topic" => "Change room topic", + "m.room.pinned_events" => "Pin events", + "m.room.server_acl" => "Change server ACLs", + _ => key }; -} \ No newline at end of file +} diff --git a/MatrixRoomUtils.Web/Shared/ModalWindow.razor b/MatrixRoomUtils.Web/Shared/ModalWindow.razor index 75c2933..216f1f3 100644 --- a/MatrixRoomUtils.Web/Shared/ModalWindow.razor +++ b/MatrixRoomUtils.Web/Shared/ModalWindow.razor @@ -1,95 +1,37 @@
@Title - -
-
- @ChildContent + +
+
+ @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 Action OnCloseClicked { get; set; } - + + [Parameter] + public bool Collapsed { get; set; } = false; private double _x = 60; private double _y = 60; - + protected override void OnInitialized() { _x = X; _y = Y; @@ -97,16 +39,17 @@ 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; @@ -127,4 +70,4 @@ } } -} \ No newline at end of file +} diff --git a/MatrixRoomUtils.Web/Shared/ModalWindow.razor.css b/MatrixRoomUtils.Web/Shared/ModalWindow.razor.css new file mode 100644 index 0000000..b25ab0e --- /dev/null +++ b/MatrixRoomUtils.Web/Shared/ModalWindow.razor.css @@ -0,0 +1,70 @@ +.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; + 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 > .content { + position: relative; + top: 25px; + left: 0; + width: fit-content; + height: fit-content; + min-width: 150px; + min-height: 5px; + max-width: 75vw; + max-height: 75vh; + overflow: auto; + background-color: #111; +} diff --git a/MatrixRoomUtils.Web/wwwroot/index.html b/MatrixRoomUtils.Web/wwwroot/index.html index 9c9e7d0..0598c4d 100644 --- a/MatrixRoomUtils.Web/wwwroot/index.html +++ b/MatrixRoomUtils.Web/wwwroot/index.html @@ -10,6 +10,8 @@ + + diff --git a/MatrixRoomUtils.sln.DotSettings.user b/MatrixRoomUtils.sln.DotSettings.user index 33f4f70..785af7c 100644 --- a/MatrixRoomUtils.sln.DotSettings.user +++ b/MatrixRoomUtils.sln.DotSettings.user @@ -7,13 +7,14 @@ True True + True + - True -- cgit 1.4.1