MatrixRoomUtils

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit 5132155714d3953a4a4fb0eba7fe2febe7e5e564
parent 6990fa14d13e63aba7211a1a93c24912531186fb
Author: TheArcaneBrony <myrainbowdash949@gmail.com>
Date:   Thu,  4 May 2023 00:40:55 +0200

Fix bugs in policy editor and state viewer

Diffstat:
MMatrixRoomUtils.Core/Room.cs | 8++++++--
MMatrixRoomUtils.Web/Pages/PolicyListEditorPage.razor | 7++++++-
MMatrixRoomUtils.Web/Pages/PolicyListRoomList.razor | 4+++-
3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/MatrixRoomUtils.Core/Room.cs b/MatrixRoomUtils.Core/Room.cs @@ -17,7 +17,11 @@ public class Room public async Task<JsonElement?> GetStateAsync(string type, string state_key="") { Console.WriteLine($"{RoomId}::_qry[{type}::{state_key}]"); - var res = await _httpClient.GetAsync($"/_matrix/client/r0/rooms/{RoomId}/state/{type}/{state_key}"); + var url = $"/_matrix/client/r0/rooms/{RoomId}/state"; + if (!string.IsNullOrEmpty(state_key)) url += $"/{type}/{state_key}"; + else if (!string.IsNullOrEmpty(type)) url += $"/{type}"; + + var res = await _httpClient.GetAsync(url); if (!res.IsSuccessStatusCode) { Console.WriteLine($"{RoomId}::_qry[{type}::{state_key}]->status=={res.StatusCode}"); @@ -35,7 +39,7 @@ public class Room return null; } Console.WriteLine($"{RoomId}::_qry_name->{res.Value.ToString()}"); - var resn = res?.GetProperty("name").GetString(); + var resn = res?.TryGetProperty("name", out var name) ?? false ? name.GetString() : null; Console.WriteLine($"Got name: {resn}"); return resn; } diff --git a/MatrixRoomUtils.Web/Pages/PolicyListEditorPage.razor b/MatrixRoomUtils.Web/Pages/PolicyListEditorPage.razor @@ -215,7 +215,12 @@ else // Console.WriteLine(JsonSerializer.Deserialize<object>(content).ToJson()); // var stateEvents = JsonSerializer.Deserialize<List<StateEvent>>(content); var room = await RuntimeCache.CurrentHomeServer.GetRoom(RoomId); - var stateEvents = (await room.GetStateAsync(""))!.Value.Deserialize<List<StateEvent>>(); + var stateEventsQuery = await room.GetStateAsync(""); + if (stateEventsQuery == null) + { + Console.WriteLine("state events query is null!!!"); + } + var stateEvents = stateEventsQuery.Value.Deserialize<List<StateEvent>>(); PolicyEvents = stateEvents.Where(x => x.type.StartsWith("m.policy.rule")) .Select(x => JsonSerializer.Deserialize<StateEvent<PolicyRuleStateEventData>>(JsonSerializer.Serialize(x))).ToList(); StateHasChanged(); diff --git a/MatrixRoomUtils.Web/Pages/PolicyListRoomList.razor b/MatrixRoomUtils.Web/Pages/PolicyListRoomList.razor @@ -125,7 +125,9 @@ else // --- // var r = await RuntimeCache.CurrentHomeServer.GetRoom(room); - roomInfo.Shortcode = (await r.GetStateAsync("org.matrix.mjolnir.shortcode")).Value.GetProperty("shortcode").GetString(); + var shortcodeState = await r.GetStateAsync("org.matrix.mjolnir.shortcode"); + if(!shortcodeState.HasValue) return null; + roomInfo.Shortcode = shortcodeState.Value.TryGetProperty("shortcode", out JsonElement shortcode) ? shortcode.GetString() : null; if (roomInfo.Shortcode != null) {