about summary refs log tree commit diff
path: root/LibMatrix/Helpers/SyncHelper.cs
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-11-05 18:17:11 +0100
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-11-05 18:17:11 +0100
commit1d6399d7f4649472333da946669ce9f1fa349b89 (patch)
tree95baedad8e42956de6d4d339d5c4fdc44ae2396b /LibMatrix/Helpers/SyncHelper.cs
parentsplit client and server http client for homeservers (diff)
downloadLibMatrix-1d6399d7f4649472333da946669ce9f1fa349b89.tar.xz
Cleanup, fixes, fix proxy support
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 fb7fad2..a63b8bb 100644
--- a/LibMatrix/Helpers/SyncHelper.cs
+++ b/LibMatrix/Helpers/SyncHelper.cs
@@ -15,12 +15,13 @@ public class SyncHelper(AuthenticatedHomeserverGeneric homeserver, ILogger? logg
     public bool FullState { get; set; } = false;
 
     public bool IsInitialSync { get; set; } = true;
-    
+
     public async Task<SyncResponse?> SyncAsync(CancellationToken? cancellationToken = null) {
         if (homeserver is null) {
             Console.WriteLine("Null passed as homeserver for SyncHelper!");
             throw new ArgumentNullException("Null passed as homeserver for SyncHelper!");
         }
+
         var url = $"/_matrix/client/v3/sync?timeout={Timeout}&set_presence={SetPresence}&full_state={(FullState ? "true" : "false")}";
         if (!string.IsNullOrWhiteSpace(Since)) url += $"&since={Since}";
         if (Filter is not null) url += $"&filter={Filter.ToJson(ignoreNull: true, indent: false)}";
@@ -45,7 +46,7 @@ public class SyncHelper(AuthenticatedHomeserverGeneric homeserver, ILogger? logg
         while (!cancellationToken?.IsCancellationRequested ?? true) {
             var sync = await SyncAsync(cancellationToken);
             if (sync is null) continue;
-            Since = string.IsNullOrWhiteSpace(sync?.NextBatch) ? Since : sync.NextBatch;
+            if (!string.IsNullOrWhiteSpace(sync?.NextBatch)) Since = sync.NextBatch;
             yield return sync;
         }
     }
@@ -73,7 +74,7 @@ public class SyncHelper(AuthenticatedHomeserverGeneric homeserver, ILogger? logg
         var tasks = SyncReceivedHandlers.Select(x => x(syncResponse)).ToList();
         await Task.WhenAll(tasks);
 
-        if (syncResponse.AccountData is { Events: { Count: > 0 } }) {
+        if (syncResponse.AccountData is { Events.Count: > 0 }) {
             foreach (var accountDataEvent in syncResponse.AccountData.Events) {
                 tasks = AccountDataReceivedHandlers.Select(x => x(accountDataEvent)).ToList();
                 await Task.WhenAll(tasks);
@@ -124,4 +125,4 @@ public class SyncHelper(AuthenticatedHomeserverGeneric homeserver, ILogger? logg
     /// Event fired when an account data event is received
     /// </summary>
     public List<Func<StateEventResponse, Task>> AccountDataReceivedHandlers { get; } = new();
-}
+}
\ No newline at end of file