@page "/Rooms/{RoomId}/Policies"
@using MatrixRoomUtils.Core.StateEventTypes
@using System.Text.Json
@using MatrixRoomUtils.Core.Helpers
@using MatrixRoomUtils.Core.Responses
@using MatrixRoomUtils.Core.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.
Enable avatars (WILL EXPOSE YOUR IP TO TARGET HOMESERVERS!)
@if (!PolicyEvents.Any(x => x.Type == "m.policy.rule.server")) {
No server policies
}
else {
Server policies
Server
Reason
Expires
Actions
@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;
Entity: @policyData.Entity State: @policyEvent.StateKey
@policyData.Reason
@policyData.ExpiryDateTime
await RemovePolicyAsync(policyEvent)" *@>Edit
@* await RemovePolicyAsync(policyEvent)" #1#>Remove *@
}
Redacted events
State key
Serialised Contents
@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;
@policyEvent.StateKey
@policyEvent.RawContent.ToJson(false, true)
}
}
@if (!PolicyEvents.Any(x => x.Type == "m.policy.rule.room")) {
No room policies
}
else {
Room policies
Room
Reason
Expires
Actions
@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;
Entity: @policyData.Entity State: @policyEvent.StateKey
@policyData.Reason
@policyData.ExpiryDateTime
await RemovePolicyAsync(policyEvent)" *@>Remove
}
Redacted events
State key
Serialised Contents
@foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && (x.TypedContent as PolicyRuleStateEventData).Entity == null)) {
@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) {
}
User
Reason
Expires
Actions
@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) {
}
Entity: @string.Join("", policyData.Entity.Take(64)) State: @string.Join("", policyEvent.StateKey.Take(64))
@policyData.Reason
@policyData.ExpiryDateTime
await RemovePolicyAsync(policyEvent)" *@>Remove
}
Redacted events
State key
Serialised Contents
@foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && (x.TypedContent as PolicyRuleStateEventData).Entity == null)) {
@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();
}
}