about summary refs log tree commit diff
path: root/ModerationClient
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-03-31 09:32:24 +0200
committerRory& <root@rory.gay>2025-03-31 09:32:24 +0200
commit5c5a9fb78c45f80330775286b65b5d78e3e99934 (patch)
tree51ddc9889274cbd052f5f368e0c64b4d5c8747e0 /ModerationClient
parentFix some crashes (diff)
downloadModerationClient-5c5a9fb78c45f80330775286b65b5d78e3e99934.tar.xz
Cleanup and some error handling HEAD master
Diffstat (limited to 'ModerationClient')
-rw-r--r--ModerationClient/Models/SpaceTreeNodes/RoomNode.cs2
-rw-r--r--ModerationClient/Models/SpaceTreeNodes/SpaceNode.cs18
-rw-r--r--ModerationClient/Services/ClientContainer.cs18
-rw-r--r--ModerationClient/ViewModels/ClientViewModel.cs27
-rw-r--r--ModerationClient/Views/MainWindow/ClientView.axaml2
-rw-r--r--ModerationClient/flake.lock6
-rw-r--r--ModerationClient/flake.nix7
7 files changed, 56 insertions, 24 deletions
diff --git a/ModerationClient/Models/SpaceTreeNodes/RoomNode.cs b/ModerationClient/Models/SpaceTreeNodes/RoomNode.cs

