about summary refs log tree commit diff
path: root/MatrixUtils.Web/Shared/RoomListComponents
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixUtils.Web/Shared/RoomListComponents')
-rw-r--r--MatrixUtils.Web/Shared/RoomListComponents/RoomListCategory.razor63
-rw-r--r--MatrixUtils.Web/Shared/RoomListComponents/RoomListPolicyRoom.razor13
-rw-r--r--MatrixUtils.Web/Shared/RoomListComponents/RoomListSpace.razor60
3 files changed, 136 insertions, 0 deletions
diff --git a/MatrixUtils.Web/Shared/RoomListComponents/RoomListCategory.razor b/MatrixUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
new file mode 100644
index 0000000..3d0070f
--- /dev/null
+++ b/MatrixUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
@@ -0,0 +1,63 @@
+@using MatrixUtils.Web.Classes.Constants
+@using LibMatrix
+@using LibMatrix.EventTypes.Spec.State
+@using LibMatrix.Homeservers
+@using LibMatrix.Responses
+@using MatrixUtils.Abstractions
+<details>
+    <summary>@RoomType (@Rooms.Count)</summary>
+    @foreach (var room in Rooms) {
+        <div class="room-list-item">
+            <RoomListItem RoomInfo="@room" ShowOwnProfile="@(RoomType == "Room")"></RoomListItem>
+            @* @if (RoomVersionDangerLevel(room) != 0 && *@
+            @*      (room.StateEvents.FirstOrDefault(x=>x.Type == "m.room.power_levels")?.TypedContent is RoomPowerLevelEventContent powerLevels && powerLevels.UserHasPermission(Homeserver.UserId, "m.room.tombstone"))) { *@
+            @*     <MatrixUtils.Web.Shared.SimpleComponents.LinkButton Color="@(RoomVersionDangerLevel(room) == 2 ? "#ff0000" : "#ff8800")" href="@($"/Rooms/Create?Import={room.Room.RoomId}")">Upgrade room</MatrixUtils.Web.Shared.SimpleComponents.LinkButton> *@
+            @* } *@
+            <LinkButton href="@($"/Rooms/{room.Room.RoomId}/Timeline")">View timeline</LinkButton>
+            <LinkButton href="@($"/Rooms/{room.Room.RoomId}/State/View")">View state</LinkButton>
+            <LinkButton href="@($"/Rooms/{room.Room.RoomId}/State/Edit")">Edit state</LinkButton>
+
+            @if (room.CreationEventContent?.Type == "m.space") {
+                <RoomListSpace Space="@room"></RoomListSpace>
+            }
+            else if (room.CreationEventContent?.Type == "support.feline.policy.lists.msc.v1" || RoomType == "org.matrix.mjolnir.policy") {
+                <LinkButton href="@($"/Rooms/{room.Room.RoomId}/Policies")">Manage policies</LinkButton>
+            }
+        </div>
+    }
+</details>
+<br/>
+
+@code {
+
+    [Parameter]
+    public KeyValuePair<string, List<RoomInfo>> Category { get; set; }
+
+    [Parameter]
+    public UserProfileResponse? GlobalProfile { get; set; }
+
+    [CascadingParameter]
+    public AuthenticatedHomeserverGeneric Homeserver { get; set; } = null!;
+
+    private string RoomType => Category.Key;
+    private List<RoomInfo> Rooms => Category.Value;
+
+    private int RoomVersionDangerLevel(RoomInfo room) {
+        var creationEvent = room.StateEvents.FirstOrDefault(x => x?.Type == "m.room.create");
+        if (creationEvent is null) return 0;
+        return creationEvent.TypedContent is not RoomCreateEventContent roomVersionContent ? 0
+            : RoomConstants.DangerousRoomVersions.Contains(roomVersionContent.RoomVersion) ? 2
+                : roomVersionContent.RoomVersion != RoomConstants.RecommendedRoomVersion ? 1 : 0;
+    }
+    
+    public static string GetRoomTypeName(string roomType) {
+        return roomType switch {
+            null => "Room",
+            "m.space" => "Space",
+            "org.matrix.mjolnir.policy" => "Policy room",
+            
+            _ => roomType
+        };
+    }
+
+}
diff --git a/MatrixUtils.Web/Shared/RoomListComponents/RoomListPolicyRoom.razor b/MatrixUtils.Web/Shared/RoomListComponents/RoomListPolicyRoom.razor
new file mode 100644
index 0000000..7afdc8c
--- /dev/null
+++ b/MatrixUtils.Web/Shared/RoomListComponents/RoomListPolicyRoom.razor
@@ -0,0 +1,13 @@
+@using LibMatrix.RoomTypes
+<LinkButton href="@($"/Rooms/{Room.RoomId}/Policies")">Manage policies</LinkButton>
+
+@code {
+
+    [Parameter]
+    public GenericRoom Room { get; set; }
+
+    protected override async Task OnInitializedAsync() {
+        await base.OnInitializedAsync();
+    }
+
+}
diff --git a/MatrixUtils.Web/Shared/RoomListComponents/RoomListSpace.razor b/MatrixUtils.Web/Shared/RoomListComponents/RoomListSpace.razor
new file mode 100644
index 0000000..895d642
--- /dev/null
+++ b/MatrixUtils.Web/Shared/RoomListComponents/RoomListSpace.razor
@@ -0,0 +1,60 @@
+@using System.Collections.ObjectModel
+@using MatrixUtils.Abstractions
+<MatrixUtils.Web.Shared.SimpleComponents.LinkButton href="@($"/Rooms/{Space.Room.RoomId}/Space")">Manage space</MatrixUtils.Web.Shared.SimpleComponents.LinkButton>
+
+<br/>
+<details @ontoggle="SpaceChildrenOpened">
+    <summary>@Children.Count children</summary>
+    @if (_shouldRenderChildren) {
+        <p>Breadcrumb: @Breadcrumbs</p>
+        <div style="margin-left: 8px;">
+            <RoomList Rooms="Children"></RoomList>
+        </div>
+    }
+</details>
+
+@code {
+
+    [Parameter]
+    public RoomInfo Space { get; set; }
+
+    [Parameter, CascadingParameter]
+    public List<RoomInfo> KnownRooms { get; set; } = new();
+
+    [Parameter, CascadingParameter]
+    public string? Breadcrumbs {
+        get => _breadcrumbs + Space.Room.RoomId;
+        set => _breadcrumbs = value;
+    }
+
+    private ObservableCollection<RoomInfo> Children { get; set; } = new();
+
+    protected override async Task OnInitializedAsync() {
+        if (Breadcrumbs == null) throw new ArgumentNullException(nameof(Breadcrumbs));
+        await Task.Delay(Random.Shared.Next(1000, 10000));
+        var rooms = Space.Room.AsSpace.GetChildrenAsync();
+        await foreach (var room in rooms) {
+            if (Breadcrumbs.Contains(room.RoomId)) continue;
+            var roomInfo = KnownRooms.FirstOrDefault(x => x.Room.RoomId == room.RoomId);
+            if (roomInfo is null) {
+                roomInfo = new RoomInfo() {
+                    Room = room
+                };
+                KnownRooms.Add(roomInfo);
+            }
+            Children.Add(roomInfo);
+        }
+        await base.OnInitializedAsync();
+    }
+
+    private bool _shouldRenderChildren = false;
+    private string? _breadcrumbs;
+
+    private Task SpaceChildrenOpened() {
+        if (_shouldRenderChildren) return Task.CompletedTask;
+        _shouldRenderChildren = true;
+        Console.WriteLine($"[RoomList] Rendering children of {Space.Room.RoomId}");
+        return Task.CompletedTask;
+    }
+
+}