about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/Rooms/PolicyListComponents
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-09-21 16:03:44 +0200
committerRory& <root@rory.gay>2025-09-21 16:03:44 +0200
commitd105d1a7ec709ddb6240a286bbd7be292a9acd1c (patch)
treea7d174479553fbe23b51a66172a3f5429e78e708 /MatrixUtils.Web/Pages/Rooms/PolicyListComponents
parentRoom upgrade CLI changes, policy list work (diff)
downloadMatrixUtils-master.tar.xz
Various fixes HEAD master
Diffstat (limited to 'MatrixUtils.Web/Pages/Rooms/PolicyListComponents')
-rw-r--r--MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListCategoryComponent.razor55
-rw-r--r--MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListEditorHeader.razor47
-rw-r--r--MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListRowComponent.razor92
3 files changed, 130 insertions, 64 deletions
diff --git a/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListCategoryComponent.razor b/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListCategoryComponent.razor

index b52e03f..932e0fe 100644 --- a/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListCategoryComponent.razor +++ b/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListCategoryComponent.razor
@@ -10,43 +10,45 @@ <table class="table table-striped table-hover table-bordered align-middle"> <thead> <tr> + <th>Actions</th> @foreach (var name in PolicyCollection.PropertiesToDisplay!.Keys) { <th>@name</th> } - <th>Actions</th> </tr> </thead> <tbody> @foreach (var policy in PolicyCollection.ActivePolicies.Values.OrderBy(x => x.Policy.RawContent?["entity"]?.GetValue<string>())) { - <PolicyListRowComponent RenderEventInfo="RenderEventInfo" PolicyInfo="@policy" PolicyCollection="@PolicyCollection" Room="@Room"></PolicyListRowComponent> + <PolicyListRowComponent PolicyCollectionStateHasChanged="@StateHasChanged" RenderEventInfo="RenderEventInfo" PolicyInfo="@policy" PolicyCollection="@PolicyCollection" Room="@Room"></PolicyListRowComponent> } </tbody> </table> - <details> - <summary> - <u> - @("Invalid " + PolicyCollection.Name.ToLower()) - </u> - </summary> - <table class="table table-striped table-hover table-bordered align-middle"> - <thead> - <tr> - <th>State key</th> - <th>Json contents</th> - </tr> - </thead> - <tbody> - @foreach (var policy in PolicyCollection.RemovedPolicies.Values) { + @if (RenderInvalidSection) { + <details> + <summary> + <u> + @("Invalid " + PolicyCollection.Name.ToLower()) + </u> + </summary> + <table class="table table-striped table-hover table-bordered align-middle"> + <thead> <tr> - <td>@policy.Policy.StateKey</td> - <td> - <pre>@policy.Policy.RawContent.ToJson(true, false)</pre> - </td> + <th>State key</th> + <th>Json contents</th> </tr> - } - </tbody> - </table> - </details> + </thead> + <tbody> + @foreach (var policy in PolicyCollection.RemovedPolicies.Values) { + <tr> + <td>@policy.Policy.StateKey</td> + <td> + <pre>@policy.Policy.RawContent.ToJson(true, false)</pre> + </td> + </tr> + } + </tbody> + </table> + </details> + } </details> @code { @@ -60,6 +62,9 @@ [Parameter] public bool RenderEventInfo { get; set; } + [Parameter] + public bool RenderInvalidSection { get; set; } = true; + protected override bool ShouldRender() { // if (PolicyCollection is null) return false; diff --git a/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListEditorHeader.razor b/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListEditorHeader.razor
index e82f17d..8585561 100644 --- a/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListEditorHeader.razor +++ b/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListEditorHeader.razor
@@ -12,14 +12,14 @@ <hr/> @* <InputCheckbox @bind-Value="EnableAvatars"></InputCheckbox><label>Enable avatars (WILL EXPOSE YOUR IP TO TARGET HOMESERVERS!)</label> *@ <LinkButton OnClickAsync="@(() => { - CurrentlyEditingEvent = new() { Type = "", RawContent = new() }; - return Task.CompletedTask; - })">Create new policy + CurrentlyEditingEvent = new() { Type = "", RawContent = new() }; + return Task.CompletedTask; + })">Create new policy </LinkButton> <LinkButton OnClickAsync="@(() => { - MassCreatePolicies = true; - return Task.CompletedTask; - })">Create many new policies + MassCreatePolicies = true; + return Task.CompletedTask; + })">Create many new policies </LinkButton> <LinkButton OnClickAsync="@(() => ReloadStateAsync())">Refresh</LinkButton> @@ -33,20 +33,43 @@ // _ = LoadStatesAsync(); })"></MassPolicyEditorModal> } +<br/> +<InputCheckbox Value="@RenderEventInfo" ValueChanged="@RenderEventInfoChanged" ValueExpression="@(() => RenderEventInfo)"/> +<span> Render event info</span> @code { + [Parameter] public required GenericRoom Room { get; set; } - + [Parameter] public required Func<Task> ReloadStateAsync { get; set; } + [Parameter] + public required bool RenderEventInfo { get; set; } + + [Parameter] + public required EventCallback<bool> RenderEventInfoChanged { get; set; } + private string? RoomName { get; set; } private string? RoomAlias { get; set; } private string? DraupnirShortcode { get; set; } - - private StateEventResponse? CurrentlyEditingEvent { get; set { field = value; StateHasChanged(); } } - private bool MassCreatePolicies { get; set { field = value; StateHasChanged(); } } + + private StateEventResponse? CurrentlyEditingEvent { + get; + set { + field = value; + StateHasChanged(); + } + } + + private bool MassCreatePolicies { + get; + set { + field = value; + StateHasChanged(); + } + } protected override async Task OnInitializedAsync() { await Task.WhenAll( @@ -54,12 +77,12 @@ Task.Run(async () => { RoomAlias = (await Room.GetCanonicalAliasAsync())?.Alias; }), Task.Run(async () => { RoomName = await Room.GetNameOrFallbackAsync(); }) ); - + StateHasChanged(); } private async Task UpdatePolicyAsync(StateEventResponse evt) { - Console.WriteLine("UpdatePolicyAsync in PolicyListEditorHeader not yet implementeD!"); + Console.WriteLine("UpdatePolicyAsync in PolicyListEditorHeader not yet implemented!"); } } \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListRowComponent.razor b/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListRowComponent.razor
index 9ac5077..cd432c9 100644 --- a/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListRowComponent.razor +++ b/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListRowComponent.razor
@@ -1,4 +1,5 @@ @using System.Reflection +@using ArcaneLibs.Extensions @using LibMatrix @using LibMatrix.EventTypes.Spec.State.Policy @using LibMatrix.RoomTypes @@ -6,30 +7,6 @@ @if (_isInitialized && IsVisible) { <tr id="@PolicyInfo.Policy.EventId"> - @foreach (var prop in PolicyCollection.PropertiesToDisplay.Values) { - if (prop.Name == "Entity") { - <td> - <span>@TruncateMxid(TypedContent.Entity)</span> - @foreach (var dup in PolicyInfo.DuplicatedBy) { - <br/> - <span>Duplicated by @dup.FriendlyTypeName.ToLower() <a href="@Anchor(dup.EventId!)">@TruncateMxid(dup.RawContent["entity"]?.GetValue<string>())</a></span> - } - @foreach (var dup in PolicyInfo.MadeRedundantBy) { - <br/> - <span>Also matched by @dup.FriendlyTypeName.ToLower() <a href="@Anchor(dup.EventId!)">@TruncateMxid(dup.RawContent["entity"]?.GetValue<string>())</a></span> - } - @if (RenderEventInfo) { - <br/> - <pre> - @PolicyInfo.Policy.Type/@PolicyInfo.Policy.StateKey by @PolicyInfo.Policy.Sender at @PolicyInfo.Policy.OriginServerTs - </pre> - } - </td> - } - else { - <td>@prop.GetGetMethod()?.Invoke(TypedContent, null)</td> - } - } <td> <div style="display: flex; flex-direction: row; gap: 0.5em;"> @* @if (PowerLevels.UserHasStatePermission(Homeserver.WhoAmI.UserId, Policy.Type)) { *@ @@ -41,7 +18,7 @@ </LinkButton> <LinkButton OnClickAsync="@RemovePolicyAsync">Remove</LinkButton> @if (Policy.IsLegacyType) { - <LinkButton OnClickAsync="@RemovePolicyAsync">Update policy type</LinkButton> + <LinkButton OnClickAsync="@RemovePolicyAsync">Update type</LinkButton> } @if (TypedContent.Entity?.StartsWith("@*:", StringComparison.Ordinal) == true) { @@ -66,6 +43,30 @@ } </div> </td> + @foreach (var prop in PolicyCollection.PropertiesToDisplay.Values) { + if (prop.Name == "Entity") { + <td> + <span>@TruncateMxid(TypedContent.Entity)</span> + @foreach (var dup in PolicyInfo.DuplicatedBy) { + <br/> + <span>Duplicated by @dup.FriendlyTypeName.ToLower() <a href="@Anchor(dup.EventId!)">@TruncateMxid(dup.RawContent["entity"]?.GetValue<string>())</a></span> + } + @foreach (var dup in PolicyInfo.MadeRedundantBy) { + <br/> + <span>Also matched by @dup.FriendlyTypeName.ToLower() <a href="@Anchor(dup.EventId!)">@TruncateMxid(dup.RawContent["entity"]?.GetValue<string>())</a></span> + } + @if (RenderEventInfo) { + <br/> + <pre style="margin-bottom: unset;"> + @PolicyInfo.Policy.Type/@PolicyInfo.Policy.StateKey by @PolicyInfo.Policy.Sender at @PolicyInfo.Policy.OriginServerTimestamp + </pre> + } + </td> + } + else { + <td>@prop.GetGetMethod()?.Invoke(TypedContent, null)</td> + } + } </tr> @if (IsEditing) { @@ -95,6 +96,9 @@ [Parameter] public bool RenderEventInfo { get; set; } + [Parameter] + public required Action PolicyCollectionStateHasChanged { get; set; } + private StateEventResponse Policy => PolicyInfo.Policy; private bool IsEditing { @@ -142,8 +146,42 @@ private async Task RemovePolicyAsync() { await Room.SendStateEventAsync(Policy.Type, Policy.StateKey, new { }); - IsVisible = false; - StateHasChanged(); + bool shouldUpdateVisibility = true; + PolicyCollection.ActivePolicies.Remove((Policy.Type, Policy.StateKey)); + PolicyCollection.RemovedPolicies.Add((Policy.Type, Policy.StateKey), PolicyInfo); + if (PolicyInfo.DuplicatedBy.Count > 0) { + foreach (var evt in PolicyInfo.DuplicatedBy) { + var matchingEntry = PolicyCollection.ActivePolicies + .FirstOrDefault(x => StateEvent.Equals(x.Value.Policy, evt)).Value; + var removals = matchingEntry.DuplicatedBy.RemoveAll(x => StateEvent.Equals(x, Policy)); + Console.WriteLine($"Removed {removals} duplicates from {evt.EventId}, matching entry: {matchingEntry.ToJson()}"); + if (PolicyCollection.ViewType == PolicyList.PolicyCollection.SpecialViewType.Duplicates && matchingEntry.DuplicatedBy.Count == 0) { + PolicyCollection.ActivePolicies.Remove((matchingEntry.Policy.Type, matchingEntry.Policy.StateKey)); + PolicyCollection.RemovedPolicies.Add((matchingEntry.Policy.Type, matchingEntry.Policy.StateKey), matchingEntry); + Console.WriteLine($"Also removed {matchingEntry.Policy.EventId} as it is now redundant"); + } + } + + PolicyCollectionStateHasChanged(); + shouldUpdateVisibility = false; + } + + if (PolicyInfo.MadeRedundantBy.Count > 0) { + foreach (var evt in PolicyInfo.MadeRedundantBy) { + var matchingEntry = PolicyCollection.ActivePolicies + .FirstOrDefault(x => StateEvent.Equals(x.Value.Policy, evt)).Value; + var removals = matchingEntry.MadeRedundantBy.RemoveAll(x => StateEvent.Equals(x, Policy)); + Console.WriteLine($"Removed {removals} redundants from {evt.EventId}, matching entry: {matchingEntry.ToJson()}"); + } + + PolicyCollectionStateHasChanged(); + shouldUpdateVisibility = false; + } + + if (shouldUpdateVisibility) { + IsVisible = false; + StateHasChanged(); + } // PolicyEventsByType[policyEvent.MappedType].Remove(policyEvent); // await LoadStatesAsync(); }