From b48f78a381058c188ed61e6f372fbf86d95ad2f9 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Wed, 14 Jun 2023 22:26:39 +0200 Subject: Add changes --- MatrixRoomUtils.Core/Room.cs | 13 +++++++++++++ MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs (limited to 'MatrixRoomUtils.Core') diff --git a/MatrixRoomUtils.Core/Room.cs b/MatrixRoomUtils.Core/Room.cs index a867c0c..2d6dc46 100644 --- a/MatrixRoomUtils.Core/Room.cs +++ b/MatrixRoomUtils.Core/Room.cs @@ -3,6 +3,7 @@ using System.Text.Json; using System.Text.Json.Serialization; using System.Web; using MatrixRoomUtils.Core.Extensions; +using MatrixRoomUtils.Core.RoomTypes; namespace MatrixRoomUtils.Core; @@ -12,6 +13,8 @@ public class Room { public Room(HttpClient httpClient, string roomId) { _httpClient = httpClient; RoomId = roomId; + if(GetType() != typeof(SpaceRoom)) + AsSpace = new SpaceRoom(_httpClient, RoomId); } public string RoomId { get; set; } @@ -137,6 +140,16 @@ public class Room { return res.Value.Deserialize() ?? new CreateEvent(); } + + public async Task GetRoomType() { + var res = await GetStateAsync("m.room.create"); + if (!res.HasValue) return null; + if (res.Value.TryGetProperty("type", out var type)) return type.GetString(); + return null; + } + + + public SpaceRoom AsSpace; } public class MessagesResponse { diff --git a/MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs b/MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs new file mode 100644 index 0000000..e8d4823 --- /dev/null +++ b/MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs @@ -0,0 +1,23 @@ +using System.Text.Json; +using MatrixRoomUtils.Core.Extensions; + +namespace MatrixRoomUtils.Core.RoomTypes; + +public class SpaceRoom : Room { + public SpaceRoom(HttpClient httpClient, string roomId) : base(httpClient, roomId) { } + + public async Task> GetRoomsAsync(bool includeRemoved = false) { + var rooms = new List(); + var state = await GetStateAsync(""); + if (state != null) { + var states = state.Value.Deserialize[]>()!; + foreach (var stateEvent in states.Where(x => x.Type == "m.space.child")) { + var roomId = stateEvent.StateKey; + if(stateEvent.Content.ToJson() != "{}" || includeRemoved) + rooms.Add(await RuntimeCache.CurrentHomeServer.GetRoom(roomId)); + } + } + + return rooms; + } +} \ No newline at end of file -- cgit 1.5.1