From 1d6399d7f4649472333da946669ce9f1fa349b89 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Sun, 5 Nov 2023 18:17:11 +0100 Subject: Cleanup, fixes, fix proxy support --- 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 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 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 /// public List> AccountDataReceivedHandlers { get; } = new(); -} +} \ No newline at end of file -- cgit 1.4.1