index e6715d8..5edc7db 100644 --- a/ModerationClient/Models/SpaceTreeNodes/RoomNode.cs +++ b/ModerationClient/Models/SpaceTreeNodes/RoomNode.cs
@@ -21,4 +21,6 @@ public class RoomNode : NotifyPropertyChanged { public ObservableCollection<StateEventResponse> Timeline { get; } = new(); public ObservableCollection<StateEventResponse> State { get; } = new(); public List<Control> RenderedTimeline => Timeline.Select(EventRenderer.RenderEvent).ToList(); + + public long? LastActivity => Timeline.LastOrDefault()?.OriginServerTs; } \ No newline at end of file diff --git a/ModerationClient/Models/SpaceTreeNodes/SpaceNode.cs b/ModerationClient/Models/SpaceTreeNodes/SpaceNode.cs
index b8042ae..781e974 100644 --- a/ModerationClient/Models/SpaceTreeNodes/SpaceNode.cs +++ b/ModerationClient/Models/SpaceTreeNodes/SpaceNode.cs
@@ -1,4 +1,7 @@ +using System; +using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Linq; namespace ModerationClient.Models.SpaceTreeNodes; @@ -6,10 +9,21 @@ public class SpaceNode : RoomNode { private bool _isExpanded = false; public SpaceNode(bool includeSelf = true) { - if(includeSelf) + if (includeSelf) ChildRooms = [this]; + + ChildRooms.CollectionChanged += (_, _) => ChildRoomsByActivity = ChildRooms.OrderByDescending(x=>x.LastActivity).ToArray(); } public ObservableCollection<SpaceNode> ChildSpaces { get; set; } = []; - public ObservableCollection<RoomNode> ChildRooms { get; set; } = []; + + public ObservableCollection<RoomNode> ChildRooms { + get; + set => SetField(ref field, value); + } = []; + + public RoomNode[] ChildRoomsByActivity { + get; + set => SetField(ref field, value); + } = []; } \ No newline at end of file diff --git a/ModerationClient/Services/ClientContainer.cs b/ModerationClient/Services/ClientContainer.cs
index 957e3cc..ebdbab6 100644 --- a/ModerationClient/Services/ClientContainer.cs +++ b/ModerationClient/Services/ClientContainer.cs
@@ -5,18 +5,10 @@ using Microsoft.Extensions.Logging; namespace ModerationClient.Services; -public class ClientContainer { - private readonly ILogger<ClientContainer> _logger; - private readonly MatrixAuthenticationService _authService; - private readonly CommandLineConfiguration _cfg; +public class ClientContainer(ILogger<ClientContainer> logger, MatrixAuthenticationService authService, CommandLineConfiguration cfg) { + private readonly CommandLineConfiguration _cfg = cfg; - public ClientContainer(ILogger<ClientContainer> logger, MatrixAuthenticationService authService, CommandLineConfiguration cfg) { - _logger = logger; - _authService = authService; - _cfg = cfg; - } - - private bool _isRunning = false; + private bool _isRunning; public void EnsureRunning() { @@ -25,7 +17,7 @@ public class ClientContainer { _ = Task.Run(Run).ContinueWith(t => { if (t.IsFaulted) { - _logger.LogError(t.Exception, "Error in client container task"); + logger.LogError(t.Exception, "Error in client container task"); } return _isRunning = false; }); @@ -34,7 +26,7 @@ public class ClientContainer { private async Task Run() { Console.WriteLine("Running client view model loop..."); - ArgumentNullException.ThrowIfNull(_authService.Homeserver, nameof(_authService.Homeserver)); + ArgumentNullException.ThrowIfNull(authService.Homeserver, nameof(authService.Homeserver)); } } \ No newline at end of file diff --git a/ModerationClient/ViewModels/ClientViewModel.cs b/ModerationClient/ViewModels/ClientViewModel.cs
index a2da5be..378c0de 100644 --- a/ModerationClient/ViewModels/ClientViewModel.cs +++ b/ModerationClient/ViewModels/ClientViewModel.cs
@@ -6,6 +6,8 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; +using System.Net; +using System.Net.Http; using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -15,8 +17,10 @@ using ArcaneLibs.Extensions; using LibMatrix; using LibMatrix.EventTypes.Spec.State; using LibMatrix.EventTypes.Spec.State.RoomInfo; +using LibMatrix.Filters; using LibMatrix.Helpers; using LibMatrix.Responses; +using LibMatrix.Services; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using ModerationClient.Models.SpaceTreeNodes; @@ -90,9 +94,13 @@ public partial class ClientViewModel : ViewModelBase { var ssr = new SyncStateResolver(_authService.Homeserver, _logger, storageProvider: store); Console.WriteLine("Created sync state resolver..."); Status = "Optimising sync store, please wait... Creating new snapshot..."; + var sw = Stopwatch.StartNew(); await ssr.OptimiseStore((remaining, total) => { - if (remaining % (remaining / 10) == 0) + // if (remaining % (remaining / 10) == 0) + if (sw.ElapsedMilliseconds > 100) { Status = $"Optimising sync store, please wait... {remaining}/{total} remaining..."; + sw.Restart(); + } }); Status = "Optimising sync store, please wait... Deleting old intermediate snapshots..."; await ssr.RemoveOldSnapshots(); @@ -110,6 +118,21 @@ public partial class ClientViewModel : ViewModelBase { Status = "Doing initial sync..."; var currentSyncRes = "init"; var lastGc = DateTime.Now; + int syncGatewayTimeouts = 0; + // var filter = new SyncFilter() { + // Room = new SyncFilter.RoomFilter() { + // Rooms = [] + // } + // }; + // + // sh.Filter = filter; + + sh.ExceptionHandlers.Add(async (ex) => { + if (ex is HttpRequestException { StatusCode: HttpStatusCode.GatewayTimeout }) { + syncGatewayTimeouts++; + Status = $"Got {syncGatewayTimeouts} sync gateway timeouts..."; + } + }); await foreach (var res in sh.EnumerateSyncAsync()) { var sw = Stopwatch.StartNew(); //log thing @@ -150,7 +173,7 @@ public partial class ClientViewModel : ViewModelBase { Console.WriteLine($"Processed sync {currentSyncRes} in {sw.ElapsedMilliseconds}ms (applied in: {applySw.ElapsedMilliseconds}ms)"); if (Paused) { Status = "Sync loop interrupted... Press pause/break to resume."; - while (Paused) await Task.Delay(1000); + while (Paused) await Task.Delay(100); } else Status = $"Syncing... {unoptimised++} unoptimised sync responses, last={currentSyncRes}..."; diff --git a/ModerationClient/Views/MainWindow/ClientView.axaml b/ModerationClient/Views/MainWindow/ClientView.axaml
index 6db948a..e183897 100644 --- a/ModerationClient/Views/MainWindow/ClientView.axaml +++ b/ModerationClient/Views/MainWindow/ClientView.axaml
@@ -19,7 +19,7 @@ </Grid.ColumnDefinitions> <TreeView Grid.Column="0" Background="#202020" ItemsSource="{CompiledBinding DisplayedSpaces}" SelectedItem="{CompiledBinding CurrentSpace}"> <TreeView.ItemTemplate> - <TreeDataTemplate ItemsSource="{Binding ChildSpaces}" DataType="spaceTreeNodes:SpaceNode"> + <TreeDataTemplate ItemsSource="{Binding ChildRoomsByActivity}" DataType="spaceTreeNodes:SpaceNode"> <TextBlock Text="{Binding Name}" Height="20" /> </TreeDataTemplate> </TreeView.ItemTemplate> diff --git a/ModerationClient/flake.lock b/ModerationClient/flake.lock
index 7a75871..6a13168 100644 --- a/ModerationClient/flake.lock +++ b/ModerationClient/flake.lock
@@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1739866667, - "narHash": "sha256-EO1ygNKZlsAC9avfcwHkKGMsmipUk1Uc0TbrEZpkn64=", + "lastModified": 1742889210, + "narHash": "sha256-hw63HnwnqU3ZQfsMclLhMvOezpM7RSB0dMAtD5/sOiw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "73cf49b8ad837ade2de76f87eb53fc85ed5d4680", + "rev": "698214a32beb4f4c8e3942372c694f40848b360d", "type": "github" }, "original": { diff --git a/ModerationClient/flake.nix b/ModerationClient/flake.nix
index 6c55fde..64476d1 100644 --- a/ModerationClient/flake.nix +++ b/ModerationClient/flake.nix
@@ -16,12 +16,13 @@ libX11 libX11.dev ]; + dotnetSdk = pkgs.dotnetCorePackages.dotnet_9.sdk; in rec { # `nix develop` devShells.default = with pkgs; mkShell { buildInputs = [ - dotnetCorePackages.dotnet_9.sdk + dotnetSdk fontconfig gnumake icu @@ -29,9 +30,9 @@ ] ++ xorgLibs; shellHook = '' - export DOTNET_ROOT=${dotnet-sdk} + export DOTNET_ROOT=${dotnetSdk} export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${lib.makeLibraryPath ([ fontconfig icu openssl ] ++ xorgLibs) } ''; }; }); -} \ No newline at end of file +}