From 229d07261e67a48d93103d6bcec84cce370153ec Mon Sep 17 00:00:00 2001 From: Rory& Date: Sat, 3 May 2025 13:33:48 +0200 Subject: Sync preprocessor support --- LibMatrix/Helpers/SyncHelper.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'LibMatrix/Helpers/SyncHelper.cs') diff --git a/LibMatrix/Helpers/SyncHelper.cs b/LibMatrix/Helpers/SyncHelper.cs index abbf541..e8ca8b7 100644 --- a/LibMatrix/Helpers/SyncHelper.cs +++ b/LibMatrix/Helpers/SyncHelper.cs @@ -5,6 +5,7 @@ using ArcaneLibs.Collections; using System.Text.Json.Nodes; using ArcaneLibs.Extensions; using LibMatrix.Filters; +using LibMatrix.Helpers.SyncProcessors; using LibMatrix.Homeservers; using LibMatrix.Interfaces.Services; using LibMatrix.Responses; @@ -23,6 +24,10 @@ public class SyncHelper(AuthenticatedHomeserverGeneric homeserver, ILogger? logg public string? SetPresence { get; set; } = "online"; public bool UseInternalStreamingSync { get; set; } = true; + public List> SyncPreprocessors { get; } = [ + SimpleSyncProcessors.FillRoomIds + ]; + public string? FilterId { get => _filterId; set { @@ -76,7 +81,7 @@ public class SyncHelper(AuthenticatedHomeserverGeneric homeserver, ILogger? logg else if (Filter is not null) _filterId = (await homeserver.UploadFilterAsync(Filter)).FilterId; else _filterId = null; - + _filterIsDirty = false; } @@ -106,6 +111,11 @@ public class SyncHelper(AuthenticatedHomeserverGeneric homeserver, ILogger? logg var sync = await SyncAsyncInternal(cancellationToken, noDelay); // Ditto here. if (sync is not null && sync.NextBatch != Since) await storageProvider.SaveObjectAsync(key, sync); + + foreach (var preprocessor in SyncPreprocessors) { + sync = preprocessor(sync); + } + return sync; } @@ -165,11 +175,10 @@ public class SyncHelper(AuthenticatedHomeserverGeneric homeserver, ILogger? logg if (sync is null) continue; if (!string.IsNullOrWhiteSpace(sync.NextBatch)) Since = sync.NextBatch; yield return sync; - - + var timeToWait = MinimumDelay.Subtract(sw.Elapsed); if (timeToWait.TotalMilliseconds > 0) { - logger?.LogWarning("EnumerateSyncAsync: Waiting {delay}", timeToWait); + logger?.LogWarning("EnumerateSyncAsync: Waiting {delay}", timeToWait); await Task.Delay(timeToWait); } } -- cgit 1.5.1