From b48f78a381058c188ed61e6f372fbf86d95ad2f9 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Wed, 14 Jun 2023 22:26:39 +0200 Subject: Add changes --- MatrixRoomUtils.Core/Room.cs | 13 +++++ MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs | 23 +++++++++ MatrixRoomUtils.Web/FileUploadTest.razor | 2 +- MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj | 10 ++-- MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor | 25 ++++++---- .../Pages/RoomManager/RoomManagerTimeline.razor | 2 +- MatrixRoomUtils.Web/Pages/Rooms/Index.razor | 22 +++++++++ MatrixRoomUtils.Web/Shared/RoomList.razor | 56 ++++++++++++++++++++++ MatrixRoomUtils.Web/Shared/RoomList.razor.css | 8 ++++ .../RoomListComponents/RoomListCategory.razor | 24 ++++++++++ .../Shared/RoomListComponents/RoomListSpace.razor | 42 ++++++++++++++++ MatrixRoomUtils.Web/Shared/RoomListItem.razor | 6 +-- .../Shared/SimpleComponents/FancyTextBox.razor | 2 +- .../Shared/SimpleComponents/FancyTextBox.razor.css | 5 ++ .../Shared/SimpleComponents/LinkButton.razor | 13 +++++ MatrixRoomUtils.Web/_Imports.razor | 7 ++- MatrixRoomUtils.sln.DotSettings | 1 + 17 files changed, 240 insertions(+), 21 deletions(-) create mode 100644 MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs create mode 100644 MatrixRoomUtils.Web/Pages/Rooms/Index.razor create mode 100644 MatrixRoomUtils.Web/Shared/RoomList.razor create mode 100644 MatrixRoomUtils.Web/Shared/RoomList.razor.css create mode 100644 MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor create mode 100644 MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor create mode 100644 MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor.css create mode 100644 MatrixRoomUtils.Web/Shared/SimpleComponents/LinkButton.razor diff --git a/MatrixRoomUtils.Core/Room.cs b/MatrixRoomUtils.Core/Room.cs index a867c0c..2d6dc46 100644 --- a/MatrixRoomUtils.Core/Room.cs +++ b/MatrixRoomUtils.Core/Room.cs @@ -3,6 +3,7 @@ using System.Text.Json; using System.Text.Json.Serialization; using System.Web; using MatrixRoomUtils.Core.Extensions; +using MatrixRoomUtils.Core.RoomTypes; namespace MatrixRoomUtils.Core; @@ -12,6 +13,8 @@ public class Room { public Room(HttpClient httpClient, string roomId) { _httpClient = httpClient; RoomId = roomId; + if(GetType() != typeof(SpaceRoom)) + AsSpace = new SpaceRoom(_httpClient, RoomId); } public string RoomId { get; set; } @@ -137,6 +140,16 @@ public class Room { return res.Value.Deserialize() ?? new CreateEvent(); } + + public async Task GetRoomType() { + var res = await GetStateAsync("m.room.create"); + if (!res.HasValue) return null; + if (res.Value.TryGetProperty("type", out var type)) return type.GetString(); + return null; + } + + + public SpaceRoom AsSpace; } public class MessagesResponse { diff --git a/MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs b/MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs new file mode 100644 index 0000000..e8d4823 --- /dev/null +++ b/MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs @@ -0,0 +1,23 @@ +using System.Text.Json; +using MatrixRoomUtils.Core.Extensions; + +namespace MatrixRoomUtils.Core.RoomTypes; + +public class SpaceRoom : Room { + public SpaceRoom(HttpClient httpClient, string roomId) : base(httpClient, roomId) { } + + public async Task> GetRoomsAsync(bool includeRemoved = false) { + var rooms = new List(); + var state = await GetStateAsync(""); + if (state != null) { + var states = state.Value.Deserialize[]>()!; + foreach (var stateEvent in states.Where(x => x.Type == "m.space.child")) { + var roomId = stateEvent.StateKey; + if(stateEvent.Content.ToJson() != "{}" || includeRemoved) + rooms.Add(await RuntimeCache.CurrentHomeServer.GetRoom(roomId)); + } + } + + return rooms; + } +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/FileUploadTest.razor b/MatrixRoomUtils.Web/FileUploadTest.razor index 478a3e4..cbdb5ce 100644 --- a/MatrixRoomUtils.Web/FileUploadTest.razor +++ b/MatrixRoomUtils.Web/FileUploadTest.razor @@ -6,7 +6,7 @@ @code { - private async void FilePicked(InputFileChangeEventArgs obj) { + private async Task FilePicked(InputFileChangeEventArgs obj) { Console.WriteLine("FilePicked"); Console.WriteLine(obj.File.Name); Console.WriteLine(obj.File.Size); diff --git a/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj b/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj index c76452f..e1511c4 100644 --- a/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj +++ b/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj @@ -7,17 +7,17 @@ - - - + + + - + - + diff --git a/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor b/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor index e6f95c7..a62362b 100644 --- a/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor +++ b/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor @@ -18,19 +18,26 @@
+@if (Results.Count > 0) { +

Found @Results.Count rooms

+} + @foreach (var res in Results) {

- @res.CanonicalAlias + @if (!string.IsNullOrWhiteSpace(res.CanonicalAlias)) { + @res.CanonicalAlias (@res.RoomId)
+ } + else { + @res.RoomId
+ } @if (!string.IsNullOrWhiteSpace(res.Creator)) { - - , created by - + Created by
}

-

@res.StateEvents state events

-

@res.JoinedMembers members, of which @res.JoinedLocalMembers are on this server

+ @res.StateEvents state events
+ @res.JoinedMembers members, of which @res.JoinedLocalMembers are on this server
} @@ -41,11 +48,11 @@ public string? OrderBy { get; set; } [Parameter] - [SupplyParameterFromQuery(Name = "search_term")] + [SupplyParameterFromQuery(Name = "name_search")] public string SearchTerm { get; set; } [Parameter] - [SupplyParameterFromQuery(Name = "content_search_term")] + [SupplyParameterFromQuery(Name = "content_search")] public string ContentSearchTerm { get; set; } [Parameter] @@ -69,6 +76,8 @@ var room = searchRooms.Current; Console.WriteLine("Hit: " + room.ToJson(false)); Results.Add(room); + if (Results.Count % 10 == 0) + StateHasChanged(); } } diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor index 2db7cab..b90cc09 100644 --- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor +++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor @@ -1,4 +1,4 @@ -@page "/RoomManager/Timeline/{RoomId}" +@page "/Rooms/{RoomId}/Timeline" @using MatrixRoomUtils.Web.Shared.TimelineComponents

RoomManagerTimeline


diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor new file mode 100644 index 0000000..17551c9 --- /dev/null +++ b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor @@ -0,0 +1,22 @@ +@page "/Rooms" +

Room list

+ +@if (Rooms != null) { + +} + + +@code { + + private List Rooms { get; set; } + + protected override async Task OnInitializedAsync() + { + await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); + + Rooms = await RuntimeCache.CurrentHomeServer.GetJoinedRooms(); + + await base.OnInitializedAsync(); + } + +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/RoomList.razor b/MatrixRoomUtils.Web/Shared/RoomList.razor new file mode 100644 index 0000000..ca93fa6 --- /dev/null +++ b/MatrixRoomUtils.Web/Shared/RoomList.razor @@ -0,0 +1,56 @@ +@using MatrixRoomUtils.Web.Shared.RoomListComponents; +

@Rooms.Count rooms total, @RoomsWithTypes.Sum(x=>x.Value.Count) fetched so far...

+@foreach (var category in RoomsWithTypes.OrderBy(x => x.Value.Count)) { + +} + +@code { + + [Parameter] + public List Rooms { get; set; } + + Dictionary> RoomsWithTypes = new(); + + protected override async Task OnInitializedAsync() { + if (RoomsWithTypes.Any()) return; + + await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); + + var tasks = Rooms.Select(AddRoom); + await Task.WhenAll(tasks); + + await base.OnInitializedAsync(); + } + + private string GetRoomTypeName(string? roomType) => roomType switch { + "m.space" => "Space", + "msc3588.stories.stories-room" => "Story room", + null => "Room", + _ => roomType + }; + + + private static SemaphoreSlim _semaphoreSlim = new SemaphoreSlim(8, 8); + private async Task AddRoom(Room room) { + await _semaphoreSlim.WaitAsync(); + var roomType = GetRoomTypeName(await room.GetRoomType()); + + if (roomType == "Room") { + var shortcodeState = await room.GetStateAsync("org.matrix.mjolnir.shortcode"); + if (shortcodeState.HasValue) roomType = "Legacy policy room"; + } + + if (!RoomsWithTypes.ContainsKey(roomType)) { + RoomsWithTypes.Add(roomType, new List()); + } + RoomsWithTypes[roomType].Add(room); + + // if (RoomsWithTypes.Count % 10 == 0) + StateHasChanged(); + await Task.Delay(100); + _semaphoreSlim.Release(); + } + + private bool _isSpaceChildrenOpen = false; + +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/RoomList.razor.css b/MatrixRoomUtils.Web/Shared/RoomList.razor.css new file mode 100644 index 0000000..a159305 --- /dev/null +++ b/MatrixRoomUtils.Web/Shared/RoomList.razor.css @@ -0,0 +1,8 @@ +.room-list-item { + background-color: #ffffff11; + border-radius: 0.5em; + display: block; + margin-top: 4px; + padding: 4px; + width: fit-content; +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor new file mode 100644 index 0000000..ecdcc68 --- /dev/null +++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor @@ -0,0 +1,24 @@ +
+ @roomType (@rooms.Count) + @foreach (var room in rooms) { +
+ + View timeline + + @if (roomType == "Space") { + + } +
+ } +
+
+ +@code { + + [Parameter] + public KeyValuePair> Category { get; set; } + + private string roomType => Category.Key; + private List rooms => Category.Value; + +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor new file mode 100644 index 0000000..c90ae8f --- /dev/null +++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor @@ -0,0 +1,42 @@ +Manage space + +
+
+ @Children.Count children + @if (_shouldRenderChildren) { +

Breadcrumb: @Breadcrumbs

+
+ +
+ } +
+ +@code { + + [Parameter] + public Room Space { get; set; } + + [Parameter, CascadingParameter] + public string? Breadcrumbs { + get => _breadcrumbs + Space.RoomId; + set => _breadcrumbs = value; + } + + private List Children { get; set; } = new(); + + protected override async Task OnInitializedAsync() { + if (Breadcrumbs == null) throw new ArgumentNullException(nameof(Breadcrumbs)); + Children = (await Space.AsSpace.GetRoomsAsync()).Where(x => !Breadcrumbs.Contains(x.RoomId)).ToList(); + await base.OnInitializedAsync(); + } + + private bool _shouldRenderChildren = false; + private string? _breadcrumbs; + + private async Task SpaceChildrenOpened() { + if (_shouldRenderChildren) return; + _shouldRenderChildren = true; + Console.WriteLine($"[RoomList] Rendering children of {Space.RoomId}"); + } + +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor index f58ab3a..6dc0683 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor @@ -2,7 +2,7 @@ @using System.Text.Json
@if (ShowOwnProfile) { - + @(profileName ?? "Loading...") -> } @@ -51,7 +51,7 @@ await _semaphoreSlim.WaitAsync(); - var hs = RuntimeCache.CurrentHomeServer; //await new AuthenticatedHomeServer(RuntimeCache.CurrentHomeServer.UserId, RuntimeCache.CurrentHomeServer.AccessToken, RuntimeCache.CurrentHomeServer.HomeServerDomain).Configure(); + var hs = RuntimeCache.CurrentHomeServer; if (Room == null) { if (RoomId == null) { @@ -119,6 +119,4 @@ await LocalStorageWrapper.SaveCacheToLocalStorage(LocalStorage); } - private void Callback(ProgressEventArgs obj) => Console.WriteLine("prog: " + obj.ToJson(false)); - } \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor b/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor index d17d0de..966c44d 100644 --- a/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor +++ b/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor @@ -3,7 +3,7 @@ } else { - @(Formatter?.Invoke(Value) ?? (IsPassword ? string.Join("", Value.Select(x => '*')) : Value)) + @(Formatter?.Invoke(Value) ?? (IsPassword ? string.Join("", Value.Select(x => '*')) : Value)) } @code { diff --git a/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor.css b/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor.css new file mode 100644 index 0000000..01b2c6f --- /dev/null +++ b/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor.css @@ -0,0 +1,5 @@ +.fancy-textbox-inline { + border-bottom: #ccc solid 1px; + height: 1.4em; + display: inline-block; +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/SimpleComponents/LinkButton.razor b/MatrixRoomUtils.Web/Shared/SimpleComponents/LinkButton.razor new file mode 100644 index 0000000..8c9e73b --- /dev/null +++ b/MatrixRoomUtils.Web/Shared/SimpleComponents/LinkButton.razor @@ -0,0 +1,13 @@ + + @ChildContent + + +@code { + + [Parameter] + public string href { get; set; } + + [Parameter] + public RenderFragment ChildContent { get; set; } + +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/_Imports.razor b/MatrixRoomUtils.Web/_Imports.razor index 837780e..155837b 100644 --- a/MatrixRoomUtils.Web/_Imports.razor +++ b/MatrixRoomUtils.Web/_Imports.razor @@ -11,13 +11,18 @@ @using MatrixRoomUtils.Web @using MatrixRoomUtils.Web.Classes @using MatrixRoomUtils.Web.Shared +@using MatrixRoomUtils.Core.RoomTypes +@using MatrixRoomUtils.Core.Extensions + +@using LinkButton = MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton + + @inject ILocalStorageService LocalStorage @inject NavigationManager NavigationManager @code { - protected override async Task OnInitializedAsync() { if (!RuntimeCache.WasLoaded) { await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); diff --git a/MatrixRoomUtils.sln.DotSettings b/MatrixRoomUtils.sln.DotSettings index 4ac5b79..3da5982 100644 --- a/MatrixRoomUtils.sln.DotSettings +++ b/MatrixRoomUtils.sln.DotSettings @@ -1,2 +1,3 @@  + ERROR \ No newline at end of file -- cgit 1.5.1