about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/Rooms/Space.razor
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixUtils.Web/Pages/Rooms/Space.razor')
-rw-r--r--MatrixUtils.Web/Pages/Rooms/Space.razor100
1 files changed, 100 insertions, 0 deletions
diff --git a/MatrixUtils.Web/Pages/Rooms/Space.razor b/MatrixUtils.Web/Pages/Rooms/Space.razor
new file mode 100644
index 0000000..2dd84a1
--- /dev/null
+++ b/MatrixUtils.Web/Pages/Rooms/Space.razor
@@ -0,0 +1,100 @@
+@page "/Rooms/{RoomId}/Space"
+@using LibMatrix.RoomTypes
+@using ArcaneLibs.Extensions
+@using LibMatrix
+<h3>Room manager - Viewing Space</h3>
+
+<button onclick="@JoinAllRooms">Join all rooms</button>
+@foreach (var room in Rooms) {
+    <RoomListItem Room="room" ShowOwnProfile="true"></RoomListItem>
+}
+
+
+<br/>
+<details style="background: #0002;">
+    <summary style="background: #fff1;">State list</summary>
+    @foreach (var stateEvent in States.OrderBy(x => x.StateKey).ThenBy(x => x.Type)) {
+        <p>@stateEvent.StateKey/@stateEvent.Type:</p>
+        <pre>@stateEvent.RawContent.ToJson()</pre>
+    }
+</details>
+
+@code {
+
+    [Parameter]
+    public string RoomId { get; set; } = "invalid!!!!!!";
+
+    private GenericRoom? Room { get; set; }
+
+    private StateEventResponse[] States { get; set; } = Array.Empty<StateEventResponse>();
+    private List<GenericRoom> Rooms { get; } = new();
+    private List<string> ServersInSpace { get; } = new();
+
+    protected override async Task OnInitializedAsync() {
+        var hs = await RMUStorage.GetCurrentSessionOrNavigate();
+        if (hs is null) return;
+
+        Room = hs.GetRoom(RoomId.Replace('~', '.'));
+
+        var state = Room.GetFullStateAsync();
+        await foreach (var stateEvent in state) {
+            switch (stateEvent.Type) {
+                case "m.space.child": {
+                    var roomId = stateEvent.StateKey;
+                    var room = hs.GetRoom(roomId);
+                    if (room is not null) {
+                        Rooms.Add(room);
+                    }
+                    break;
+                }
+                case "m.room.member": {
+                    var serverName = stateEvent.StateKey.Split(':').Last();
+                    if (!ServersInSpace.Contains(serverName)) {
+                        ServersInSpace.Add(serverName);
+                    }
+                    break;
+                }
+            }
+        }
+        await base.OnInitializedAsync();
+
+    //     var state = await Room.GetStateAsync("");
+    //     if (state is not null) {
+    // // Console.WriteLine(state.Value.ToJson());
+    //         States = state.Value.Deserialize<StateEventResponse[]>()!;
+    //
+    //         foreach (var stateEvent in States) {
+    //             if (stateEvent.Type == "m.space.child") {
+    // // if (stateEvent.Content.ToJson().Length < 5) return;
+    //                 var roomId = stateEvent.StateKey;
+    //                 var room = hs.GetRoom(roomId);
+    //                 if (room is not null) {
+    //                     Rooms.Add(room);
+    //                 }
+    //             }
+    //             else if (stateEvent.Type == "m.room.member") {
+    //                 var serverName = stateEvent.StateKey.Split(':').Last();
+    //                 if (!ServersInSpace.Contains(serverName)) {
+    //                     ServersInSpace.Add(serverName);
+    //                 }
+    //             }
+    //         }
+
+    // if(state.Value.TryGetProperty("Type", out var Type))
+    // {
+    // }
+    // else
+    // {
+    //     //this is fine, apprently...
+    //     //Console.WriteLine($"Room {room.RoomId} has no Content.Type in m.room.create!");
+    // }
+
+    // await base.OnInitializedAsync();
+    }
+
+    private async Task JoinAllRooms() {
+        List<Task<RoomIdResponse>> tasks = Rooms.Select(room => room.JoinAsync(ServersInSpace.ToArray())).ToList();
+        await Task.WhenAll(tasks);
+    }
+
+}