about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Pages/RoomManager
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixRoomUtils.Web/Pages/RoomManager')
-rw-r--r--MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor96
-rw-r--r--MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor11
2 files changed, 5 insertions, 102 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
diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor
index e32b5cb..3225c15 100644
--- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor
+++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor
@@ -14,13 +14,12 @@
 @code {
 
     [Parameter]
-    public string RoomId { get; set; } = "invalid!!!!!!";
+    public string RoomId { get; set; }
 
     private List<MessagesResponse> Messages { get; } = new();
     private List<StateEventResponse> Events { get; } = new();
 
     protected override async Task OnInitializedAsync() {
-        RoomId = RoomId.Replace('~', '.');
         Console.WriteLine("RoomId: " + RoomId);
         var hs = await MRUStorage.GetCurrentSessionOrNavigate();
         if (hs is null) return;
@@ -46,10 +45,10 @@
         _ => typeof(TimelineUnknownItem)
         };
 
-    private Dictionary<string, object> ComponentParameters(Type ComponentType, StateEventResponse Event) => ComponentType switch {
-        Type t when t == typeof(TimelineMessageItem) => new Dictionary<string, object> { { "Event", Event }, { "Events", Events } },
-        Type t when t == typeof(TimelineMemberItem) => new Dictionary<string, object> { { "Event", Event }, { "Events", Events } },
-        _ => new Dictionary<string, object> { { "Event", Event }, { "Events", Events } }
+    private Dictionary<string, object> ComponentParameters(Type componentType, StateEventResponse @event) => componentType switch {
+        not null when componentType == typeof(TimelineMessageItem) => new Dictionary<string, object> { { "Event", @event }, { "Events", Events } },
+        not null when componentType == typeof(TimelineMemberItem) => new Dictionary<string, object> { { "Event", @event }, { "Events", Events } },
+        _ => new Dictionary<string, object> { { "Event", @event }, { "Events", Events } }
         };
 
 }
\ No newline at end of file