@page "/Rooms/{RoomId}/State/Edit" @using System.Net.Http.Headers @using System.Text.Json @using MatrixRoomUtils.Core.Responses @inject ILocalStorageService LocalStorage @inject NavigationManager NavigationManager

Room state editor - Editing @RoomId


@status

Show member events
@foreach (var stateEvent in FilteredEvents.Where(x => x.StateKey != "").Select(x => x.StateKey).Distinct().OrderBy(x => x)) { Console.WriteLine(stateEvent); }
@foreach (var stateEvent in FilteredEvents.Where(x => x.StateKey != shownStateKey).Select(x => x.Type).Distinct().OrderBy(x => x)) { }
@code { //get room list // - sync withroom list filter // Type = support.feline.msc3784 //support.feline.policy.lists.msc.v1 [Parameter] public string? RoomId { get; set; } public List FilteredEvents { get; set; } = new(); public List Events { get; set; } = new(); public string status = ""; 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 DateTime _lastUpdate = DateTime.Now; private async Task LoadStatesAsync() { var hs = await MRUStorage.GetCurrentSessionOrNavigate(); var StateLoaded = 0; var response = (await hs.GetRoom(RoomId)).GetFullStateAsync(); await foreach (var _ev in response) { // var e = new StateEventResponse { // Type = _ev.Type, // StateKey = _ev.StateKey, // OriginServerTs = _ev.OriginServerTs, // Content = _ev.Content // }; Events.Add(_ev); if (string.IsNullOrEmpty(_ev.StateKey)) { FilteredEvents.Add(_ev); } StateLoaded++; if ((DateTime.Now - _lastUpdate).TotalMilliseconds > 100) { _lastUpdate = DateTime.Now; status = $"Loaded {StateLoaded} state events"; StateHasChanged(); await Task.Delay(0); } } StateHasChanged(); } private async Task RebuildFilteredData() { status = "Rebuilding filtered data..."; StateHasChanged(); await Task.Delay(1); var _FilteredEvents = Events; if (!ShowMembershipEvents) _FilteredEvents = _FilteredEvents.Where(x => x.Type != "m.room.member").ToList(); status = "Done, rerendering!"; StateHasChanged(); await Task.Delay(1); FilteredEvents = _FilteredEvents; if (_shownType is not null) shownEventJson = _FilteredEvents.Where(x => x.Type == _shownType).First().RawContent.ToJson(indent: true, ignoreNull: true); StateHasChanged(); } public struct PreRenderedStateEvent { public string content { get; set; } public long origin_server_ts { get; set; } public string state_key { get; set; } public string type { get; set; } // public string Sender { get; set; } // public string EventId { get; set; } // public string UserId { get; set; } // public string ReplacesState { get; set; } } public bool ShowMembershipEvents { get => _showMembershipEvents; set { _showMembershipEvents = value; RebuildFilteredData(); } } private bool _showMembershipEvents; private string _shownStateKey; private string _shownType; private string shownStateKey { get => _shownStateKey; set { _shownStateKey = value; RebuildFilteredData(); } } private string shownType { get => _shownType; set { _shownType = value; RebuildFilteredData(); } } private string shownEventJson { get; set; } }