about summary refs log tree commit diff
path: root/MatrixRoomUtils.Core/Room.cs
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-05-04 00:40:55 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-05-04 00:40:55 +0200
commit5132155714d3953a4a4fb0eba7fe2febe7e5e564 (patch)
tree4383337796a79a391be27235692c0efb8fca23e4 /MatrixRoomUtils.Core/Room.cs
parentFix state reloading (diff)
downloadMatrixUtils-5132155714d3953a4a4fb0eba7fe2febe7e5e564.tar.xz
Fix bugs in policy editor and state viewer
Diffstat (limited to 'MatrixRoomUtils.Core/Room.cs')
-rw-r--r--MatrixRoomUtils.Core/Room.cs8
1 files changed, 6 insertions, 2 deletions
diff --git a/MatrixRoomUtils.Core/Room.cs b/MatrixRoomUtils.Core/Room.cs
index 44364c6..fff5013 100644
--- 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;
     }