about summary refs log tree commit diff
path: root/MatrixRoomUtils.Core/Room.cs
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-05-03 18:40:53 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-05-03 18:40:53 +0200
commit3d3edeae16252a311704b390cfad6faa435a8b84 (patch)
tree34974194435fbe9789de5140ef9a9c0ddb834c74 /MatrixRoomUtils.Core/Room.cs
parentAdd policy room discovery ,add room state viewer (diff)
downloadMatrixUtils-3d3edeae16252a311704b390cfad6faa435a8b84.tar.xz
Refactor
Diffstat (limited to 'MatrixRoomUtils.Core/Room.cs')
-rw-r--r--MatrixRoomUtils.Core/Room.cs44
1 files changed, 44 insertions, 0 deletions
diff --git a/MatrixRoomUtils.Core/Room.cs b/MatrixRoomUtils.Core/Room.cs
new file mode 100644
index 0000000..6cb439a
--- /dev/null
+++ b/MatrixRoomUtils.Core/Room.cs
@@ -0,0 +1,44 @@
+using System.Net.Http.Headers;
+using System.Net.Http.Json;
+using System.Text.Json;
+
+namespace MatrixRoomUtils;
+
+public class Room
+{
+    private readonly HttpClient _httpClient;
+    public string RoomId { get; set; }
+
+    public Room(HttpClient httpClient, string roomId)
+    {
+        _httpClient = httpClient;
+        RoomId = roomId;
+    }
+    
+    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}");
+        if (!res.IsSuccessStatusCode)
+        {
+            Console.WriteLine($"{RoomId}::_qry[{type}::{state_key}]->status=={res.StatusCode}");
+            return null;
+        }
+        return await res.Content.ReadFromJsonAsync<JsonElement>();
+    }
+    public async Task<string?> GetNameAsync()
+    {   
+        Console.WriteLine($"{RoomId}::_qry_name");
+        var res = await GetStateAsync("m.room.name");
+        if (!res.HasValue)
+        {
+            Console.WriteLine($"{RoomId}::_qry_name->null");
+            return null;
+        }
+        Console.WriteLine($"{RoomId}::_qry_name->{res.Value.ToString()}");
+        var resn = res?.GetProperty("name").GetString();
+        Console.WriteLine($"Got name: {resn}");
+        return resn;
+    }
+    
+}
\ No newline at end of file