about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/HSAdmin/RoomQuery.razor
blob: 11df2616c187bb373107628e64883dd57cdebb67 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
@page "/HSAdmin/RoomQuery"
@using LibMatrix.Responses.Admin
@using LibMatrix.Filters
@using ArcaneLibs.Extensions

<h3>Homeserver Administration - Room Query</h3>

<label>Search name: </label>
<InputText @bind-Value="SearchTerm"/><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/>
<details>
    <summary>
        <span>Local filtering (slow)</span>

    </summary>
    <div style="margin-left: 8px; margin-bottom: 8px;">
        <u style="display: block;">String contains</u>
        <span class="tile tile280">Room ID: <FancyTextBox @bind-Value="@Filter.RoomIdContains"></FancyTextBox></span>
        <span class="tile tile280">Room name: <FancyTextBox @bind-Value="@Filter.NameContains"></FancyTextBox></span>
        <span class="tile tile280">Canonical alias: <FancyTextBox @bind-Value="@Filter.CanonicalAliasContains"></FancyTextBox></span>
        <span class="tile tile280">Creator: <FancyTextBox @bind-Value="@Filter.CreatorContains"></FancyTextBox></span>
        <span class="tile tile280">Room version: <FancyTextBox @bind-Value="@Filter.VersionContains"></FancyTextBox></span>
        <span class="tile tile280">Encryption algorithm: <FancyTextBox @bind-Value="@Filter.EncryptionContains"></FancyTextBox></span>
        <span class="tile tile280">Join rules: <FancyTextBox @bind-Value="@Filter.JoinRulesContains"></FancyTextBox></span>
        <span class="tile tile280">Guest access: <FancyTextBox @bind-Value="@Filter.GuestAccessContains"></FancyTextBox></span>
        <span class="tile tile280">History visibility: <FancyTextBox @bind-Value="@Filter.HistoryVisibilityContains"></FancyTextBox></span>

        <u style="display: block;">Optional checks</u>
        <span class="tile tile150">
            <InputCheckbox @bind-Value="@Filter.CheckFederation"></InputCheckbox> Is federated:
            @if (Filter.CheckFederation) {
                <InputCheckbox @bind-Value="@Filter.Federatable"></InputCheckbox>
            }
        </span>
        <span class="tile tile150">
            <InputCheckbox @bind-Value="@Filter.CheckPublic"></InputCheckbox> Is public:
            @if (Filter.CheckPublic) {
                <InputCheckbox @bind-Value="@Filter.Public"></InputCheckbox>
            }
        </span>

        <u style="display: block;">Ranges</u>
        <span class="tile center-children">
            <InputNumber max="@int.MaxValue" class="int-input" TValue="int" @bind-Value="@Filter.StateEventsGreaterThan"></InputNumber><span class="range-sep">state events</span><InputNumber max="@int.MaxValue" class="int-input" TValue="int" @bind-Value="@Filter.StateEventsLessThan"></InputNumber>
        </span>
        <span class="tile center-children">
            <InputNumber max="@int.MaxValue" class="int-input" TValue="int" @bind-Value="@Filter.JoinedMembersGreaterThan"></InputNumber><span class="range-sep">members</span><InputNumber max="@int.MaxValue" class="int-input" TValue="int" @bind-Value="@Filter.JoinedMembersLessThan"></InputNumber>
        </span>
        <span class="tile center-children">
            <InputNumber max="@int.MaxValue" class="int-input" TValue="int" @bind-Value="@Filter.JoinedLocalMembersGreaterThan"></InputNumber><span class="range-sep">local members</span><InputNumber max="@int.MaxValue" class="int-input" TValue="int" @bind-Value="@Filter.JoinedLocalMembersLessThan"></InputNumber>
        </span>
    </div>
</details>
<button class="btn btn-primary" @onclick="Search">Search</button>
<br/>

@if (Results.Count > 0) {
    <p>Found @Results.Count rooms</p>
    <details>
        <summary>TSV data (copy/paste)</summary>
        <pre style="font-size: 0.6em;">
            <table>
                @foreach (var res in Results) {
                    <tr>
                        <td style="padding: 8px;">@res.RoomId@("\t")</td>
                        <td style="padding: 8px;">@res.CanonicalAlias@("\t")</td>
                        <td style="padding: 8px;">@res.Creator@("\t")</td>
                        <td style="padding: 8px;">@res.Name</td>
                    </tr>
                }
            </table>
        </pre>
    </details>
}

@foreach (var res in Results) {
    <div style="background-color: #ffffff11; border-radius: 0.5em; display: block; margin-top: 4px; padding: 4px;">
        @* <RoomListItem RoomName="@res.Name" RoomId="@res.RoomId"></RoomListItem> *@
        <p>
            @if (!string.IsNullOrWhiteSpace(res.CanonicalAlias)) {
                <span>@res.CanonicalAlias - @res.RoomId (@res.Name)</span>
                <br/>
            }
            else {
                <span>@res.RoomId (@res.Name)</span>
                <br/>
            }
            @if (!string.IsNullOrWhiteSpace(res.Creator)) {
                @* <span>Created by <InlineUserItem UserId="@res.Creator"></InlineUserItem></span> *@
                <span>Created by @res.Creator</span>
                <br/>
            }
        </p>
        <span>@res.StateEvents state events</span><br/>
        <span>@res.JoinedMembers members, of which @res.JoinedLocalMembers are on this server</span>
        <details>
            <summary>Full result data</summary>
            <pre>@res.ToJson(ignoreNull: true)</pre>
        </details>
    </div>
}

<style>
    .int-input {
        width: 128px;
    }
    .tile {
        display: inline-block;
        padding: 4px;
        border: 1px solid #ffffff22;
    }
    .tile280 {
        min-width: 280px;
    }
    .tile150 {
        min-width: 150px;
    }
    .range-sep {
        display: inline-block;
        padding: 4px;
        width: 150px;
    }
    .range-sep::before {
        content: "@("<") ";
    }
    .range-sep::after {
        content: " @("<")";
    }
    .center-children {
        text-align: center;
    }
</style>

@code {

    [Parameter]
    [SupplyParameterFromQuery(Name = "order_by")]
    public string? OrderBy { get; set; }

    [Parameter]
    [SupplyParameterFromQuery(Name = "name_search")]
    public string SearchTerm { get; set; }

    [Parameter]
    [SupplyParameterFromQuery(Name = "ascending")]
    public bool Ascending { get; set; }

    public List<AdminRoomListingResult.AdminRoomListingResultRoom> Results { get; set; } = new();

    private string Status { get; set; }

    public LocalRoomQueryFilter Filter { get; set; } = new();

    protected override Task OnParametersSetAsync() {
        if (Ascending == null)
            Ascending = true;
        OrderBy ??= "name";
        return Task.CompletedTask;
    }

    private async Task Search() {
        Results.Clear();
        var hs = await RMUStorage.GetCurrentSessionOrNavigate();
        if (hs is AuthenticatedHomeserverSynapse synapse) {
            var searchRooms = synapse.Admin.SearchRoomsAsync(orderBy: OrderBy!, dir: Ascending ? "f" : "b", searchTerm: SearchTerm, localFilter: Filter).GetAsyncEnumerator();
            while (await searchRooms.MoveNextAsync()) {
                var room = searchRooms.Current;
                Console.WriteLine("Hit: " + room.ToJson(false));
                Results.Add(room);
                if (Results.Count % 10 == 0)
                    StateHasChanged();
            }
        }

        StateHasChanged();
    }

    private readonly Dictionary<string, string> validOrderBy = new() {
        { "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" }
    };

}