about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Shared
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-01-08 13:55:15 +0100
committerRory& <root@rory.gay>2024-01-08 13:56:32 +0100
commitede3857084bc7c6e65b7d36cbf913b09596e2787 (patch)
treeb94694c307fb831ea5e63fabde0dbb5f56f02941 /MatrixRoomUtils.Web/Shared
parentSmall changes (diff)
downloadMatrixUtils-ede3857084bc7c6e65b7d36cbf913b09596e2787.tar.xz
Internal changes to policy list viewer (extensibility), fix duplicating change handler for room list page (performance), use /state in room list page before sync
Diffstat (limited to 'MatrixRoomUtils.Web/Shared')
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomList.razor29
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor13
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor1
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomListItem.razor13
4 files changed, 35 insertions, 21 deletions
diff --git a/MatrixRoomUtils.Web/Shared/RoomList.razor b/MatrixRoomUtils.Web/Shared/RoomList.razor

index f78c7f7..31f0430 100644 --- a/MatrixRoomUtils.Web/Shared/RoomList.razor +++ b/MatrixRoomUtils.Web/Shared/RoomList.razor
@@ -5,6 +5,7 @@ @using LibMatrix.EventTypes.Spec.State @using System.Collections.ObjectModel @using LibMatrix.Responses +@using MatrixRoomUtils.Abstractions @using _Imports = MatrixRoomUtils.Web._Imports @if (!StillFetching) { <p>Fetching room details... @RoomsWithTypes.Sum(x => x.Value.Count) out of @Rooms.Count done!</p> @@ -34,18 +35,23 @@ else { private Dictionary<string, List<RoomInfo>> RoomsWithTypes => Rooms is null ? new() : Rooms.GroupBy(x => GetRoomTypeName(x.CreationEventContent?.Type)).ToDictionary(x => x.Key, x => x.ToList()); + private bool hooked; protected override async Task OnParametersSetAsync() { var hs = await MRUStorage.GetCurrentSessionOrNavigate(); if (hs is null) return; - Rooms.CollectionChanged += (_, args) => { - foreach (RoomInfo item in args.NewItems) { - item.PropertyChanged += (_, args2) => { - Console.WriteLine(args2); - if(args2.PropertyName == nameof(item.CreationEventContent)) - StateHasChanged(); - }; - } - }; + if (!hooked) { + Rooms.CollectionChanged += (_, args) => { + foreach (RoomInfo item in args.NewItems) { + item.PropertyChanged += (_, args2) => { + // Console.WriteLine(args2); + + if (args2.PropertyName == nameof(item.CreationEventContent)) + StateHasChanged(); + }; + } + }; + hooked = true; + } // GlobalProfile ??= await hs.GetProfileAsync(hs.WhoAmI.UserId); @@ -53,10 +59,10 @@ else { } private string GetRoomTypeName(string? roomType) => roomType switch { + null => "Room", "m.space" => "Space", "msc3588.stories.stories-room" => "Story room", "support.feline.policy.lists.msc.v1" => "MSC3784 Policy list (v1)", - null => "Room", _ => roomType }; @@ -88,5 +94,4 @@ else { // _semaphoreSlim.Release(); // } -} - +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
index 55ffc1e..4db25e1 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
@@ -3,6 +3,7 @@ @using LibMatrix.EventTypes.Spec.State @using LibMatrix.Homeservers @using LibMatrix.Responses +@using MatrixRoomUtils.Abstractions <details> <summary>@RoomType (@Rooms.Count)</summary> @foreach (var room in Rooms) { @@ -42,17 +43,19 @@ private List<RoomInfo> Rooms => Category.Value; private int RoomVersionDangerLevel(RoomInfo room) { - var roomVersion = room.StateEvents.FirstOrDefault(x => x.Type == "m.room.create"); - if (roomVersion is null) return 0; - return roomVersion.TypedContent is not RoomCreateEventContent roomVersionContent ? 0 + 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 { - "Room" => "Rooms", - "org.matrix.mjolnir.policy" => "Policies", + null => "Room", + "m.space" => "Space", + "org.matrix.mjolnir.policy" => "Policy room", + _ => roomType }; } diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor
index e08f98d..a6c006b 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor
@@ -1,4 +1,5 @@ @using System.Collections.ObjectModel +@using MatrixRoomUtils.Abstractions <MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton href="@($"/Rooms/{Space.Room.RoomId}/Space")">Manage space</MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton> <br/> diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
index 3aa28e6..07f0756 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
@@ -5,6 +5,7 @@ @using LibMatrix.Homeservers @using LibMatrix.Responses @using LibMatrix.RoomTypes +@using MatrixRoomUtils.Abstractions @using MatrixRoomUtils.Web.Classes.Constants @if (RoomInfo is not null) { <div class="roomListItem @(HasDangerousRoomVersion ? "dangerousRoomVersion" : HasOldRoomVersion ? "oldRoomVersion" : "")" id="@RoomInfo.Room.RoomId"> @@ -70,12 +71,16 @@ else { private bool _loadData = false; private static AuthenticatedHomeserverGeneric? hs { get; set; } + private bool _hooked; protected override async Task OnParametersSetAsync() { if (RoomInfo != null) { - RoomInfo.PropertyChanged += (_, a) => { - Console.WriteLine(a.PropertyName); - StateHasChanged(); - }; + if (!_hooked) { + _hooked = true; + RoomInfo.PropertyChanged += (_, a) => { + Console.WriteLine(a.PropertyName); + StateHasChanged(); + }; + } if (LoadData) { try {