about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/Rooms/Space.razor
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-07-07 20:25:48 +0200
committerRory& <root@rory.gay>2024-07-07 20:25:48 +0200
commit3c0f32505405eb893d9260ab29381dff1dfbe036 (patch)
treefb950d2c0346ac4a7f298cf6642ea1d9aaa1fe29 /MatrixUtils.Web/Pages/Rooms/Space.razor
parentSome cleanup, update libs (diff)
downloadMatrixUtils-main-pre-media-refactor.tar.xz
Diffstat (limited to 'MatrixUtils.Web/Pages/Rooms/Space.razor')
-rw-r--r--MatrixUtils.Web/Pages/Rooms/Space.razor87
1 files changed, 47 insertions, 40 deletions
diff --git a/MatrixUtils.Web/Pages/Rooms/Space.razor b/MatrixUtils.Web/Pages/Rooms/Space.razor
index 01ab1c4..bec0a72 100644
--- a/MatrixUtils.Web/Pages/Rooms/Space.razor
+++ b/MatrixUtils.Web/Pages/Rooms/Space.razor
@@ -6,15 +6,15 @@
 
 <button onclick="@JoinAllRooms">Join all rooms</button>
 @foreach (var room in Rooms) {
-    <RoomListItem Room="room" ShowOwnProfile="true"></RoomListItem>
+    @* <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>
+    @foreach (var stateEvent in States.OrderBy(x => x.Type).ThenBy(x => x.StateKey)) {
+        <p>@stateEvent.Type/@stateEvent.StateKey:</p>
         <pre>@stateEvent.RawContent.ToJson()</pre>
     }
 </details>
@@ -26,13 +26,15 @@
 
     private GenericRoom? Room { get; set; }
 
-    private StateEventResponse[] States { get; set; } = Array.Empty<StateEventResponse>();
+    private List<StateEventResponse> States { get; set; } = [];
     private List<GenericRoom> Rooms { get; } = new();
     private List<string> ServersInSpace { get; } = new();
+    private AuthenticatedHomeserverGeneric Homeserver { get; set; } = null!;
 
     protected override async Task OnInitializedAsync() {
         var hs = await RMUStorage.GetCurrentSessionOrNavigate();
         if (hs is null) return;
+        Homeserver = hs;
 
         Room = hs.GetRoom(RoomId.Replace('~', '.'));
 
@@ -55,49 +57,54 @@
                     break;
                 }
             }
+            States.Add(stateEvent);
         }
-        await base.OnInitializedAsync();
+        
+        StateHasChanged();
 
-    //     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);
-    //                 }
-    //             }
-    //         }
+        //     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!");
-    // }
+        // 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();
+        // await base.OnInitializedAsync();
     }
 
     private async Task JoinAllRooms() {
-        // List<Task<RoomIdResponse>> tasks = Rooms.Select(room => room.JoinAsync(ServersInSpace.ToArray())).ToList();
-        // await Task.WhenAll(tasks);
-        foreach (var room in Rooms) {
-            await room.JoinAsync(ServersInSpace.ToArray());
-        }
+        var joinedRooms = await Homeserver.GetJoinedRooms(); 
+        List<Task<RoomIdResponse>> tasks = Rooms
+            .Where(x=>!joinedRooms.Any(y=>y.RoomId == x.RoomId))
+            .Select(room => room.JoinAsync(ServersInSpace.ToArray())).ToList();
+        await Task.WhenAll(tasks);
+        // foreach (var room in Rooms) {
+            // await room.JoinAsync(ServersInSpace.ToArray());
+        // }
     }
 
 }