From 47bd54a9646c4093d638292b67974ad58d4471c4 Mon Sep 17 00:00:00 2001 From: Rory& Date: Mon, 11 Aug 2025 15:14:30 +0200 Subject: Room upgrade CLI, more RMU GUI work --- LibMatrix | 2 +- .../Commands/NewFileCommand.cs | 230 +++++++++++++++++++++ .../MatrixUtils.RoomUpgradeCLI.csproj | 18 ++ MatrixUtils.RoomUpgradeCLI/Program.cs | 28 +++ .../Properties/launchSettings.json | 12 ++ MatrixUtils.RoomUpgradeCLI/RuntimeContext.cs | 5 + .../appsettings.Development.json | 8 + MatrixUtils.RoomUpgradeCLI/appsettings.json | 8 + .../MatrixUtils.Web.Server.csproj | 2 +- MatrixUtils.Web/MatrixUtils.Web.csproj | 8 +- MatrixUtils.Web/Pages/Rooms/Create2.razor | 40 ++-- .../RoomCreateInitialStateOptions.razor | 65 ++++-- .../RoomCreateMembershipOptions.razor | 9 +- .../RoomCreateMsc4321UpgradeOptions.razor | 19 ++ .../RoomCreateStateDisplay.razor | 65 ++++++ .../RoomCreateUpgradeOptions.razor | 52 +++-- MatrixUtils.Web/Program.cs | 8 +- MatrixUtils.sln | 14 ++ 18 files changed, 521 insertions(+), 72 deletions(-) create mode 100644 MatrixUtils.RoomUpgradeCLI/Commands/NewFileCommand.cs create mode 100644 MatrixUtils.RoomUpgradeCLI/MatrixUtils.RoomUpgradeCLI.csproj create mode 100644 MatrixUtils.RoomUpgradeCLI/Program.cs create mode 100644 MatrixUtils.RoomUpgradeCLI/Properties/launchSettings.json create mode 100644 MatrixUtils.RoomUpgradeCLI/RuntimeContext.cs create mode 100644 MatrixUtils.RoomUpgradeCLI/appsettings.Development.json create mode 100644 MatrixUtils.RoomUpgradeCLI/appsettings.json create mode 100644 MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateMsc4321UpgradeOptions.razor create mode 100644 MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateStateDisplay.razor diff --git a/LibMatrix b/LibMatrix index fcad357..1feb7fb 160000 --- a/LibMatrix +++ b/LibMatrix @@ -1 +1 @@ -Subproject commit fcad35734ffe635a85e27349ff09bc035f268062 +Subproject commit 1feb7fb87444807c3fb5d266fa3cb76069c061a1 diff --git a/MatrixUtils.RoomUpgradeCLI/Commands/NewFileCommand.cs b/MatrixUtils.RoomUpgradeCLI/Commands/NewFileCommand.cs new file mode 100644 index 0000000..da2ad2f --- /dev/null +++ b/MatrixUtils.RoomUpgradeCLI/Commands/NewFileCommand.cs @@ -0,0 +1,230 @@ +using ArcaneLibs.Extensions; +using LibMatrix.EventTypes.Spec.State.RoomInfo; +using LibMatrix.Helpers; +using LibMatrix.Homeservers; +using LibMatrix.RoomTypes; +using LibMatrix.Utilities.Bot.Interfaces; + +namespace MatrixUtils.RoomUpgradeCLI.Commands; + +public class NewFileCommand(ILogger logger, IHost host, RuntimeContext ctx, AuthenticatedHomeserverGeneric hs) : IHostedService { + public async Task StartAsync(CancellationToken cancellationToken) { + var rb = ctx.Args.Contains("--upgrade") ? new RoomUpgradeBuilder() : new RoomBuilder(); + if (ctx.Args.Length <= 1) { + await PrintHelp(); + return; + } + var filename = ctx.Args[1]; + if (filename.StartsWith("--")) { + Console.WriteLine("Filename cannot start with --, please provide a valid filename."); + await PrintHelp(); + } + for (int i = 2; i < ctx.Args.Length; i++) { + switch (ctx.Args[i]) { + case "--alias": + rb.AliasLocalPart = ctx.Args[++i]; + break; + case "--avatar-url": + rb.Avatar!.Url = ctx.Args[++i]; + break; + case "--copy-avatar": { + var room = hs.GetRoom(ctx.Args[++i]); + rb.Avatar = await room.GetAvatarUrlAsync() ?? throw new ArgumentException($"Room {room.RoomId} does not have an avatar"); + break; + } + case "--copy-powerlevels": { + var room = hs.GetRoom(ctx.Args[++i]); + rb.PowerLevels = await room.GetPowerLevelsAsync() ?? throw new ArgumentException($"Room {room.RoomId} does not have power levels???"); + break; + } + case "--invite-admin": + var inviteAdmin = ctx.Args[++i]; + if (!inviteAdmin.StartsWith('@')) { + throw new ArgumentException("Invalid user reference: " + inviteAdmin); + } + + rb.Invites.Add(inviteAdmin, "Marked explicitly as admin to be invited"); + break; + case "--invite": + var inviteUser = ctx.Args[++i]; + if (!inviteUser.StartsWith('@')) { + throw new ArgumentException("Invalid user reference: " + inviteUser); + } + + rb.Invites.Add(inviteUser, "Marked explicitly to be invited"); + break; + case "--name": + var nameEvt = rb.Name = new() { Name = "" }; + while (i + 1 < ctx.Args.Length && !ctx.Args[i + 1].StartsWith("--")) { + nameEvt.Name += (nameEvt.Name.Length > 0 ? " " : "") + ctx.Args[++i]; + } + + break; + case "--topic": + var topicEvt = rb.Topic = new() { Topic = "" }; + while (i + 1 < ctx.Args.Length && !ctx.Args[i + 1].StartsWith("--")) { + topicEvt.Topic += (topicEvt.Topic.Length > 0 ? " " : "") + ctx.Args[++i]; + } + + break; + case "--federate": + rb.IsFederatable = bool.Parse(ctx.Args[++i]); + break; + case "--public": + case "--invite-only": + case "--knock": + case "--restricted": + case "--knock_restricted": + case "--private": + rb.JoinRules.JoinRule = ctx.Args[i].Replace("--", "").ToLowerInvariant() switch { + "public" => RoomJoinRulesEventContent.JoinRules.Public, + "invite-only" => RoomJoinRulesEventContent.JoinRules.Invite, + "knock" => RoomJoinRulesEventContent.JoinRules.Knock, + "restricted" => RoomJoinRulesEventContent.JoinRules.Restricted, + "knock_restricted" => RoomJoinRulesEventContent.JoinRules.KnockRestricted, + "private" => RoomJoinRulesEventContent.JoinRules.Private, + _ => throw new ArgumentException("Unknown join rule: " + ctx.Args[i]) + }; + break; + case "--join-rule": + if (i + 1 >= ctx.Args.Length || !ctx.Args[i + 1].StartsWith("--")) { + throw new ArgumentException("Expected join rule after --join-rule"); + } + + rb.JoinRules.JoinRule = ctx.Args[++i].ToLowerInvariant() switch { + "public" => RoomJoinRulesEventContent.JoinRules.Public, + "invite" => RoomJoinRulesEventContent.JoinRules.Invite, + "knock" => RoomJoinRulesEventContent.JoinRules.Knock, + "restricted" => RoomJoinRulesEventContent.JoinRules.Restricted, + "knock_restricted" => RoomJoinRulesEventContent.JoinRules.KnockRestricted, + "private" => RoomJoinRulesEventContent.JoinRules.Private, + _ => throw new ArgumentException("Unknown join rule: " + ctx.Args[i]) + }; + break; + case "--history-visibility": + rb.HistoryVisibility = new RoomHistoryVisibilityEventContent { + HistoryVisibility = ctx.Args[++i].ToLowerInvariant() switch { + "shared" => RoomHistoryVisibilityEventContent.HistoryVisibilityTypes.Shared, + "invited" => RoomHistoryVisibilityEventContent.HistoryVisibilityTypes.Invited, + "joined" => RoomHistoryVisibilityEventContent.HistoryVisibilityTypes.Joined, + "world_readable" => RoomHistoryVisibilityEventContent.HistoryVisibilityTypes.WorldReadable, + _ => throw new ArgumentException("Unknown history visibility: " + ctx.Args[i]) + } + }; + break; + case "--type": + rb.Type = ctx.Args[++i]; + break; + case "--version": + rb.Version = ctx.Args[++i]; + // if (!RoomBuilder.V12PlusRoomVersions.Contains(rb.Version)) { + // logger.LogWarning("Using room version {Version} which is not v12 or higher, this may cause issues with some features.", rb.Version); + // } + break; + // upgrade options + case "--invite-members": + if (rb is not RoomUpgradeBuilder upgradeBuilder) { + throw new InvalidOperationException("Invite members can only be used with room upgrades"); + } + + upgradeBuilder.UpgradeOptions.InviteMembers = true; + break; + case "--invite-powerlevel-users": + if (rb is not RoomUpgradeBuilder upgradeBuilderInvite) { + throw new InvalidOperationException("Invite powerlevel users can only be used with room upgrades"); + } + + upgradeBuilderInvite.UpgradeOptions.InvitePowerlevelUsers = true; + break; + case "--migrate-bans": + if (rb is not RoomUpgradeBuilder upgradeBuilderBan) { + throw new InvalidOperationException("Migrate bans can only be used with room upgrades"); + } + + upgradeBuilderBan.UpgradeOptions.MigrateBans = true; + break; + case "--migrate-empty-state-events": + if (rb is not RoomUpgradeBuilder upgradeBuilderEmpty) { + throw new InvalidOperationException("Migrate empty state events can only be used with room upgrades"); + } + + upgradeBuilderEmpty.UpgradeOptions.MigrateEmptyStateEvents = true; + break; + case "--upgrade-unstable-values": + if (rb is not RoomUpgradeBuilder upgradeBuilderUnstable) { + throw new InvalidOperationException("Update unstable values can only be used with room upgrades"); + } + + upgradeBuilderUnstable.UpgradeOptions.UpgradeUnstableValues = true; + break; + case "--msc4321-policy-list-upgrade": + if (rb is not RoomUpgradeBuilder upgradeBuilderPolicy) { + throw new InvalidOperationException("MSC4321 policy list upgrade can only be used with room upgrades"); + } + + upgradeBuilderPolicy.UpgradeOptions.Msc4321PolicyListUpgradeOptions.Enable = true; + upgradeBuilderPolicy.UpgradeOptions.Msc4321PolicyListUpgradeOptions.UpgradeType = ctx.Args[++i].ToLowerInvariant() switch { + "move" => RoomUpgradeBuilder.Msc4321PolicyListUpgradeOptions.Msc4321PolicyListUpgradeType.Move, + "transition" => RoomUpgradeBuilder.Msc4321PolicyListUpgradeOptions.Msc4321PolicyListUpgradeType.Transition, + _ => throw new ArgumentException("Unknown MSC4321 policy list upgrade type: " + ctx.Args[i]) + }; + break; + + case "--upgrade": + if (rb is not RoomUpgradeBuilder upgradeBuilderUpgrade) { + throw new InvalidOperationException("Upgrade can only be used with room upgrades"); + } + upgradeBuilderUpgrade.OldRoomId = ctx.Args[++i]; + break; + case "--help": + await PrintHelp(); + return; + default: + throw new ArgumentException("Unknown argument: " + ctx.Args[i]); + } + } + + await File.WriteAllTextAsync(filename, rb.ToJson(), cancellationToken); + + await host.StopAsync(cancellationToken); + } + + public async Task StopAsync(CancellationToken cancellationToken) { } + + private async Task PrintHelp() { + Console.WriteLine("Usage: new [filename] [options]"); + Console.WriteLine("Options:"); + Console.WriteLine(" --help Show this help message"); + Console.WriteLine(" --version Set the room version (e.g. 9, 10, 11, 12)"); + Console.WriteLine("-- New room options --"); + Console.WriteLine(" --alias Set the room alias (local part)"); + Console.WriteLine(" --avatar-url Set the room avatar URL"); + Console.WriteLine(" --copy-avatar Copy the avatar from an existing room"); + Console.WriteLine(" --copy-powerlevels Copy power levels from an existing room"); + Console.WriteLine(" --invite-admin Invite a user as an admin (userId must start with '@')"); + Console.WriteLine(" --invite Invite a user (userId must start with '@')"); + Console.WriteLine(" --name Set the room name (can be multiple words)"); + Console.WriteLine(" --topic Set the room topic (can be multiple words)"); + Console.WriteLine(" --federate Set whether the room is federatable"); + Console.WriteLine(" --public Set the room join rule to public"); + Console.WriteLine(" --invite-only Set the room join rule to invite-only"); + Console.WriteLine(" --knock Set the room join rule to knock"); + Console.WriteLine(" --restricted Set the room join rule to restricted"); + Console.WriteLine(" --knock_restricted Set the room join rule to knock_restricted"); + Console.WriteLine(" --private Set the room join rule to private"); + Console.WriteLine(" --join-rule Set the room join rule (public, invite, knock, restricted, knock_restricted, private)"); + Console.WriteLine(" --history-visibility Set the room history visibility (shared, invited, joined, world_readable)"); + Console.WriteLine(" --type Set the room type (e.g. m.space, m.room, support.feline.policy.list.msc.v1 etc.)"); + // upgrade opts + Console.WriteLine("-- Upgrade options --"); + Console.WriteLine(" --upgrade Create a room upgrade file instead of a new room file - WARNING: incompatible with non-upgrade options"); + Console.WriteLine(" --invite-members Invite members during room upgrade"); + Console.WriteLine(" --invite-powerlevel-users Invite users with power levels during room upgrade"); + Console.WriteLine(" --migrate-bans Migrate bans during room upgrade"); + Console.WriteLine(" --migrate-empty-state-events Migrate empty state events during room upgrade"); + Console.WriteLine(" --upgrade-unstable-values Upgrade unstable values during room upgrade"); + Console.WriteLine(" --msc4321-policy-list-upgrade Upgrade MSC4321 policy list"); + Console.WriteLine("WARNING: The --upgrade option is incompatible with options listed under \"New room\", please use the equivalent options in the `apply-upgrade` command instead."); + await host.StopAsync(); + } +} \ No newline at end of file diff --git a/MatrixUtils.RoomUpgradeCLI/MatrixUtils.RoomUpgradeCLI.csproj b/MatrixUtils.RoomUpgradeCLI/MatrixUtils.RoomUpgradeCLI.csproj new file mode 100644 index 0000000..bf76cfe --- /dev/null +++ b/MatrixUtils.RoomUpgradeCLI/MatrixUtils.RoomUpgradeCLI.csproj @@ -0,0 +1,18 @@ + + + + net9.0 + enable + enable + dotnet-MatrixUtils.RoomUpgradeCLI-19ffcbc3-eeaa-4cef-b398-0db2008ca04b + + + + + + + + + + + diff --git a/MatrixUtils.RoomUpgradeCLI/Program.cs b/MatrixUtils.RoomUpgradeCLI/Program.cs new file mode 100644 index 0000000..64de553 --- /dev/null +++ b/MatrixUtils.RoomUpgradeCLI/Program.cs @@ -0,0 +1,28 @@ +using LibMatrix.Services; +using LibMatrix.Utilities.Bot; +using MatrixUtils.RoomUpgradeCLI; +using MatrixUtils.RoomUpgradeCLI.Commands; + +var builder = Host.CreateApplicationBuilder(args); +builder.Services.AddRoryLibMatrixServices(); +builder.Services.AddMatrixBot(); + +if (args.Length == 0) { + Console.WriteLine("No command provided. Use 'new', 'new-upgrade', or 'import-upgrade'."); + return; +} + +builder.Services.AddSingleton(new RuntimeContext() { + Args = args +}); + +if (args[0] == "new") + builder.Services.AddHostedService(); +else if (args[0] == "import-upgrade") { } +else { + Console.WriteLine("Unknown command. Use 'new', 'new-upgrade', or 'import-upgrade'."); + return; +} + +var host = builder.Build(); +host.Run(); \ No newline at end of file diff --git a/MatrixUtils.RoomUpgradeCLI/Properties/launchSettings.json b/MatrixUtils.RoomUpgradeCLI/Properties/launchSettings.json new file mode 100644 index 0000000..76f122f --- /dev/null +++ b/MatrixUtils.RoomUpgradeCLI/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "MatrixUtils.RoomUpgradeCLI": { + "commandName": "Project", + "dotnetRunMessages": true, + "environmentVariables": { + "DOTNET_ENVIRONMENT": "Development" + } + } + } +} diff --git a/MatrixUtils.RoomUpgradeCLI/RuntimeContext.cs b/MatrixUtils.RoomUpgradeCLI/RuntimeContext.cs new file mode 100644 index 0000000..50e6781 --- /dev/null +++ b/MatrixUtils.RoomUpgradeCLI/RuntimeContext.cs @@ -0,0 +1,5 @@ +namespace MatrixUtils.RoomUpgradeCLI; + +public class RuntimeContext { + public string[] Args { get; set; } +} \ No newline at end of file diff --git a/MatrixUtils.RoomUpgradeCLI/appsettings.Development.json b/MatrixUtils.RoomUpgradeCLI/appsettings.Development.json new file mode 100644 index 0000000..b2dcdb6 --- /dev/null +++ b/MatrixUtils.RoomUpgradeCLI/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/MatrixUtils.RoomUpgradeCLI/appsettings.json b/MatrixUtils.RoomUpgradeCLI/appsettings.json new file mode 100644 index 0000000..b2dcdb6 --- /dev/null +++ b/MatrixUtils.RoomUpgradeCLI/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/MatrixUtils.Web.Server/MatrixUtils.Web.Server.csproj b/MatrixUtils.Web.Server/MatrixUtils.Web.Server.csproj index e69774b..f446bf3 100644 --- a/MatrixUtils.Web.Server/MatrixUtils.Web.Server.csproj +++ b/MatrixUtils.Web.Server/MatrixUtils.Web.Server.csproj @@ -8,7 +8,7 @@ - + diff --git a/MatrixUtils.Web/MatrixUtils.Web.csproj b/MatrixUtils.Web/MatrixUtils.Web.csproj index f418340..18204d0 100644 --- a/MatrixUtils.Web/MatrixUtils.Web.csproj +++ b/MatrixUtils.Web/MatrixUtils.Web.csproj @@ -39,10 +39,10 @@ - - - - + + + + diff --git a/MatrixUtils.Web/Pages/Rooms/Create2.razor b/MatrixUtils.Web/Pages/Rooms/Create2.razor index 19f6fbc..4a29847 100644 --- a/MatrixUtils.Web/Pages/Rooms/Create2.razor +++ b/MatrixUtils.Web/Pages/Rooms/Create2.razor @@ -1,14 +1,9 @@ @page "/Rooms/Create2" -@using System.Text.Json -@using System.Reflection -@using ArcaneLibs @using ArcaneLibs.Extensions -@using Blazored.LocalStorage @using LibMatrix -@using LibMatrix.EventTypes.Spec.State.RoomInfo @using LibMatrix.Helpers @using LibMatrix.Responses -@using MatrixUtils.Web.Classes.RoomCreationTemplates +@using LibMatrix.RoomTypes @using MatrixUtils.Web.Pages.Rooms.RoomCreateComponents @inject ILogger logger @* @* ReSharper disable once RedundantUsingDirective - Must not remove this, Rider marks this as "unused" when it's not */ *@ @@ -23,7 +18,7 @@ @if (roomBuilder is RoomUpgradeBuilder roomUpgrade) { - + } else { @* *@ @@ -49,21 +44,13 @@ @* Initial states, should remain at bottom *@ -
+ + Create room -
-
-
- RoomBuilder state - - Show null values
-
-                @roomBuilder.ToJson(ignoreNull: !ShowNullInState)
-            
-
-
} + + + @if (_matrixException is not null) {
@@ -73,13 +60,13 @@
 }
 
 @code {
-    
+
 #region State
 
     [Parameter, SupplyParameterFromQuery(Name = "previousRoomId")]
     public string? PreviousRoomId { get; set; }
-
-    private bool ShowNullInState { get; set; }
+    
+    public GenericRoom? PreviousRoom { get; set; }
 
     private bool Ready { get; set; }
 
@@ -109,7 +96,8 @@
         Homeserver = await sessionStore.GetCurrentHomeserver(navigateOnFailure: true);
         if (Homeserver is null) return;
         if (!string.IsNullOrWhiteSpace(PreviousRoomId)) {
-            roomBuilder = new RoomUpgradeBuilder(Homeserver.GetRoom(PreviousRoomId));
+            roomBuilder = new RoomUpgradeBuilder();
+            PreviousRoom = Homeserver.GetRoom(PreviousRoomId);
         }
 
         roomBuilder.ServerAcls.Allow = ["*"];
@@ -124,14 +112,14 @@
         // Presets = Presets.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
 
         // if (!Presets.ContainsKey("Default")) {
-            // Console.WriteLine($"No default room found in {Presets.Count} presets: {string.Join(", ", Presets.Keys)}");
+        // Console.WriteLine($"No default room found in {Presets.Count} presets: {string.Join(", ", Presets.Keys)}");
         // }
         // else RoomPreset = "Default";
 
         Ready = true;
         StateHasChanged();
         if (roomBuilder is RoomUpgradeBuilder roomUpgrade) {
-            await roomUpgrade.ImportAsync().ConfigureAwait(false);
+            // await roomUpgrade.ImportAsync().ConfigureAwait(false);
             StateHasChanged();
         }
     }
diff --git a/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateInitialStateOptions.razor b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateInitialStateOptions.razor
index 272bd8b..99facbf 100644
--- a/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateInitialStateOptions.razor
+++ b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateInitialStateOptions.razor
@@ -1,4 +1,5 @@
 @using System.Text.Json
+@using ArcaneLibs.Extensions
 @using LibMatrix
 @using LibMatrix.Helpers
 
@@ -8,7 +9,7 @@
                           { "Important room state (before final access rules)", roomBuilder.ImportantState },
                           { "Additional room state (after final access rules)", roomBuilder.InitialState },
                       }) {
-            
+
@code { @@ -17,30 +18,50 @@ @* @displayName: @events.Count(x => !ImplementedStates.Contains(x.Type)) events *@ @displayName: @events.Count events - - @* @foreach (var initialState in events.Where(x => !ImplementedStates.Contains(x.Type))) { *@ + Remove all + + Add new event + +
+ @if (events.Count > 1000) { + Warning: Too many initial state events! (more than 1000) - Please use the save/load feature in the state panel instead. + } + else { + int i = 0; @foreach (var initialState in events) { - - - - +
+ Event @(++i) (@GetRemoveButton(events, initialState)) +
+ @* *@ + +
+
} -
- @(initialState.Type): - @if (!string.IsNullOrEmpty(initialState.StateKey)) { -
- (@initialState.StateKey) - } - -
-
@JsonSerializer.Serialize(initialState.RawContent, new JsonSerializerOptions { WriteIndented = true })
-
+ }
} @code { + [Parameter] public required RoomBuilder roomBuilder { get; set; } @@ -49,4 +70,14 @@ [Parameter] public AuthenticatedHomeserverGeneric Homeserver { get; set; } + + private RenderFragment GetRemoveButton(List events, StateEvent initialState) { + return @ + Remove + ; + } + } \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateMembershipOptions.razor b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateMembershipOptions.razor index 5170d2d..6e300d4 100644 --- a/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateMembershipOptions.razor +++ b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateMembershipOptions.razor @@ -6,10 +6,13 @@
@roomBuilder.Invites.Count members Invite all logged in accounts +
@foreach (var member in roomBuilder.Invites) { - + + @* *@ : +
}
@@ -19,8 +22,10 @@
@roomBuilder.Bans.Count members +
@foreach (var member in roomBuilder.Bans) { - + @* *@ + : } diff --git a/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateMsc4321UpgradeOptions.razor b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateMsc4321UpgradeOptions.razor new file mode 100644 index 0000000..94e9638 --- /dev/null +++ b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateMsc4321UpgradeOptions.razor @@ -0,0 +1,19 @@ +@using LibMatrix.Helpers +
+ Policy list upgrade type: + + + + +
+
+ +@code { + + [Parameter] + public required RoomUpgradeBuilder roomUpgrade { get; set; } + + [Parameter] + public required Action PageStateHasChanged { get; set; } + +} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateStateDisplay.razor b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateStateDisplay.razor new file mode 100644 index 0000000..eb373ba --- /dev/null +++ b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateStateDisplay.razor @@ -0,0 +1,65 @@ +@using System.Text.Json +@using System.Text.Json.Nodes +@using ArcaneLibs.Blazor.Components.Services +@using ArcaneLibs.Extensions +@using LibMatrix.Helpers +@inject BlazorSaveFileService SaveFileService +
+
+ RoomBuilder state + + Show null values
+ Save + +
+
+                @RoomBuilder.ToJson(ignoreNull: !ShowNullInState)
+            
+
+
+ +@code { + + [Parameter] + public required RoomBuilder RoomBuilder { get; set; } + + [Parameter] + public required EventCallback RoomBuilderChanged { get; set; } + + [Parameter] + public required Action PageStateHasChanged { get; set; } + + private bool ShowNullInState { get; set; } + + private async Task SaveFile() { + Console.WriteLine("Saving room builder state to file..."); + await SaveFileService.SaveFileAsync("room-builder.json", RoomBuilder.ToJson(), "application/json"); + } + + private async Task LoadFile(InputFileChangeEventArgs e) { + if (!RoomBuilderChanged.HasDelegate) throw new InvalidOperationException("RoomBuilderChanged must have a delegate."); + if (e.FileCount == 0) return; + Console.WriteLine("Loading room builder state from file..."); + var stream = e.File.OpenReadStream(4 * 1024 * 1024 * 1024L); + var json = await JsonSerializer.DeserializeAsync(stream); + if (json is null) { + Console.WriteLine("Failed to deserialize JSON from file."); + return; + } + + if (json.ContainsKey(nameof(RoomUpgradeBuilder.UpgradeOptions))) { + Console.WriteLine("Got room upgrade builder state."); + RoomBuilder = json.Deserialize(); + } + else { + Console.WriteLine("Got room builder state."); + RoomBuilder = json.Deserialize(); + } + + await RoomBuilderChanged.InvokeAsync(RoomBuilder); + PageStateHasChanged(); + Console.WriteLine("Room builder state loaded from file."); + } + +} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateUpgradeOptions.razor b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateUpgradeOptions.razor index 3e8c3dd..d4c4bfe 100644 --- a/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateUpgradeOptions.razor +++ b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateUpgradeOptions.razor @@ -1,32 +1,50 @@ @using LibMatrix.Helpers +@using LibMatrix.RoomTypes Room upgrade options -
- Upgrading from @roomUpgrade.OldRoom.RoomId - - Invite members + @*
*@ + @* Upgrading from @roomUpgrade.OldRoom.RoomId *@ + + Invite members +
+ + Invite users with powerlevels +
+ + Copy bans (do not use with moderation bots!) +
+ + Include empty state events +
+ + Update unstable namespaced values to spec versions (experimental) +
+ @if (roomUpgrade.Type == "support.feline.policy.lists.msc.v1") { + + Enable MSC4321 support
- - Invite users with powerlevels -
- - Copy bans (do not use with moderation bots!) -
- Apply - -
+ @if (roomUpgrade.UpgradeOptions.Msc4321PolicyListUpgradeOptions.Enable) { + + } + } + Apply + + @*
*@ @code { [Parameter] - public required RoomUpgradeBuilder roomUpgrade { get; set; } + public required GenericRoom OldRoom { get; set; } + [Parameter] + public required RoomUpgradeBuilder roomUpgrade { get; set; } + [Parameter] public required Action PageStateHasChanged { get; set; } diff --git a/MatrixUtils.Web/Program.cs b/MatrixUtils.Web/Program.cs index 57fe03d..cad5393 100644 --- a/MatrixUtils.Web/Program.cs +++ b/MatrixUtils.Web/Program.cs @@ -1,6 +1,7 @@ using System.Net; using System.Text.Json; using System.Text.Json.Serialization; +using ArcaneLibs.Blazor.Components.Services; using Blazored.LocalStorage; using Blazored.SessionStorage; using LibMatrix.Extensions; @@ -20,8 +21,7 @@ builder.RootComponents.Add("head::after"); builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); builder.Services.AddBlazorJSRuntime(); -builder.Services.AddWebWorkerService(webWorkerService => -{ +builder.Services.AddWebWorkerService(webWorkerService => { // Optionally configure the WebWorkerService service before it is used // Default WebWorkerService.TaskPool settings: PoolSize = 0, MaxPoolSize = 1, AutoGrow = true // Below sets TaskPool max size to 2. By default the TaskPool size will grow as needed up to the max pool size. @@ -48,8 +48,7 @@ catch (Exception e) { Console.WriteLine("Could not load appsettings: " + e); } -builder.Logging.AddConfiguration( - builder.Configuration.GetSection("Logging")); +builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging")); builder.Services.AddBlazoredLocalStorage(config => { config.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase; @@ -82,5 +81,6 @@ MatrixHttpClient.LogRequests = false; builder.Services.AddRoryLibMatrixServices(); builder.Services.AddScoped(); +builder.Services.AddSingleton(); // await builder.Build().RunAsync(); await builder.Build().BlazorJSRunAsync(); \ No newline at end of file diff --git a/MatrixUtils.sln b/MatrixUtils.sln index 889232b..093e8e9 100644 --- a/MatrixUtils.sln +++ b/MatrixUtils.sln @@ -74,6 +74,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibMatrix.Federation", "Lib EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibMatrix.FederationTest", "LibMatrix\Utilities\LibMatrix.FederationTest\LibMatrix.FederationTest.csproj", "{960CC2DF-BB1A-4164-A895-834F81B3A113}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatrixUtils.RoomUpgradeCLI", "MatrixUtils.RoomUpgradeCLI\MatrixUtils.RoomUpgradeCLI.csproj", "{F0F10F51-4883-4C70-80D2-24D3AA8C0096}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -468,6 +470,18 @@ Global {960CC2DF-BB1A-4164-A895-834F81B3A113}.Release|x64.Build.0 = Release|Any CPU {960CC2DF-BB1A-4164-A895-834F81B3A113}.Release|x86.ActiveCfg = Release|Any CPU {960CC2DF-BB1A-4164-A895-834F81B3A113}.Release|x86.Build.0 = Release|Any CPU + {F0F10F51-4883-4C70-80D2-24D3AA8C0096}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F0F10F51-4883-4C70-80D2-24D3AA8C0096}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F0F10F51-4883-4C70-80D2-24D3AA8C0096}.Debug|x64.ActiveCfg = Debug|Any CPU + {F0F10F51-4883-4C70-80D2-24D3AA8C0096}.Debug|x64.Build.0 = Debug|Any CPU + {F0F10F51-4883-4C70-80D2-24D3AA8C0096}.Debug|x86.ActiveCfg = Debug|Any CPU + {F0F10F51-4883-4C70-80D2-24D3AA8C0096}.Debug|x86.Build.0 = Debug|Any CPU + {F0F10F51-4883-4C70-80D2-24D3AA8C0096}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F0F10F51-4883-4C70-80D2-24D3AA8C0096}.Release|Any CPU.Build.0 = Release|Any CPU + {F0F10F51-4883-4C70-80D2-24D3AA8C0096}.Release|x64.ActiveCfg = Release|Any CPU + {F0F10F51-4883-4C70-80D2-24D3AA8C0096}.Release|x64.Build.0 = Release|Any CPU + {F0F10F51-4883-4C70-80D2-24D3AA8C0096}.Release|x86.ActiveCfg = Release|Any CPU + {F0F10F51-4883-4C70-80D2-24D3AA8C0096}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- cgit 1.5.1