about summary refs log tree commit diff
path: root/LibMatrix/Helpers/SyncHelper.cs
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-10-17 17:11:37 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-10-17 17:11:37 +0200
commit0ad13628bb8ef899927b7b42b5357fe616ce057c (patch)
tree8a04032802bdc13d0b9006e024a54b888a2562dc /LibMatrix/Helpers/SyncHelper.cs
parentHandle floats etc in requests (diff)
downloadLibMatrix-0ad13628bb8ef899927b7b42b5357fe616ce057c.tar.xz
Add updating of profiles and fetching room profiles
Diffstat (limited to 'LibMatrix/Helpers/SyncHelper.cs')
-rw-r--r--LibMatrix/Helpers/SyncHelper.cs9
1 files changed, 5 insertions, 4 deletions
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<SyncResponse?> 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);
         }
     }