2 files changed, 173 insertions, 0 deletions
diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor
new file mode 100644
index 0000000..6d27679
--- /dev/null
+++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor
@@ -0,0 +1,96 @@
+@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>
+ @* <p>Loading progress: @checkedRoomCount/@totalRoomCount</p> *@
+}
+else
+{
+ <p>You are in @Rooms.Count rooms and @Spaces.Count spaces</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="true"></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<Room> Rooms { get; set; } = new();
+ public List<Room> 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<Task<Room?>>();
+ foreach (var room in Rooms)
+ {
+ tasks.Add(CheckIfSpace(room, semaphore));
+ }
+ await Task.WhenAll(tasks);
+
+ Console.WriteLine("Fetched joined rooms!");
+ }
+
+ private async Task<Room?> 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;
+ }
+}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor
new file mode 100644
index 0000000..4a5bddf
--- /dev/null
+++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor
@@ -0,0 +1,77 @@
+@page "/RoomManager/Space/{RoomId}"
+@using MatrixRoomUtils.Core.Extensions
+@using System.Text.Json
+<h3>Room manager - Viewing Space</h3>
+
+<button onclick="@JoinAllRooms">Join all rooms</button>
+@foreach (var room in Rooms)
+{
+ <RoomListItem Room="room" ShowOwnProfile="true"></RoomListItem>
+}
+
+
+<br/>
+<details style="background: #0002;">
+ <summary style="background: #fff1;">State list</summary>
+ @foreach (var stateEvent in States.OrderBy(x => x.state_key).ThenBy(x => x.type))
+ {
+ <p>@stateEvent.state_key/@stateEvent.type:</p>
+ <pre>@stateEvent.content.ToJson()</pre>
+ }
+</details>
+
+@code {
+
+ [Parameter]
+ public string RoomId { get; set; } = "invalid!!!!!!";
+
+ private Room? Room { get; set; }
+
+ private StateEvent<object>[] States { get; set; } = Array.Empty<StateEvent<object>>();
+ private List<Room> Rooms { get; set; } = new();
+
+ protected override async Task OnInitializedAsync()
+ {
+ await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+ Room = await RuntimeCache.CurrentHomeServer.GetRoom(RoomId.Replace('~', '.'));
+ var state = await Room.GetStateAsync("");
+ if (state != null)
+ {
+ Console.WriteLine(state.Value.ToJson());
+ States = state.Value.Deserialize<StateEvent<object>[]>()!;
+
+ foreach (var stateEvent in States)
+ {
+ if (stateEvent.type == "m.space.child")
+ {
+ // if (stateEvent.content.ToJson().Length < 5) return;
+ var roomId = stateEvent.state_key;
+ var room = await RuntimeCache.CurrentHomeServer.GetRoom(roomId);
+ if (room != null)
+ {
+ Rooms.Add(room);
+ }
+ }
+ }
+
+ // 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 async Task JoinAllRooms()
+ {
+ foreach (var room in Rooms)
+ {
+ room.JoinAsync();
+ }
+ }
+
+}
\ No newline at end of file
|