about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/Labs/Client
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixUtils.Web/Pages/Labs/Client')
-rw-r--r--MatrixUtils.Web/Pages/Labs/Client/ClientComponents/ClientRoomList.razor15
-rw-r--r--MatrixUtils.Web/Pages/Labs/Client/ClientComponents/ClientStatusList.razor35
-rw-r--r--MatrixUtils.Web/Pages/Labs/Client/ClientComponents/ClientSyncWrapper.cs41
-rw-r--r--MatrixUtils.Web/Pages/Labs/Client/ClientComponents/MatrixClient.razor31
-rw-r--r--MatrixUtils.Web/Pages/Labs/Client/Index.razor72
5 files changed, 194 insertions, 0 deletions
diff --git a/MatrixUtils.Web/Pages/Labs/Client/ClientComponents/ClientRoomList.razor b/MatrixUtils.Web/Pages/Labs/Client/ClientComponents/ClientRoomList.razor
new file mode 100644

index 0000000..b370080 --- /dev/null +++ b/MatrixUtils.Web/Pages/Labs/Client/ClientComponents/ClientRoomList.razor
@@ -0,0 +1,15 @@ +@using ClientContext = MatrixUtils.Web.Pages.Labs.Client.Index.ClientContext +@* user header and room list *@ +@foreach (var room in Data.SyncWrapper.Rooms) { + <LinkButton OnClick="@(async () => Data.SelectedRoom = room)" Color="@(Data.SelectedRoom == room ? "#FF00FF" : "")"> + @room.RoomName + </LinkButton> + <br/> +} + +@code { + + [Parameter] + public ClientContext Data { get; set; } = null!; + +} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Labs/Client/ClientComponents/ClientStatusList.razor b/MatrixUtils.Web/Pages/Labs/Client/ClientComponents/ClientStatusList.razor new file mode 100644
index 0000000..c680c13 --- /dev/null +++ b/MatrixUtils.Web/Pages/Labs/Client/ClientComponents/ClientStatusList.razor
@@ -0,0 +1,35 @@ +@using ClientContext = MatrixUtils.Web.Pages.Labs.Client.Index.ClientContext; +@using System.Collections.ObjectModel + +@foreach (var ctx in Data) { + <pre> + @ctx.Homeserver.UserId - @ctx.SyncWrapper.Status + </pre> +} + +@code { + + [Parameter] + public ObservableCollection<ClientContext> Data { get; set; } = null!; + + protected override void OnInitialized() { + Data.CollectionChanged += (_, e) => { + foreach (var item in e.NewItems?.Cast<ClientContext>() ?? []) { + item.SyncWrapper.PropertyChanged += (_, pe) => { + if (pe.PropertyName == nameof(item.SyncWrapper.Status)) + StateHasChanged(); + }; + } + + StateHasChanged(); + }; + + Data.ToList().ForEach(ctx => { + ctx.SyncWrapper.PropertyChanged += (_, pe) => { + if (pe.PropertyName == nameof(ctx.SyncWrapper.Status)) + StateHasChanged(); + }; + }); + } + +} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Labs/Client/ClientComponents/ClientSyncWrapper.cs b/MatrixUtils.Web/Pages/Labs/Client/ClientComponents/ClientSyncWrapper.cs new file mode 100644
index 0000000..16051b8 --- /dev/null +++ b/MatrixUtils.Web/Pages/Labs/Client/ClientComponents/ClientSyncWrapper.cs
@@ -0,0 +1,41 @@ +using System.Collections.ObjectModel; +using ArcaneLibs; +using LibMatrix; +using LibMatrix.Helpers; +using LibMatrix.Homeservers; +using LibMatrix.Responses; +using MatrixUtils.Abstractions; + +namespace MatrixUtils.Web.Pages.Client.ClientComponents; + +public class ClientSyncWrapper(AuthenticatedHomeserverGeneric homeserver) : NotifyPropertyChanged { + private SyncHelper _syncHelper = new SyncHelper(homeserver) { + MinimumDelay = TimeSpan.FromMilliseconds(2000), + IsInitialSync = false + }; + private string _status = "Loading..."; + + public ObservableCollection<StateEvent> AccountData { get; set; } = new(); + public ObservableCollection<RoomInfo> Rooms { get; set; } = new(); + + public string Status { + get => _status; + set => SetField(ref _status, value); + } + + public async Task Start() { + Task.Yield(); + var resp = _syncHelper.EnumerateSyncAsync(); + Status = $"[{DateTime.Now:s}] Syncing..."; + await foreach (var response in resp) { + Task.Yield(); + Status = $"[{DateTime.Now:s}] {response.Rooms?.Join?.Count ?? 0 + response.Rooms?.Invite?.Count ?? 0 + response.Rooms?.Leave?.Count ?? 0} rooms, {response.AccountData?.Events?.Count ?? 0} account data, {response.ToDevice?.Events?.Count ?? 0} to-device, {response.DeviceLists?.Changed?.Count ?? 0} device lists, {response.Presence?.Events?.Count ?? 0} presence updates"; + await HandleSyncResponse(response); + await Task.Yield(); + } + } + + private async Task HandleSyncResponse(SyncResponse resp) { + + } +} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Labs/Client/ClientComponents/MatrixClient.razor b/MatrixUtils.Web/Pages/Labs/Client/ClientComponents/MatrixClient.razor new file mode 100644
index 0000000..7d3e52a --- /dev/null +++ b/MatrixUtils.Web/Pages/Labs/Client/ClientComponents/MatrixClient.razor
@@ -0,0 +1,31 @@ +@using Index = MatrixUtils.Web.Pages.Labs.Client.Index +@using MatrixUtils.Web.Pages.Client.ClientComponents + +<div class="container-fluid"> + <div class="row"> + <div class="col-3"> + <ClientRoomList Data="@Data"/> + </div> + <div class="col-6"> + @if (Data.SelectedRoom != null) { + <Index.RoomHeader Data="@Data"/> + <Index.RoomTimeline Data="@Data"/> + } + else { + <p>No room selected</p> + } + </div> + @if (Data.SelectedRoom != null) { + <div class="col-3"> + <Index.UserList Data="@Data"/> + </div> + } + </div> +</div> + +@code { + + [Parameter] + public Index.ClientContext Data { get; set; } = null!; + +} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Labs/Client/Index.razor b/MatrixUtils.Web/Pages/Labs/Client/Index.razor new file mode 100644
index 0000000..5b489b0 --- /dev/null +++ b/MatrixUtils.Web/Pages/Labs/Client/Index.razor
@@ -0,0 +1,72 @@ +@page "/Labs/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; } + } + +} +