about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/Client/Index.razor
blob: 2a9a327caec6623fad358f083915050a3ba5cc99 (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
@page "/Client"
@using LibMatrix
@using MatrixUtils.Abstractions
@using MatrixUtils.Web.Pages.Client.ClientComponents
@using System.Collections.ObjectModel

<h3>Client</h3>


@foreach (var client in Clients) {
    <LinkButton Color="@(SelectedClient == client ? "#ff00ff" : "")" OnClick="@(async () => SelectedClient = client)">
        @client.Homeserver.WhoAmI.UserId
    </LinkButton>
}
<ClientStatusList Data="@Clients"></ClientStatusList>


@* @foreach (var client in Clients) { *@
@*     <div class="card"> *@
@*         <span>@client.Homeserver.UserId - @client.SyncWrapper.Status</span> *@
@*     </div> *@
@* } *@

@if (SelectedClient != null) {
    <div class="card">
        <MatrixClient Data="@SelectedClient"/>
    </div>
}

@code {

    private static readonly ObservableCollection<ClientContext> Clients = [];
    private static ClientContext _selectedClient;

    private ClientContext SelectedClient {
        get => _selectedClient;
        set {
            _selectedClient = value;
            StateHasChanged();
        }
    }

    protected override async Task OnInitializedAsync() {
        var tokens = await RMUStorage.GetAllTokens();
        var tasks = tokens.Select(async token => {
            try {
                var cc = new ClientContext() {
                    Homeserver = await RMUStorage.GetSession(token)
                };
                cc.SyncWrapper = new ClientSyncWrapper(cc.Homeserver);

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                cc.SyncWrapper.Start();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

                Clients.Add(cc);
                StateHasChanged();
            }
            catch { }
        }).ToList();
        await Task.WhenAll(tasks);
    }

    public class ClientContext {
        public AuthenticatedHomeserverGeneric Homeserver { get; set; }
        public ClientSyncWrapper SyncWrapper { get; set; }

        public RoomInfo? SelectedRoom { get; set; }
    }

}