diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-06-13 01:49:10 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-06-13 01:49:10 +0200 |
commit | fc749b3e57098740377e6eabd5d010d133256fa5 (patch) | |
tree | cc97267a3d4222c910769e46bdb37c96c7c31531 /MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor | |
parent | unknown changes (diff) | |
download | MatrixUtils-fc749b3e57098740377e6eabd5d010d133256fa5.tar.xz |
Improved many features
Diffstat (limited to 'MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor')
-rw-r--r-- | MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor b/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor new file mode 100644 index 0000000..109ad7d --- /dev/null +++ b/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor @@ -0,0 +1,86 @@ +@page "/RoomQuery" +@using MatrixRoomUtils.Core.Extensions +@using System.Runtime.InteropServices +@using System.ComponentModel +@using MatrixRoomUtils.Core.Responses.Admin +<h3>Homeserver Administration - Room Query</h3> + +<label>Search name: </label> +<InputText @bind-Value="SearchTerm" /><br/> +<label>Search id/name/creator (slow!): </label> +<InputText @bind-Value="ContentSearchTerm" /><br/> +<label>Order by: </label> +<select @bind="OrderBy"> + @foreach (var item in validOrderBy) + { + <option value="@item.Key">@item.Value</option> + } +</select><br/> +<label>Ascending: </label> +<InputCheckbox @bind-Value="Ascending" /><br/> +<button class="btn btn-primary" @onclick="Search">Search</button> +<br/> + +@foreach (var res in Results) +{ + <div style="background-color: #ffffff11; border-radius: 0.5em; display: block; margin-top: 4px; padding: 4px;"> + <RoomListItem RoomId="@res.RoomId"></RoomListItem> + <p>@res.CanonicalAlias, created by <InlineUserItem UserId="@res.Creator"></InlineUserItem></p> + <p>@res.StateEvents state events</p> + <p>@res.JoinedMembers members, of which @res.JoinedLocalMembers are on this server</p> + </div> +} + +@code { + + [Parameter, SupplyParameterFromQuery(Name = "order_by")] + public string? OrderBy { get; set; } + + [Parameter, SupplyParameterFromQuery(Name = "search_term")] + public string SearchTerm { get; set; } + + [Parameter, SupplyParameterFromQuery(Name = "content_search_term")] + public string ContentSearchTerm { get; set; } + + [Parameter, SupplyParameterFromQuery(Name = "ascending")] + public bool Ascending { get; set; } + + public List<AdminRoomListingResult.AdminRoomListingResultRoom> Results { get; set; } = new(); + + protected override async Task OnParametersSetAsync() + { + if(Ascending == null) + Ascending = true; + OrderBy ??= "name"; + } + + private async Task Search() + { + Results.Clear(); + var searchRooms = RuntimeCache.CurrentHomeServer.Admin.SearchRoomsAsync(orderBy: OrderBy!, dir: Ascending ? "f" : "b", searchTerm: SearchTerm, contentSearch: ContentSearchTerm).GetAsyncEnumerator(); + while (await searchRooms.MoveNextAsync()) + { + var room = searchRooms.Current; + Console.WriteLine("Hit: " + room.ToJson(indent: false)); + Results.Add(room); + } + } + + private Dictionary<string, string> validOrderBy = new Dictionary<string, string>() + { + { "name", "Room name" }, + { "canonical_alias", "Main alias address" }, + { "joined_members", "Number of members (reversed)" }, + { "joined_local_members", "Number of local members (reversed)" }, + { "version", "Room version" }, + { "creator", "Creator of the room" }, + { "encryption", "End-to-end encryption algorithm" }, + { "federatable", "Is room federated" }, + { "public", "Visibility in room list" }, + { "join_rules", "Join rules" }, + { "guest_access", "Guest access" }, + { "history_visibility", "Visibility of history" }, + { "state_events", "Number of state events" }, + }; + +} \ No newline at end of file |