From 0ad13628bb8ef899927b7b42b5357fe616ce057c Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Tue, 17 Oct 2023 17:11:37 +0200 Subject: Add updating of profiles and fetching room profiles --- LibMatrix/Helpers/SyncHelper.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'LibMatrix/Helpers') diff --git a/LibMatrix/Helpers/SyncHelper.cs b/LibMatrix/Helpers/SyncHelper.cs index 6bdf5ad..bfcd650 100644 --- a/LibMatrix/Helpers/SyncHelper.cs +++ b/LibMatrix/Helpers/SyncHelper.cs @@ -14,6 +14,8 @@ public class SyncHelper(AuthenticatedHomeserverGeneric homeserver, ILogger? logg public SyncFilter? Filter { get; set; } public bool FullState { get; set; } = false; + public bool IsInitialSync { get; set; } = true; + public async Task SyncAsync(CancellationToken? cancellationToken = null) { var url = $"/_matrix/client/v3/sync?timeout={Timeout}&set_presence={SetPresence}&full_state={(FullState ? "true" : "false")}"; if (!string.IsNullOrWhiteSpace(Since)) url += $"&since={Since}"; @@ -39,14 +41,13 @@ public class SyncHelper(AuthenticatedHomeserverGeneric homeserver, ILogger? logg while (!cancellationToken?.IsCancellationRequested ?? true) { var sync = await SyncAsync(cancellationToken); if (sync is null) continue; - Since = sync.NextBatch ?? Since; + Since = string.IsNullOrWhiteSpace(sync?.NextBatch) ? Since : sync.NextBatch; yield return sync; } } public async Task RunSyncLoopAsync(bool skipInitialSyncEvents = true, CancellationToken? cancellationToken = null) { var sw = Stopwatch.StartNew(); - bool isInitialSync = true; int emptyInitialSyncCount = 0; var oldTimeout = Timeout; Timeout = 0; @@ -55,12 +56,12 @@ public class SyncHelper(AuthenticatedHomeserverGeneric homeserver, ILogger? logg if (sync?.ToJson(ignoreNull: true, indent: false).Length < 250) { emptyInitialSyncCount++; if (emptyInitialSyncCount > 5) { - isInitialSync = false; + IsInitialSync = false; Timeout = oldTimeout; } } - await RunSyncLoopCallbacksAsync(sync, isInitialSync && skipInitialSyncEvents); + await RunSyncLoopCallbacksAsync(sync, IsInitialSync && skipInitialSyncEvents); } } -- cgit 1.4.1