diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-05-29 09:33:32 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-05-29 09:33:32 +0200 |
commit | 81bf1a1cd1678efd2e73ebc347f51809cffaac46 (patch) | |
tree | f68ae7d6f31a8c167a7baae2492aa56062cf5ba9 | |
parent | Add changes (diff) | |
download | MatrixUtils-81bf1a1cd1678efd2e73ebc347f51809cffaac46.tar.xz |
Bugfixes, improvements
-rw-r--r-- | MatrixRoomUtils.Core/Extensions/ObjectExtensions.cs | 3 | ||||
-rw-r--r-- | MatrixRoomUtils.Core/StateEvent.cs | 15 | ||||
-rw-r--r-- | MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerCreateRoom.razor | 27 |
3 files changed, 34 insertions, 11 deletions
diff --git a/MatrixRoomUtils.Core/Extensions/ObjectExtensions.cs b/MatrixRoomUtils.Core/Extensions/ObjectExtensions.cs index aa1832d..5aa9645 100644 --- a/MatrixRoomUtils.Core/Extensions/ObjectExtensions.cs +++ b/MatrixRoomUtils.Core/Extensions/ObjectExtensions.cs @@ -4,11 +4,12 @@ namespace MatrixRoomUtils.Core.Extensions; public static class ObjectExtensions { - public static string ToJson(this object obj, bool indent = true, bool ignoreNull = false) + public static string ToJson(this object obj, bool indent = true, bool ignoreNull = false, bool unsafeContent = false) { var jso = new JsonSerializerOptions(); if(indent) jso.WriteIndented = true; if(ignoreNull) jso.IgnoreNullValues = true; + if(unsafeContent) jso.Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping; return JsonSerializer.Serialize(obj, jso); } } \ No newline at end of file diff --git a/MatrixRoomUtils.Core/StateEvent.cs b/MatrixRoomUtils.Core/StateEvent.cs index f98d963..6321fb6 100644 --- a/MatrixRoomUtils.Core/StateEvent.cs +++ b/MatrixRoomUtils.Core/StateEvent.cs @@ -24,6 +24,19 @@ public class StateEvent { return (StateEvent<T>)this; } + + public string dtype + { + get + { + string res = GetType().Name switch + { + "StateEvent`1" => $"StateEvent<{Content.GetType().Name}>", + _ => GetType().Name + }; + return res; + } + } } public class StateEvent<T> : StateEvent where T : class @@ -38,5 +51,5 @@ public class StateEvent<T> : StateEvent where T : class } } [JsonPropertyName("content")] - public T Content { get; set; } + public new T Content { get; set; } } \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerCreateRoom.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerCreateRoom.razor index c43e276..cb133dd 100644 --- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerCreateRoom.razor +++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerCreateRoom.razor @@ -65,15 +65,10 @@ <tr> <td>Guest access:</td> <td> -@code -{ - bool test { get; set; } = true; - GuestAccessContent a => creationEvent["m.room.guest_access"].As<GuestAccessContent>().Content; -} -<ToggleSlider @bind-Value="a.IsGuestAccessEnabled">@(a.IsGuestAccessEnabled ? "Guests can join" : "Guests cannot join")</ToggleSlider> + <ToggleSlider Value="guestAccessEvent.IsGuestAccessEnabled" ValueChanged="@((bool v) => { guestAccessEvent.IsGuestAccessEnabled = v; creationEvent["m.room.guest_access"].Content = guestAccessEvent; })">@(guestAccessEvent.IsGuestAccessEnabled ? "Guests can join" : "Guests cannot join")</ToggleSlider> @* <InputSelect @bind-Value="@creationEvent.GuestAccess"> *@ - @* <option value="can_join">Can join</option> *@ - @* <option value="forbidden">Forbidden</option> *@ + @* <option value="can_join">Can join</option> *@ + @* <option value="forbidden">Forbidden</option> *@ @* </InputSelect> *@ </td> </tr> @@ -98,7 +93,7 @@ { var _event = user; <tr> - <td><FancyTextBox Formatter="@GetPermissionFriendlyName" Value="@_event" ValueChanged="val => { creationEvent.PowerLevelContentOverride.Events.ChangeKey(_event, val); }"></FancyTextBox>:</td> + <td><FancyTextBox Formatter="@GetPermissionFriendlyName" Value="@_event" ValueChanged="val => { creationEvent.PowerLevelContentOverride.Events.ChangeKey(_event, val); }"></FancyTextBox>:</td> <td> <input type="number" value="@creationEvent.PowerLevelContentOverride.Events[_event]" @oninput="val => { creationEvent.PowerLevelContentOverride.Events[_event] = int.Parse(val.Value.ToString()); }" @onfocusout="() => { creationEvent.PowerLevelContentOverride.Events = creationEvent.PowerLevelContentOverride.Events.OrderByDescending(x => x.Value).ThenBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value); }"/> </td> @@ -235,12 +230,24 @@ JsonChanged(); 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<GuestAccessContent>().Content; + + Console.WriteLine($"Creation event uncasted: {creationEvent["m.room.guest_access"].ToJson()}"); + Console.WriteLine($"Creation event casted: {creationEvent["m.room.guest_access"].As<GuestAccessContent>().ToJson()}"); + creationEvent["m.room.guest_access"].As<GuestAccessContent>().Content.IsGuestAccessEnabled = false; + 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<GuestAccessContent>().ToJson()}"); + Console.WriteLine($"Creation event casted back: {creationEvent["m.room.guest_access"].As<GuestAccessContent>().ToJson()}"); + StateHasChanged(); } } private Dictionary<string, string> creationEventValidationErrors { get; set; } = new(); private CreateRoomRequest creationEvent { get; set; } + GuestAccessContent guestAccessEvent { get; set; } private Dictionary<string, CreateRoomRequest> Presets { get; set; } = new(); @@ -355,6 +362,7 @@ "m.room.server_acl" => "Change server ACLs", _ => key }; + public class GuestAccessContent { [JsonPropertyName("guest_access")] @@ -366,6 +374,7 @@ set => GuestAccess = value ? "can_join" : "forbidden"; } } + } |