@page "/RoomManager"
@inject ILocalStorageService LocalStorage
@inject NavigationManager NavigationManager
Room manager
@if (Rooms.Count == 0)
{
You are not in any rooms!
@* Loading progress: @checkedRoomCount/@totalRoomCount
*@
}
else
{
You are in @Rooms.Count rooms and @Spaces.Count spaces
Space List
@foreach (var room in Spaces)
{
}
Room List
@foreach (var room in Rooms)
{
}
}
@code {
public List Rooms { get; set; } = new();
public List Spaces { get; set; } = new();
protected override async Task OnInitializedAsync()
{
if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
await base.OnInitializedAsync();
if (RuntimeCache.CurrentHomeServer == null)
{
NavigationManager.NavigateTo("/Login");
return;
}
Rooms = await RuntimeCache.CurrentHomeServer.GetJoinedRooms();
StateHasChanged();
var semaphore = new SemaphoreSlim(1000);
var tasks = new List>();
foreach (var room in Rooms)
{
tasks.Add(CheckIfSpace(room, semaphore));
}
await Task.WhenAll(tasks);
Console.WriteLine("Fetched joined rooms!");
}
private async Task CheckIfSpace(Room room, SemaphoreSlim semaphore)
{
await semaphore.WaitAsync();
try
{
var state = await room.GetStateAsync("m.room.create");
if (state != null)
{
//Console.WriteLine(state.Value.ToJson());
if(state.Value.TryGetProperty("type", out var type))
{
if(type.ToString() == "m.space")
{
Spaces.Add(room);
Rooms.Remove(room);
StateHasChanged();
return room;
}
}
else
{
//this is fine, apprently...
//Console.WriteLine($"Room {room.RoomId} has no content.type in m.room.create!");
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
return null;
}
finally
{
semaphore.Release();
}
return null;
}
}