about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Pages
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixRoomUtils.Web/Pages')
-rw-r--r--MatrixRoomUtils.Web/Pages/ModalTest.razor2
-rw-r--r--MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor107
-rw-r--r--MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor96
-rw-r--r--MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor11
-rw-r--r--MatrixRoomUtils.Web/Pages/Rooms/Index.razor9
-rw-r--r--MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor (renamed from MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor)3
6 files changed, 13 insertions, 215 deletions
diff --git a/MatrixRoomUtils.Web/Pages/ModalTest.razor b/MatrixRoomUtils.Web/Pages/ModalTest.razor
index f32c672..79c7fcd 100644
--- a/MatrixRoomUtils.Web/Pages/ModalTest.razor
+++ b/MatrixRoomUtils.Web/Pages/ModalTest.razor
@@ -16,7 +16,7 @@
 
 @code {
 
-    private Dictionary<int, WindowInfo> _windowInfos = new Dictionary<int, WindowInfo>();
+    private Dictionary<int, WindowInfo> _windowInfos = new();
 
     private class WindowInfo {
         public double X;
diff --git a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor
deleted file mode 100644
index 4db2b5a..0000000
--- a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor
+++ /dev/null
@@ -1,107 +0,0 @@
-@page "/PolicyListEditor"
-@using System.Text.Json.Serialization
-@using MatrixRoomUtils.Core.Interfaces
-@using MatrixRoomUtils.Core.StateEventTypes
-@inject ILocalStorageService LocalStorage
-@inject NavigationManager NavigationManager
-<h3>Policy list editor - Room list</h3>
-<hr/>
-
-@if (PolicyRoomList.Count == 0) {
-    <p>No policy rooms found.</p>
-    <p>Loading progress: @checkedRoomCount/@totalRoomCount</p>
-}
-else {
-    @if (checkedRoomCount != totalRoomCount) {
-        <p>Loading progress: @checkedRoomCount/@totalRoomCount</p>
-    }
-    foreach (var s in PolicyRoomList) {
-        <a style="color: unset; text-decoration: unset;" href="/PolicyListEditor/@s.RoomId.Replace('.', '~')">
-            <RoomListItem RoomId="@s.RoomId">
-                <br/>
-                <span>Shortcode: @s.Shortcode</span>
-            </RoomListItem>
-        </a>
-        @* <a href="@(NavigationManager.Uri + "/" + s.RoomId.Replace('.', '~'))">[@s.Shortcode] @s.Name (@s.RoomId)</a> *@
-        @* <br/> *@
-    }
-}
-
-<div style="margin-bottom: 4em;"></div>
-<LogView></LogView>
-
-@code {
-    //get room list
-    // - sync withroom list filter
-    // Type = support.feline.msc3784
-    //support.feline.policy.lists.msc.v1
-
-    public List<PolicyRoomInfo> PolicyRoomList { get; set; } = new();
-
-    private int checkedRoomCount { get; set; }
-    private int totalRoomCount { get; set; }
-
-    protected override async Task OnInitializedAsync() {
-        await base.OnInitializedAsync();
-        var hs = await MRUStorage.GetCurrentSessionOrNavigate();
-        if (hs is null) return;
-        await EnumeratePolicyRooms();
-        Console.WriteLine("Policy list editor initialized!");
-    }
-
-    private async Task EnumeratePolicyRooms() {
-        var hs = await MRUStorage.GetCurrentSession();
-        var rooms = await hs.GetJoinedRooms();
-        totalRoomCount = rooms.Count;
-        StateHasChanged();
-
-        var semaphore = new SemaphoreSlim(8);
-        var tasks = new List<Task<PolicyRoomInfo?>>();
-        foreach (var room in rooms) {
-            tasks.Add(GetPolicyRoomInfo(room.RoomId, semaphore));
-        }
-        var results = await Task.WhenAll(tasks);
-        PolicyRoomList.AddRange(results.Where(x => x is not null).Select(x => x.Value));
-
-        Console.WriteLine($"Detected policy lists: {PolicyRoomList.ToJson()}");
-    }
-
-    private async Task<PolicyRoomInfo?> GetPolicyRoomInfo(string room, SemaphoreSlim semaphore) {
-        try {
-            await semaphore.WaitAsync();
-            var hs = await MRUStorage.GetCurrentSession();
-            PolicyRoomInfo roomInfo = new() {
-                RoomId = room
-            };
-            var r = await hs.GetRoom(room);
-            var shortcodeState = await r.GetStateAsync<MjolnirShortcodeEventData>("org.matrix.mjolnir.shortcode");
-            roomInfo.Shortcode = shortcodeState.Shortcode;
-
-            if (roomInfo.Shortcode is not null) {
-                roomInfo.Name = await r.GetNameAsync();
-                return roomInfo;
-            }
-
-            return null;
-        }
-        finally {
-            checkedRoomCount++;
-            StateHasChanged();
-            semaphore.Release();
-        }
-    }
-
-    
-
-    public struct PolicyRoomInfo {
-        public
-            string RoomId { get; set; }
-
-        public
-            string? Shortcode { get; set; }
-
-        public
-            string? Name { get; set; }
-    }
-
-}
\ No newline at end of file
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
diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor
index 932748d..d88d5b2 100644
--- a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor
+++ b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor
@@ -1,5 +1,6 @@
 @page "/Rooms"
 @using MatrixRoomUtils.Core.StateEventTypes
+@using MatrixRoomUtils.Core.StateEventTypes.Spec
 <h3>Room list</h3>
 
 @if (Rooms is not null) {
@@ -9,14 +10,14 @@
 
 @code {
 
-    private List<GenericRoom> Rooms { get; set; }
-    private ProfileResponse GlobalProfile { get; set; }
-    
+    private List<RoomInfo> Rooms { get; set; }
+    private ProfileResponseEventData GlobalProfile { get; set; }
+
     protected override async Task OnInitializedAsync() {
         var hs = await MRUStorage.GetCurrentSessionOrNavigate();
         if (hs is null) return;
         GlobalProfile = await hs.GetProfile(hs.WhoAmI.UserId);
-        Rooms = await hs.GetJoinedRooms();
+        Rooms = (await hs.GetJoinedRooms()).Select(x => new RoomInfo() { Room = x }).ToList();
 
         await base.OnInitializedAsync();
     }
diff --git a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor b/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor
index 8e2609f..4cb16b8 100644
--- a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor
+++ b/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor
@@ -1,8 +1,9 @@
-@page "/PolicyListEditor/{RoomId}"
+@page "/Rooms/{RoomId}/Policies"
 @using MatrixRoomUtils.Core.StateEventTypes
 @using System.Text.Json
 @using MatrixRoomUtils.Core.Helpers
 @using MatrixRoomUtils.Core.Responses
+@using MatrixRoomUtils.Core.StateEventTypes.Spec
 <h3>Policy list editor - Editing @RoomId</h3>
 <hr/>