@page "/Rooms/{RoomId}/Space"
@using LibMatrix.Extensions
@using LibMatrix.Responses
@using LibMatrix.RoomTypes
@using ArcaneLibs.Extensions
Room manager - Viewing Space
@foreach (var room in Rooms) {
}
State list
@foreach (var stateEvent in States.OrderBy(x => x.StateKey).ThenBy(x => x.Type)) {
@stateEvent.StateKey/@stateEvent.Type:
@stateEvent.RawContent.ToJson()
}
@code {
[Parameter]
public string RoomId { get; set; } = "invalid!!!!!!";
private GenericRoom? Room { get; set; }
private StateEventResponse[] States { get; set; } = Array.Empty();
private List Rooms { get; } = new();
private List ServersInSpace { get; } = new();
protected override async Task OnInitializedAsync() {
var hs = await MRUStorage.GetCurrentSessionOrNavigate();
if (hs is null) return;
Room = await 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 = await 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()!;
//
// foreach (var stateEvent in States) {
// if (stateEvent.Type == "m.space.child") {
// // if (stateEvent.Content.ToJson().Length < 5) return;
// var roomId = stateEvent.StateKey;
// var room = await 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 Task JoinAllRooms() {
List tasks = Rooms.Select(room => room.JoinAsync(ServersInSpace.ToArray())).ToList();
Task.WaitAll(tasks.ToArray());
return Task.CompletedTask;
}
}