From 89a14526658e5d061b1aef34ab569e979c9c0cf8 Mon Sep 17 00:00:00 2001 From: Rory& Date: Wed, 6 Aug 2025 03:15:16 +0200 Subject: Various changes, room create/upgrade work --- .../RoomCreateBasicRoomInfoOptions.razor | 52 +++++++++ .../RoomCreateCreateOptions.razor | 92 +++++++++++++++ .../RoomCreateInitialStateOptions.razor | 52 +++++++++ .../RoomCreateMembershipOptions.razor | 55 +++++++++ .../RoomCreatePermissionsOptions.razor | 123 +++++++++++++++++++++ .../RoomCreatePrivacyOptions.razor | 70 ++++++++++++ .../RoomCreateUpgradeOptions.razor | 33 ++++++ 7 files changed, 477 insertions(+) create mode 100644 MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateBasicRoomInfoOptions.razor create mode 100644 MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateCreateOptions.razor create mode 100644 MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateInitialStateOptions.razor create mode 100644 MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateMembershipOptions.razor create mode 100644 MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreatePermissionsOptions.razor create mode 100644 MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreatePrivacyOptions.razor create mode 100644 MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateUpgradeOptions.razor (limited to 'MatrixUtils.Web/Pages/Rooms/RoomCreateComponents') diff --git a/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateBasicRoomInfoOptions.razor b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateBasicRoomInfoOptions.razor new file mode 100644 index 0000000..c1ee202 --- /dev/null +++ b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateBasicRoomInfoOptions.razor @@ -0,0 +1,52 @@ +@using ArcaneLibs +@using LibMatrix.Helpers + + Room name: + + + + + + Room alias: + + + + + + Room icon: + + @if (!string.IsNullOrWhiteSpace(roomBuilder.Avatar.Url)) { + + } + else { + + } +
+ +
+ +
+ + + +@code { + + [Parameter] + public required RoomBuilder roomBuilder { get; set; } + + [Parameter] + public required Action PageStateHasChanged { get; set; } + + [Parameter] + public AuthenticatedHomeserverGeneric Homeserver { get; set; } + + private static readonly SvgIdenticonGenerator IdenticonGenerator = new(); + + private async Task RoomIconFilePicked(InputFileChangeEventArgs obj) { + var res = await Homeserver.UploadFile(obj.File.Name, obj.File.OpenReadStream(), obj.File.ContentType); + Console.WriteLine(res); + roomBuilder.Avatar.Url = res; + PageStateHasChanged(); + } + +} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateCreateOptions.razor b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateCreateOptions.razor new file mode 100644 index 0000000..3f4a73d --- /dev/null +++ b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateCreateOptions.razor @@ -0,0 +1,92 @@ +@using Blazored.LocalStorage +@using LibMatrix.Helpers +@inject ILocalStorageService LocalStorage + + Room type: + + @if (RoomTypes.ContainsKey(roomBuilder.Type ?? "")) { + + @foreach (var type in RoomTypes) { + + } + + + } + else { + + } + + version + @if (Capabilities is null) { + Loading... + } + else { + + @foreach (var version in Capabilities.Capabilities.RoomVersions!.Available!) { + + } + + } + + + + Allow attribution: + + + Allow attribution to Rory&::MatrixUtils + ? + + + +@if (ShowAttributionInfo) { + + This will add the following to the room creation content: +
+
{ "gay.rory.created_using": "Rory&::MatrixUtils (https://mru.rory.gay)" }
+ This is not visible to users unless they manually inspect the room's create event source. +
+} + +@code { + + [Parameter] + public required RoomBuilder roomBuilder { get; set; } + + [Parameter] + public required Action PageStateHasChanged { get; set; } + + [Parameter] + public AuthenticatedHomeserverGeneric Homeserver { get; set; } + + private AuthenticatedHomeserverGeneric.CapabilitiesResponse? Capabilities { get; set; } + + private bool ShowAttributionInfo { + get; + set { + field = value; + StateHasChanged(); + } + } + + private bool AllowAttribution { + get; + set { + field = value; + _ = LocalStorage.SetItemAsync("rmu.room_create.allow_attribution", value); + } + } = true; + + protected override async Task OnInitializedAsync() { + Capabilities = await Homeserver.GetCapabilitiesAsync(); + roomBuilder.Version = Capabilities.Capabilities.RoomVersions!.Default; + AllowAttribution = await LocalStorage.GetItemAsync("rmu.room_create.allow_attribution") ?? true; + } + + private static Dictionary RoomTypes { get; } = new() { + { "", "Room" }, + { "m.space", "Space" }, + { "support.feline.policy.lists.msc.v1", "Policy list" } + }; + +} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateInitialStateOptions.razor b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateInitialStateOptions.razor new file mode 100644 index 0000000..272bd8b --- /dev/null +++ b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateInitialStateOptions.razor @@ -0,0 +1,52 @@ +@using System.Text.Json +@using LibMatrix +@using LibMatrix.Helpers + + Initial room state: + + @foreach (var (displayName, events) in new Dictionary>() { + { "Important room state (before final access rules)", roomBuilder.ImportantState }, + { "Additional room state (after final access rules)", roomBuilder.InitialState }, + }) { +
+ + @code + { + // private static readonly string[] ImplementedStates = { "m.room.avatar", "m.room.history_visibility", "m.room.guest_access", "m.room.server_acl" }; + } + + @* @displayName: @events.Count(x => !ImplementedStates.Contains(x.Type)) events *@ + @displayName: @events.Count events + + @* @foreach (var initialState in events.Where(x => !ImplementedStates.Contains(x.Type))) { *@ + @foreach (var initialState in events) { + + + + + } +
+ @(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; } + + [Parameter] + public required Action PageStateHasChanged { get; set; } + + [Parameter] + public AuthenticatedHomeserverGeneric Homeserver { get; set; } +} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateMembershipOptions.razor b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateMembershipOptions.razor new file mode 100644 index 0000000..5170d2d --- /dev/null +++ b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateMembershipOptions.razor @@ -0,0 +1,55 @@ +@using ArcaneLibs.Extensions +@using LibMatrix.Helpers + + Invited members: + +
+ @roomBuilder.Invites.Count members + Invite all logged in accounts + @foreach (var member in roomBuilder.Invites) { + + : + + } +
+ + + + Banned members: + +
+ @roomBuilder.Bans.Count members + @foreach (var member in roomBuilder.Bans) { + + : + + } +
+ + + +@code { + + [Parameter] + public required RoomBuilder roomBuilder { get; set; } + + [Parameter] + public required Action PageStateHasChanged { get; set; } + + [Parameter] + public AuthenticatedHomeserverGeneric Homeserver { get; set; } + + private async Task InviteAllSessions() { + var sessions = await sessionStore.GetAllSessions(); + foreach (var session in sessions) { + if (roomBuilder.Invites.ContainsKey(session.Value.Auth.UserId) || session.Value.Auth.UserId == Homeserver!.WhoAmI.UserId) continue; + Console.WriteLine("Inviting " + session.Value.Auth.UserId); + roomBuilder.Invites.Add(session.Value.Auth.UserId, null); + Console.WriteLine("--"); + } + + Console.WriteLine("Got all sessions, invited: " + string.Join(", ", roomBuilder.Invites.Keys)); + StateHasChanged(); + } + +} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreatePermissionsOptions.razor b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreatePermissionsOptions.razor new file mode 100644 index 0000000..ba28b82 --- /dev/null +++ b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreatePermissionsOptions.razor @@ -0,0 +1,123 @@ +@using ArcaneLibs.Extensions +@using LibMatrix.Helpers + + Permissions: +
+ + @if (roomBuilder.Version is "org.matrix.hydra.11" or "12") { + @(roomBuilder.AdditionalCreators.Count + 1) creators, + } + @roomBuilder.PowerLevels.Users.Count members, @roomBuilder.PowerLevels.Events.Count events + + + @if (roomBuilder.Version is "org.matrix.hydra.11" or "12") { + Creators: +
+ @Homeserver.WhoAmI.UserId (you - to change, visit the homepage.) +
+ + +
+ } + + Events:
+ @foreach (var eventType in roomBuilder.PowerLevels.Events.Keys) { + var _event = eventType; + + + - + +
+ + + : +
+ + + + + + } + + + + + + + + + Users:
+ @foreach (var user in roomBuilder.PowerLevels.Users.Keys) { + var _user = user; + + + - + +
+ + + : +
+ + + + + + } + + + + + + + +
+ + + +@code { + + [Parameter] + public required RoomBuilder roomBuilder { get; set; } + + [Parameter] + public required Action PageStateHasChanged { get; set; } + + [Parameter] + public AuthenticatedHomeserverGeneric Homeserver { get; set; } + + 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", + "org.matrix.msc4284.policy" => "Change policy server", + "m.room.guest_access" => "Change guest access", + _ => key + }; + +} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreatePrivacyOptions.razor b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreatePrivacyOptions.razor new file mode 100644 index 0000000..76f61c4 --- /dev/null +++ b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreatePrivacyOptions.razor @@ -0,0 +1,70 @@ +@using LibMatrix.Helpers + + Join rules: + + + + + + + + + + + + History visibility: + + + + + + + + + + + Guest access: + + + Allow guests to join + ? + + + + Server ACLs: + + @if (roomBuilder.ServerAcls?.Allow is null) { +

No allow rules exist!

+ Create sane defaults + } + else { +
+ @(roomBuilder.ServerAcls.Allow?.Count) allow rules + +
+ } + @if (roomBuilder.ServerAcls?.Deny is null) { +

No deny rules exist!

+ Create sane defaults + } + else { +
+ @(roomBuilder.ServerAcls.Deny?.Count) deny rules + +
+ } + + + +@code { + + [Parameter] + public required RoomBuilder roomBuilder { get; set; } + + [Parameter] + public required Action PageStateHasChanged { get; set; } + + [Parameter] + public AuthenticatedHomeserverGeneric Homeserver { get; set; } + +} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateUpgradeOptions.razor b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateUpgradeOptions.razor new file mode 100644 index 0000000..3e8c3dd --- /dev/null +++ b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateUpgradeOptions.razor @@ -0,0 +1,33 @@ +@using LibMatrix.Helpers + + Room upgrade options + +
+ Upgrading from @roomUpgrade.OldRoom.RoomId + + Invite members +
+ + Invite users with powerlevels +
+ + Copy bans (do not use with moderation bots!) +
+ Apply + +
+ + + +@code { + + [Parameter] + public required RoomUpgradeBuilder roomUpgrade { get; set; } + + [Parameter] + public required Action PageStateHasChanged { get; set; } + +} \ No newline at end of file -- cgit 1.5.1