about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/Index.razor
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-02-23 13:57:06 +0100
committerRory& <root@rory.gay>2024-02-23 13:57:06 +0100
commitd0d11db2209a8be65c27e15ca9d8a3b594f1a352 (patch)
treeb42b7de4b09888a1439d0939707ba1331becf626 /MatrixUtils.Web/Pages/Index.razor
parentHS emulator (diff)
downloadMatrixUtils-d0d11db2209a8be65c27e15ca9d8a3b594f1a352.tar.xz
Add eons of work because I forgot to push
Diffstat (limited to 'MatrixUtils.Web/Pages/Index.razor')
-rw-r--r--MatrixUtils.Web/Pages/Index.razor58
1 files changed, 14 insertions, 44 deletions
diff --git a/MatrixUtils.Web/Pages/Index.razor b/MatrixUtils.Web/Pages/Index.razor
index 0c0c87a..f216488 100644
--- a/MatrixUtils.Web/Pages/Index.razor
+++ b/MatrixUtils.Web/Pages/Index.razor
@@ -3,6 +3,8 @@
 @using LibMatrix.Responses
 @using LibMatrix
 @using ArcaneLibs.Extensions
+@using ArcaneLibs
+@using System.Diagnostics
 
 <PageTitle>Index</PageTitle>
 
@@ -12,7 +14,10 @@ Small collection of tools to do not-so-everyday things.
 <br/><br/>
 <h5>@totalSessions signed in sessions - <a href="/Login">Add new account</a></h5>
 @if (scannedSessions != totalSessions) {
-    <progress max="@totalSessions" value="@scannedSessions"></progress>
+    <span>
+        <span>@scannedSessions/@totalSessions</span>
+        <progress max="@totalSessions" value="@scannedSessions"></progress>
+    </span>
 }
 <hr/>
 <form>
@@ -103,6 +108,7 @@ Small collection of tools to do not-so-everyday things.
     private readonly List<UserAuth> _offlineSessions = [];
     private LoginResponse? _currentSession;
     int scannedSessions = 0, totalSessions = 1;
+    private SvgIdenticonGenerator _identiconGenerator = new();
 
     protected override async Task OnInitializedAsync() {
         Console.WriteLine("Index.OnInitializedAsync");
@@ -124,6 +130,7 @@ Small collection of tools to do not-so-everyday things.
 
         List<string> offlineServers = [];
         var sema = new SemaphoreSlim(64, 64);
+        var updateSw = Stopwatch.StartNew();
         var tasks = tokens.Select(async token => {
             await sema.WaitAsync();
             scannedSessions++;
@@ -141,7 +148,7 @@ Small collection of tools to do not-so-everyday things.
                 var serverVersionTask = hs.FederationClient?.GetServerVersionAsync();
                 _sessions.Add(new() {
                     UserInfo = new() {
-                        AvatarUrl = "/blobfox_outage.gif",
+                        AvatarUrl = string.IsNullOrWhiteSpace((await profileTask).AvatarUrl) ? _identiconGenerator.GenerateAsDataUri(hs.WhoAmI.UserId) : hs.ResolveMediaUri((await profileTask).AvatarUrl),
                         RoomCount = (await joinedRoomsTask).Count,
                         DisplayName = (await profileTask).DisplayName ?? hs.WhoAmI.UserId
                     },
@@ -149,6 +156,10 @@ Small collection of tools to do not-so-everyday things.
                     ServerVersion = await (serverVersionTask ?? Task.FromResult<ServerVersionResponse?>(null)!),
                     Homeserver = hs
                 });
+                if (updateSw.ElapsedMilliseconds > 250) {
+                    updateSw.Restart();
+                    StateHasChanged();
+                }
             }
             catch (MatrixException e) {
                 if (e is { ErrorCode: "M_UNKNOWN_TOKEN" }) _offlineSessions.Add(token);
@@ -166,50 +177,9 @@ Small collection of tools to do not-so-everyday things.
             }
 
             sema.Release();
-
-            StateHasChanged();
         }).ToList();
         await Task.WhenAll(tasks);
-
-        // var profileTasks = tokens.Select(async token => {
-        //     UserInfo userInfo = new();
-        //     AuthenticatedHomeserverGeneric hs;
-        //     Console.WriteLine($"Getting hs for {token.ToJson()}");
-        //     try {
-        //         hs = await hsProvider.GetAuthenticatedWithToken(token.Homeserver, token.AccessToken, token.Proxy);
-        //     }
-        //     catch (MatrixException e) {
-        //         if (e.ErrorCode != "M_UNKNOWN_TOKEN") throw;
-        //         _offlineSessions.Add(token);
-        //         return;
-        //         NavigationManager.NavigateTo("/InvalidSession?ctx=" + token.AccessToken);
-        //     }
-        //     catch (Exception e) {
-        //         logger.LogError(e, $"Failed to instantiate AuthenticatedHomeserver for {token.ToJson()}, homeserver may be offline?", token.UserId);
-        //         _offlineSessions.Add(token);
-        //         return;
-        //     }
-        //
-        //     Console.WriteLine($"Got hs for {token.ToJson()}");
-        //
-        //     var roomCountTask = hs.GetJoinedRooms();
-        //     var profile = await hs.GetProfileAsync(hs.WhoAmI.UserId);
-        //     userInfo.DisplayName = profile.DisplayName ?? hs.WhoAmI.UserId;
-        //     Console.WriteLine(profile.ToJson());
-        //     _sessions.Add(new() {
-        //         UserInfo = new() {
-        //             AvatarUrl = string.IsNullOrWhiteSpace(profile.AvatarUrl) ? "/blobfox_outage.gif" : hs.ResolveMediaUri(profile.AvatarUrl),
-        //             RoomCount = (await roomCountTask).Count,
-        //             DisplayName = profile.DisplayName ?? hs.WhoAmI.UserId
-        //         },
-        //         UserAuth = token,
-        //         ServerVersion = await (hs.FederationClient?.GetServerVersionAsync() ?? Task.FromResult<ServerVersionResponse?>(null)),
-        //         Homeserver = hs
-        //     });
-        // }).ToList();
-        // Console.WriteLine($"Waiting for {profileTasks.Count} profile tasks");
-        // await Task.WhenAll(profileTasks);
-        // Console.WriteLine("Done waiting for profile tasks");
+        
         await base.OnInitializedAsync();
     }