@page "/PolicyListEditor/{RoomId}" @using System.Text.Json @using MatrixRoomUtils.Core.Extensions @using MatrixRoomUtils.Core.StateEventTypes @inject ILocalStorageService LocalStorage @inject NavigationManager NavigationManager

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.Content.Entity != null)) { }
Server Reason Expires Actions
Entity: @policyEvent.Content.Entity
State: @policyEvent.StateKey
@policyEvent.Content.Reason @policyEvent.Content.ExpiryDateTime @* *@
Invalid events @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.server" && x.Content.Entity == null)) { }
State key Serialised Contents
@policyEvent.StateKey @policyEvent.Content.ToJson(indent: false, ignoreNull: 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.Content.Entity != null)) { }
Room Reason Expires Actions
Entity: @policyEvent.Content.Entity
State: @policyEvent.StateKey
@policyEvent.Content.Reason @policyEvent.Content.ExpiryDateTime
Invalid events @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && x.Content.Entity == null)) { }
State key Serialised Contents
@policyEvent.StateKey @policyEvent.Content.ToJson(indent: false, ignoreNull: 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.Content.Entity != null)) { @if (_enableAvatars) { } }
User Reason Expires Actions
Entity: @string.Join("", policyEvent.Content.Entity.Take(64))
State: @string.Join("", policyEvent.StateKey.Take(64))
@policyEvent.Content.Reason @policyEvent.Content.ExpiryDateTime
Invalid events @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && x.Content.Entity == null)) { }
State key Serialised Contents
@policyEvent.StateKey @policyEvent.Content.ToJson(indent: false, ignoreNull: 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 = false; static Dictionary avatars = new Dictionary(); static Dictionary servers = new Dictionary(); public static List> PolicyEvents { get; set; } = new(); protected override async Task OnInitializedAsync() { await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); await base.OnInitializedAsync(); // if(RuntimeCache.AccessToken == null || RuntimeCache.CurrentHomeserver == null) if (RuntimeCache.CurrentHomeServer == null) { NavigationManager.NavigateTo("/Login"); return; } RoomId = RoomId.Replace('~', '.'); await LoadStatesAsync(); Console.WriteLine("Policy list editor initialized!"); } private async Task LoadStatesAsync() { // using var client = new HttpClient(); // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalStorageWrapper.AccessToken); // var response = await client.GetAsync($"{LocalStorageWrapper.CurrentHomeserver}/_matrix/client/r0/rooms/{RoomId}/state"); // var Content = await response.Content.ReadAsStringAsync(); // Console.WriteLine(JsonSerializer.Deserialize(Content).ToJson()); // var stateEvents = JsonSerializer.Deserialize>(Content); var room = await RuntimeCache.CurrentHomeServer.GetRoom(RoomId); var stateEventsQuery = await room.GetStateAsync(""); if (stateEventsQuery == null) { Console.WriteLine("state events query is null!!!"); } 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]; RemoteHomeServer server = servers.ContainsKey(hs) ? servers[hs] : await new RemoteHomeServer(userId.Split(':')[1]).Configure(); if (!servers.ContainsKey(hs)) servers.Add(hs, server); var profile = await server.GetProfile(userId); avatars.Add(userId, server.ResolveMediaUri(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.Content.Entity != null)) { await GetAvatar(policyEvent.Content.Entity); } StateHasChanged(); } }