about summary refs log tree commit diff
path: root/MatrixRoomUtils.Core
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixRoomUtils.Core')
-rw-r--r--MatrixRoomUtils.Core/Room.cs13
-rw-r--r--MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs23
2 files changed, 36 insertions, 0 deletions
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<CreateEvent>() ?? new CreateEvent(); } + + public async Task<string?> 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<List<Room>> GetRoomsAsync(bool includeRemoved = false) { + var rooms = new List<Room>(); + var state = await GetStateAsync(""); + if (state != null) { + var states = state.Value.Deserialize<StateEventResponse<object>[]>()!; + 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