From 03313562d21d5db9bf6a14ebbeab80e06c883d3a Mon Sep 17 00:00:00 2001 From: Rory& Date: Wed, 24 Jan 2024 02:31:56 +0100 Subject: MRU->RMU, fixes, cleanup --- .../RoomListComponents/RoomListCategory.razor | 63 ++++++++++++++++++++++ .../RoomListComponents/RoomListPolicyRoom.razor | 13 +++++ .../Shared/RoomListComponents/RoomListSpace.razor | 60 +++++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 MatrixUtils.Web/Shared/RoomListComponents/RoomListCategory.razor create mode 100644 MatrixUtils.Web/Shared/RoomListComponents/RoomListPolicyRoom.razor create mode 100644 MatrixUtils.Web/Shared/RoomListComponents/RoomListSpace.razor (limited to 'MatrixUtils.Web/Shared/RoomListComponents') 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 +
+ @RoomType (@Rooms.Count) + @foreach (var room in Rooms) { +
+ + @* @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"))) { *@ + @* Upgrade room *@ + @* } *@ + View timeline + View state + Edit state + + @if (room.CreationEventContent?.Type == "m.space") { + + } + else if (room.CreationEventContent?.Type == "support.feline.policy.lists.msc.v1" || RoomType == "org.matrix.mjolnir.policy") { + Manage policies + } +
+ } +
+
+ +@code { + + [Parameter] + public KeyValuePair> Category { get; set; } + + [Parameter] + public UserProfileResponse? GlobalProfile { get; set; } + + [CascadingParameter] + public AuthenticatedHomeserverGeneric Homeserver { get; set; } = null!; + + private string RoomType => Category.Key; + private List 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 +Manage policies + +@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 +Manage space + +
+
+ @Children.Count children + @if (_shouldRenderChildren) { +

Breadcrumb: @Breadcrumbs

+
+ +
+ } +
+ +@code { + + [Parameter] + public RoomInfo Space { get; set; } + + [Parameter, CascadingParameter] + public List KnownRooms { get; set; } = new(); + + [Parameter, CascadingParameter] + public string? Breadcrumbs { + get => _breadcrumbs + Space.Room.RoomId; + set => _breadcrumbs = value; + } + + private ObservableCollection 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; + } + +} -- cgit 1.5.1