From 9319fe76c56b79e0933c09280fe32658c2f176c7 Mon Sep 17 00:00:00 2001 From: Rory& Date: Fri, 5 Apr 2024 19:01:39 +0200 Subject: Cleanup, work on index2, some tooling updates --- MatrixUtils.Web/Pages/Index.razor | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'MatrixUtils.Web/Pages/Index.razor') diff --git a/MatrixUtils.Web/Pages/Index.razor b/MatrixUtils.Web/Pages/Index.razor index 7c0a9f2..b3dc7d4 100644 --- a/MatrixUtils.Web/Pages/Index.razor +++ b/MatrixUtils.Web/Pages/Index.razor @@ -2,7 +2,6 @@ @inject ILogger logger @using LibMatrix.Responses @using LibMatrix -@using ArcaneLibs.Extensions @using ArcaneLibs @using System.Diagnostics @@ -34,7 +33,7 @@ Small collection of tools to do not-so-everyday things. @session.UserInfo.DisplayName on @_auth.Homeserver

@session.UserInfo.RoomCount rooms - @session.ServerVersion.Server.Name @session.ServerVersion.Server.Version + @session.ServerVersion?.Server.Name @session.ServerVersion?.Server.Version @if (_auth.Proxy != null) { (proxied via @_auth.Proxy) } @@ -132,7 +131,6 @@ Small collection of tools to do not-so-everyday things. public AuthenticatedHomeserverGeneric? Homeserver { get; set; } } - // private Dictionary _users = new(); private readonly List _sessions = []; private readonly List _offlineSessions = []; private readonly List _invalidSessions = []; @@ -142,12 +140,14 @@ Small collection of tools to do not-so-everyday things. protected override async Task OnInitializedAsync() { Console.WriteLine("Index.OnInitializedAsync"); + logger.LogDebug("Initialising index page"); _currentSession = await RMUStorage.GetCurrentToken(); _sessions.Clear(); _offlineSessions.Clear(); var tokens = await RMUStorage.GetAllTokens(); scannedSessions = 0; totalSessions = tokens.Count; + logger.LogDebug("Found {0} tokens", totalSessions); if (tokens is not { Count: > 0 }) { Console.WriteLine("No tokens found, trying migration from MRU..."); await RMUStorage.MigrateFromMRU(); @@ -166,7 +166,7 @@ Small collection of tools to do not-so-everyday things. if ((!string.IsNullOrWhiteSpace(token.Proxy) && offlineServers.Contains(token.Proxy)) || offlineServers.Contains(token.Homeserver)) { _offlineSessions.Add(token); sema.Release(); - scannedSessions++; + scannedSessions++; return; } @@ -192,10 +192,17 @@ Small collection of tools to do not-so-everyday things. } } catch (MatrixException e) { - if (e is { ErrorCode: "M_UNKNOWN_TOKEN" }) _invalidSessions.Add(token); - else throw; + if (e is { ErrorCode: "M_UNKNOWN_TOKEN" }) { + logger.LogWarning("Got unknown token error for {0} via {1}", token.UserId, token.Homeserver); + _invalidSessions.Add(token); + } + else { + logger.LogError("Failed to get info for {0} via {1}: {2}", token.UserId, token.Homeserver, e); + throw; + } } - catch { + catch (Exception e) { + logger.LogError("Failed to get info for {0} via {1}: {2}", token.UserId, token.Homeserver, e); if (!string.IsNullOrWhiteSpace(token.Proxy)) { offlineServers.Add(token.Proxy); @@ -211,7 +218,7 @@ Small collection of tools to do not-so-everyday things. }).ToList(); await Task.WhenAll(tasks); scannedSessions = totalSessions; - + await base.OnInitializedAsync(); } @@ -239,7 +246,6 @@ Small collection of tools to do not-so-everyday things. await RMUStorage.RemoveToken(auth); if ((await RMUStorage.GetCurrentToken())?.AccessToken == auth.AccessToken) await RMUStorage.SetCurrentToken((await RMUStorage.GetAllTokens() ?? throw new InvalidOperationException()).FirstOrDefault()); - // await OnInitializedAsync(); StateHasChanged(); } @@ -247,7 +253,6 @@ Small collection of tools to do not-so-everyday things. Console.WriteLine($"Switching to {auth.Homeserver} {auth.UserId} via {auth.Proxy}"); await RMUStorage.SetCurrentToken(auth); _currentSession = auth; - // await OnInitializedAsync(); StateHasChanged(); } -- cgit 1.4.1