about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor
blob: 109ad7d8a2a5ecfd5f500a43e80f5b0ebec2c0f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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" },
    };

}