about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Pages/Tools/KnownHomeserverList.razor
blob: dbf2f5f7c8eda68cbc19cc02c89aa46c74d6c0d6 (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
@page "/KnownHomeserverList"
@using System.Diagnostics
@using ArcaneLibs.Extensions
@using LibMatrix.Homeservers
@using LibMatrix.RoomTypes
<h3>Known Homeserver List</h3>
<hr/>

@if (!IsFinished) {
    <p>
        <b>Loading...</b>
    </p>
}

@foreach (var (homeserver, members) in counts.OrderByDescending(x => x.Value)) {
    <p>@homeserver - @members</p>
}
<hr/>

@code {
    Dictionary<string, List<string>> homeservers { get; set; } = new();
    Dictionary<string, int> counts { get; set; } = new();
    // List<HomeserverInfo> Homeservers = new();
    bool IsFinished { get; set; }
    // HomeserverInfoQueryProgress QueryProgress { get; set; } = new();
    AuthenticatedHomeserverGeneric? hs { get; set; }

    protected override async Task OnInitializedAsync() {
        hs = await MRUStorage.GetCurrentSessionOrNavigate();
        if (hs is null) return;
        var fetchTasks = (await hs.GetJoinedRooms()).Select(x=>x.GetMembersByHomeserverAsync()).ToAsyncEnumerable();
        await foreach (var result in fetchTasks) {
            foreach (var (resHomeserver, resMembers) in result) {
                if (!homeservers.TryAdd(resHomeserver, resMembers)) {
                    homeservers[resHomeserver].AddRange(resMembers);
                }
                counts[resHomeserver] = homeservers[resHomeserver].Count;
            }
            // StateHasChanged();
            // await Task.Delay(250);
        }

        foreach (var resHomeserver in homeservers.Keys) {
            homeservers[resHomeserver] = homeservers[resHomeserver].Distinct().ToList();
            counts[resHomeserver] = homeservers[resHomeserver].Count;
        }

        IsFinished = true;
        StateHasChanged();
        Console.WriteLine("Rerendered!");
        await base.OnInitializedAsync();
    }

}