@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
Create room
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()
{
Console.WriteLine("Initializing room manager");
await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
Console.WriteLine("Loaded from local storage");
await base.OnInitializedAsync();
Console.WriteLine("Initialized base");
if (RuntimeCache.CurrentHomeServer == null)
{
NavigationManager.NavigateTo("/Login");
return;
}
Console.WriteLine("Fetching joined rooms");
var _rooms = await RuntimeCache.CurrentHomeServer.GetJoinedRooms();
StateHasChanged();
Console.WriteLine($"Got {_rooms.Count} rooms");
var semaphore = new SemaphoreSlim(10);
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();
// Console.WriteLine($"Checking if {room.RoomId} is a space");
try
{
var state = await room.GetStateAsync("m.room.create");
if (state != null)
{
//Console.WriteLine(state.Value.ToJson());
if (state.Type != null)
{
if (state.Type == "m.space")
{
Console.WriteLine($"Room {room.RoomId} is a space!");
Spaces.Add(room);
StateHasChanged();
return room;
}
else
{
Console.WriteLine($"Encountered unknown room type {state.Type}");
}
}
else
{
Rooms.Add(room);
//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;
}
}