@page "/Rooms/{RoomId}/Policies" @using LibMatrix.StateEventTypes @using System.Text.Json @using LibMatrix @using LibMatrix.Extensions @using LibMatrix.Helpers @using LibMatrix.Responses @using LibMatrix.StateEventTypes.Spec

Policy list editor - Editing @RoomId


This policy list contains @PolicyEvents.Count(x => x.Type == "m.policy.rule.server") server bans, @PolicyEvents.Count(x => x.Type == "m.policy.rule.room") room bans and @PolicyEvents.Count(x => x.Type == "m.policy.rule.user") user bans.

@if (!PolicyEvents.Any(x => x.Type == "m.policy.rule.server")) {

No server policies

} else {

Server policies


@foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.server" && (x.TypedContent as PolicyRuleStateEventData).Entity is not null)) { var policyData = policyEvent.TypedContent as PolicyRuleStateEventData; }
Server Reason Expires Actions
Entity: @policyData.Entity
State: @policyEvent.StateKey
@policyData.Reason @policyData.ExpiryDateTime @* *@
Redacted events @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.server" && (x.TypedContent as PolicyRuleStateEventData).Entity == null)) { var policyData = policyEvent.TypedContent as PolicyRuleStateEventData; }
State key Serialised Contents
@policyEvent.StateKey @policyEvent.RawContent.ToJson(false, true)
} @if (!PolicyEvents.Any(x => x.Type == "m.policy.rule.room")) {

No room policies

} else {

Room policies


@foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && (x.TypedContent as PolicyRuleStateEventData).Entity is not null)) { var policyData = policyEvent.TypedContent as PolicyRuleStateEventData; }
Room Reason Expires Actions
Entity: @policyData.Entity
State: @policyEvent.StateKey
@policyData.Reason @policyData.ExpiryDateTime
Redacted events @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && (x.TypedContent as PolicyRuleStateEventData).Entity == null)) { }
State key Serialised Contents
@policyEvent.StateKey @policyEvent.RawContent!.ToJson(false, true)
} @if (!PolicyEvents.Any(x => x.Type == "m.policy.rule.user")) {

No user policies

} else {

User policies


@if (_enableAvatars) { } @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && (x.TypedContent as PolicyRuleStateEventData).Entity is not null)) { var policyData = policyEvent.TypedContent as PolicyRuleStateEventData; @if (_enableAvatars) { } }
User Reason Expires Actions
Entity: @string.Join("", policyData.Entity.Take(64))
State: @string.Join("", policyEvent.StateKey.Take(64))
@policyData.Reason @policyData.ExpiryDateTime
Redacted events @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && (x.TypedContent as PolicyRuleStateEventData).Entity == null)) { }
State key Serialised Contents
@policyEvent.StateKey @policyEvent.RawContent.ToJson(false, true)
} @code { //get room list // - sync withroom list filter // Type = support.feline.msc3784 //support.feline.policy.lists.msc.v1 [Parameter] public string? RoomId { get; set; } private bool _enableAvatars; static readonly Dictionary avatars = new(); static readonly Dictionary servers = new(); public static List PolicyEvents { get; set; } = new(); protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); var hs = await MRUStorage.GetCurrentSessionOrNavigate(); if (hs is null) return; RoomId = RoomId.Replace('~', '.'); await LoadStatesAsync(); Console.WriteLine("Policy list editor initialized!"); } private async Task LoadStatesAsync() { var hs = await MRUStorage.GetCurrentSessionOrNavigate(); if (hs is null) return; var room = await hs.GetRoom(RoomId); var states = room.GetFullStateAsync(); await foreach (var state in states) { if (!state.Type.StartsWith("m.policy.rule")) continue; PolicyEvents.Add(state); } // var stateEventsQuery = await room.GetStateAsync(""); // var stateEvents = stateEventsQuery.Value.Deserialize>(); // PolicyEvents = stateEvents.Where(x => x.Type.StartsWith("m.policy.rule")) // .Select(x => JsonSerializer.Deserialize(JsonSerializer.Serialize(x))).ToList(); StateHasChanged(); } private async Task GetAvatar(string userId) { try { if (avatars.ContainsKey(userId)) return; var hs = userId.Split(':')[1]; var server = servers.ContainsKey(hs) ? servers[hs] : new RemoteHomeServer(userId.Split(':')[1]); if (!servers.ContainsKey(hs)) servers.Add(hs, server); var profile = await server.GetProfile(userId); avatars.Add(userId, MediaResolver.ResolveMediaUri(server.FullHomeServerDomain, profile.AvatarUrl)); servers.Add(userId, server); StateHasChanged(); } catch { // ignored } } private async Task GetAllAvatars() { foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && (x.TypedContent as PolicyRuleStateEventData).Entity is not null)) { await GetAvatar((policyEvent.TypedContent as PolicyRuleStateEventData).Entity); } StateHasChanged(); } }