about summary refs log tree commit diff
path: root/MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs
blob: 6eaa73b27c9f9aa66b01b4db0b5c9476b384c66f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using System.Text.Json;
using MatrixRoomUtils.Core.Extensions;
using MatrixRoomUtils.Core.Interfaces;
using MatrixRoomUtils.Core.Responses;

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[]>()!;
            foreach (var stateEvent in states.Where(x => x.Type == "m.space.child")) {
                var roomId = stateEvent.StateKey;
                if(stateEvent.TypedContent.ToJson() != "{}" || includeRemoved)
                    rooms.Add(await RuntimeCache.CurrentHomeServer.GetRoom(roomId));
            }
        }

        return rooms;
    }
}