diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-07-02 01:01:09 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-07-02 01:01:09 +0200 |
commit | def33cc092ae2c6defcc218b108b7c99cbfb8581 (patch) | |
tree | ba992ff8c30b7d4e8af0a78350e157e095455a18 /MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor | |
parent | Deduplicate some api calls (diff) | |
download | MatrixUtils-def33cc092ae2c6defcc218b108b7c99cbfb8581.tar.xz |
Prefetch room info
Diffstat (limited to 'MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor')
-rw-r--r-- | MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor | 96 |
1 files changed, 0 insertions, 96 deletions
diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor deleted file mode 100644 index 087adf8..0000000 --- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor +++ /dev/null @@ -1,96 +0,0 @@ -@page "/RoomManager" -@inject ILocalStorageService LocalStorage -@inject NavigationManager NavigationManager -<h3>Room manager</h3> -<hr/> -@if (Rooms.Count == 0) { - <p>You are not in any rooms!</p> -} -else { - <p>You are in @Rooms.Count rooms and @Spaces.Count spaces</p> - <p> - <a href="/RoomManagerCreateRoom">Create room</a> - </p> - - <details open> - <summary>Space List</summary> - @foreach (var room in Spaces) { - <a style="color: unset; text-decoration: unset;" href="/RoomManager/Space/@room.RoomId.Replace('.', '~')"> - <RoomListItem Room="@room" ShowOwnProfile="false"></RoomListItem> - </a> - } - </details> - <details open> - <summary>Room List</summary> - @foreach (var room in Rooms) { - <a style="color: unset; text-decoration: unset;" href="/RoomManager/Room/@room.RoomId.Replace('.', '~')"> - <RoomListItem Room="@room" ShowOwnProfile="true"></RoomListItem> - </a> - } - </details> -} - -<div style="margin-bottom: 4em;"></div> -<LogView></LogView> - -@code { - public List<GenericRoom> Rooms { get; set; } = new(); - public List<GenericRoom> Spaces { get; set; } = new(); - - protected override async Task OnInitializedAsync() { - Console.WriteLine("Initializing room manager"); - Console.WriteLine("Loaded from local storage"); - await base.OnInitializedAsync(); - Console.WriteLine("Initialized base"); - var hs = await MRUStorage.GetCurrentSessionOrNavigate(); - if (hs is null) return; - Console.WriteLine("Fetching joined rooms"); - var _rooms = await hs.GetJoinedRooms(); - StateHasChanged(); - Console.WriteLine($"Got {_rooms.Count} rooms"); - var semaphore = new SemaphoreSlim(10); - var tasks = new List<Task<GenericRoom?>>(); - foreach (var room in _rooms) { - tasks.Add(CheckIfSpace(room, semaphore)); - } - await Task.WhenAll(tasks); - - Console.WriteLine("Fetched joined rooms!"); - } - - private async Task<GenericRoom?> CheckIfSpace(GenericRoom room, SemaphoreSlim semaphore) { - await semaphore.WaitAsync(); - // Console.WriteLine($"Checking if {room.RoomId} is a space"); - try { - var state = await room.GetStateAsync<CreateEvent>("m.room.create"); - if (state is not null) { - //Console.WriteLine(state.Value.ToJson()); - if (state.Type is not 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; - } - -} \ No newline at end of file |