From 3c0f32505405eb893d9260ab29381dff1dfbe036 Mon Sep 17 00:00:00 2001 From: Rory& Date: Sun, 7 Jul 2024 20:25:48 +0200 Subject: Add space parent update tool --- MatrixUtils.Web/Pages/Rooms/Space.razor | 87 ++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 40 deletions(-) (limited to 'MatrixUtils.Web/Pages/Rooms/Space.razor') 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 @@ @foreach (var room in Rooms) { - + @* *@ }
State list - @foreach (var stateEvent in States.OrderBy(x => x.StateKey).ThenBy(x => x.Type)) { -

@stateEvent.StateKey/@stateEvent.Type:

+ @foreach (var stateEvent in States.OrderBy(x => x.Type).ThenBy(x => x.StateKey)) { +

@stateEvent.Type/@stateEvent.StateKey:

@stateEvent.RawContent.ToJson()
}
@@ -26,13 +26,15 @@ private GenericRoom? Room { get; set; } - private StateEventResponse[] States { get; set; } = Array.Empty(); + private List States { get; set; } = []; private List Rooms { get; } = new(); private List 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()!; - // - // 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()!; + // + // 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> 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> 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()); + // } } } -- cgit 1.4.1