@page "/Moderation/DraupnirProtectedRoomsEditor" @using System.Text.Json.Serialization @using LibMatrix.EventTypes.Spec.State @using LibMatrix.RoomTypes

Edit Draupnir protected rooms


@if (data is not null) {

Current rooms


Tickyboxes

@* Checkbox column *@ @* PL > kick *@ @* PL > ban *@ @* PL > m.room.server_acls event *@ @foreach (var room in Rooms.OrderBy(x => x.RoomName)) { }
Kick?Ban?ACL?Room ID Room name
@(room.PowerLevels.Kick <= room.PowerLevels.GetUserPowerLevel(hs.UserId) ? "X" : "") @(room.PowerLevels.Ban <= room.PowerLevels.GetUserPowerLevel(hs.UserId) ? "X" : "") @(room.PowerLevels.UserHasStatePermission(hs.UserId, RoomServerACLEventContent.EventId) ? "X" : "") @room.Room.RoomId @room.RoomName
}
Apply @code { private DraupnirProtectedRoomsData data { get; set; } = new(); private List Rooms { get; set; } = new(); private AuthenticatedHomeserverGeneric hs { get; set; } protected override async Task OnInitializedAsync() { hs = await RMUStorage.GetCurrentSessionOrNavigate(); if (hs is null) return; data = await hs.GetAccountDataAsync("org.matrix.mjolnir.protected_rooms"); StateHasChanged(); var tasks = (await hs.GetJoinedRooms()).Select(async room => { var plTask = room.GetPowerLevelsAsync(); var roomNameTask = room.GetNameOrFallbackAsync(); var EditorRoomInfo = new EditorRoomInfo { Room = room, IsProtected = data.Rooms.Contains(room.RoomId), RoomName = await roomNameTask, PowerLevels = await plTask }; Rooms.Add(EditorRoomInfo); StateHasChanged(); return Task.CompletedTask; }).ToList(); await Task.WhenAll(tasks); await Task.Delay(500); StateHasChanged(); } private class DraupnirProtectedRoomsData { [JsonPropertyName("rooms")] public List Rooms { get; set; } = new(); } private class EditorRoomInfo { public GenericRoom Room { get; set; } public bool IsProtected { get; set; } public string RoomName { get; set; } public RoomPowerLevelEventContent PowerLevels { get; set; } } private async Task Apply() { Console.WriteLine(string.Join('\n', Rooms.Where(x => x.IsProtected).Select(x => x.Room.RoomId))); data.Rooms = Rooms.Where(x => x.IsProtected).Select(x => x.Room.RoomId).ToList(); await hs.SetAccountDataAsync("org.matrix.mjolnir.protected_rooms", data); } }