diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-06-30 03:36:58 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-06-30 03:36:58 +0200 |
commit | bb8c2637af3b7982e7a4b2fd15e2fbec613d0848 (patch) | |
tree | b8075ba7e507aad3f96f354712ad920ac421e474 /MatrixRoomUtils.Web/Pages/RoomState | |
parent | Update stuff (diff) | |
download | MatrixUtils-bb8c2637af3b7982e7a4b2fd15e2fbec613d0848.tar.xz |
Todays progress
Diffstat (limited to 'MatrixRoomUtils.Web/Pages/RoomState')
3 files changed, 40 insertions, 75 deletions
diff --git a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor index 296514c..b2d28f6 100644 --- a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor +++ b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor @@ -45,12 +45,9 @@ public string status = ""; protected override async Task OnInitializedAsync() { - await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); await base.OnInitializedAsync(); - if (RuntimeCache.CurrentHomeServer != null) { - NavigationManager.NavigateTo("/Login"); - return; - } + var hs = await MRUStorage.GetCurrentSessionOrNavigate(); + if (hs is null) return; RoomId = RoomId.Replace('~', '.'); await LoadStatesAsync(); Console.WriteLine("Policy list editor initialized!"); @@ -59,25 +56,20 @@ private DateTime _lastUpdate = DateTime.Now; private async Task LoadStatesAsync() { + var hs = await MRUStorage.GetCurrentSessionOrNavigate(); + var StateLoaded = 0; - using var client = new HttpClient(); - //TODO: can this be improved? - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", RuntimeCache.CurrentHomeServer.AccessToken); - var response = await client.GetAsync($"{RuntimeCache.CurrentHomeServer.FullHomeServerDomain}/_matrix/client/v3/rooms/{RoomId}/state"); - // var response = await client.GetAsync($"http://localhost:5117/matrix-hq-state.json"); - //var _events = await response.Content.ReadFromJsonAsync<Queue<StateEventStruct>>(); - var _data = await response.Content.ReadAsStreamAsync(); - var __events = JsonSerializer.DeserializeAsyncEnumerable<StateEventResponse>(_data); - await foreach (var _ev in __events) { - var e = new StateEventResponse { - Type = _ev.Type, - StateKey = _ev.StateKey, - OriginServerTs = _ev.OriginServerTs, - Content = _ev.Content - }; - Events.Add(e); - if (string.IsNullOrEmpty(e.StateKey)) { - FilteredEvents.Add(e); + 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) { @@ -104,8 +96,8 @@ await Task.Delay(1); FilteredEvents = _FilteredEvents; - if (_shownType != null) - shownEventJson = _FilteredEvents.Where(x => x.Type == _shownType).First().Content.ToJson(indent: true, ignoreNull: true); + if (_shownType is not null) + shownEventJson = _FilteredEvents.Where(x => x.Type == _shownType).First().RawContent.ToJson(indent: true, ignoreNull: true); StateHasChanged(); } diff --git a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateRoomList.razor b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateRoomList.razor index 82b5d75..55c44d9 100644 --- a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateRoomList.razor +++ b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateRoomList.razor @@ -22,13 +22,10 @@ else { public List<string> Rooms { get; set; } = new(); protected override async Task OnInitializedAsync() { - await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); await base.OnInitializedAsync(); - if (RuntimeCache.CurrentHomeServer == null) { - NavigationManager.NavigateTo("/Login"); - return; - } - Rooms = (await RuntimeCache.CurrentHomeServer.GetJoinedRooms()).Select(x => x.RoomId).ToList(); + var hs = await MRUStorage.GetCurrentSessionOrNavigate(); + if (hs is null) return; + Rooms = (await hs.GetJoinedRooms()).Select(x => x.RoomId).ToList(); Console.WriteLine("Fetched joined rooms!"); } diff --git a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor index ff1d9ac..a0072ab 100644 --- a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor +++ b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor @@ -1,6 +1,7 @@ @page "/RoomStateViewer/{RoomId}" @using System.Net.Http.Headers @using System.Text.Json +@using MatrixRoomUtils.Core.Responses @inject ILocalStorageService LocalStorage @inject NavigationManager NavigationManager <h3>Room state viewer - Viewing @RoomId</h3> @@ -18,18 +19,18 @@ </tr> </thead> <tbody> - @foreach (var stateEvent in FilteredEvents.Where(x => x.state_key == "").OrderBy(x => x.origin_server_ts)) { + @foreach (var stateEvent in FilteredEvents.Where(x => x.StateKey == "").OrderBy(x => x.OriginServerTs)) { <tr> - <td>@stateEvent.type</td> + <td>@stateEvent.Type</td> <td style="max-width: fit-Content;"> - <pre>@stateEvent.content</pre> + <pre>@stateEvent.RawContent.ToJson()</pre> </td> </tr> } </tbody> </table> -@foreach (var group in FilteredEvents.GroupBy(x => x.state_key).OrderBy(x => x.Key).Where(x => x.Key != "")) { +@foreach (var group in FilteredEvents.GroupBy(x => x.StateKey).OrderBy(x => x.Key).Where(x => x.Key != "")) { <details> <summary>@group.Key</summary> <table class="table table-striped table-hover" style="width: fit-Content;"> @@ -40,11 +41,11 @@ </tr> </thead> <tbody> - @foreach (var stateEvent in group.OrderBy(x => x.origin_server_ts)) { + @foreach (var stateEvent in group.OrderBy(x => x.OriginServerTs)) { <tr> - <td>@stateEvent.type</td> + <td>@stateEvent.Type</td> <td style="max-width: fit-Content;"> - <pre>@stateEvent.content</pre> + <pre>@stateEvent.RawContent.ToJson()</pre> </td> </tr> } @@ -64,17 +65,14 @@ [Parameter] public string? RoomId { get; set; } - public List<PreRenderedStateEvent> FilteredEvents { get; set; } = new(); - public List<PreRenderedStateEvent> Events { get; set; } = new(); + public List<StateEventResponse> FilteredEvents { get; set; } = new(); + public List<StateEventResponse> Events { get; set; } = new(); public string status = ""; protected override async Task OnInitializedAsync() { - await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); await base.OnInitializedAsync(); - if (RuntimeCache.CurrentHomeServer == null) { - NavigationManager.NavigateTo("/Login"); - return; - } + var hs = await MRUStorage.GetCurrentSessionOrNavigate(); + if (hs is null) return; RoomId = RoomId.Replace('~', '.'); await LoadStatesAsync(); Console.WriteLine("Policy list editor initialized!"); @@ -84,24 +82,13 @@ private async Task LoadStatesAsync() { var StateLoaded = 0; - //TODO: can we improve this? - using var client = new HttpClient(); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", RuntimeCache.CurrentHomeServer.AccessToken); - var response = await client.GetAsync($"{RuntimeCache.CurrentHomeServer.FullHomeServerDomain}/_matrix/client/v3/rooms/{RoomId}/state"); - // var response = await client.GetAsync($"http://localhost:5117/matrix-hq-state.json"); - //var _events = await response.Content.ReadFromJsonAsync<Queue<StateEventStruct>>(); - var _data = await response.Content.ReadAsStreamAsync(); - var __events = JsonSerializer.DeserializeAsyncEnumerable<StateEventStruct>(_data); - await foreach (var _ev in __events) { - var e = new PreRenderedStateEvent { - type = _ev.type, - state_key = _ev.state_key, - origin_server_ts = _ev.origin_server_ts, - content = _ev.content.ToJson(true, true) - }; - Events.Add(e); - if (string.IsNullOrEmpty(e.state_key)) { - FilteredEvents.Add(e); + var hs = await MRUStorage.GetCurrentSessionOrNavigate(); + if (hs is null) return; + var response = (await hs.GetRoom(RoomId)).GetFullStateAsync(); + await foreach (var _ev in response) { + Events.Add(_ev); + if (string.IsNullOrEmpty(_ev.StateKey)) { + FilteredEvents.Add(_ev); } StateLoaded++; if ((DateTime.Now - _lastUpdate).TotalMilliseconds > 100) { @@ -121,7 +108,7 @@ await Task.Delay(1); var _FilteredEvents = Events; if (!ShowMembershipEvents) - _FilteredEvents = _FilteredEvents.Where(x => x.type != "m.room.member").ToList(); + _FilteredEvents = _FilteredEvents.Where(x => x.Type != "m.room.member").ToList(); status = "Done, rerendering!"; StateHasChanged(); @@ -130,17 +117,6 @@ 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 { |