From 0330ff6706a968400ca8fe2a3e3ccf6237a15566 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Thu, 19 Oct 2023 07:20:34 +0200 Subject: fix synchelper null check --- LibMatrix/Helpers/SyncHelper.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'LibMatrix/Helpers') diff --git a/LibMatrix/Helpers/SyncHelper.cs b/LibMatrix/Helpers/SyncHelper.cs index bfcd650..c6c5378 100644 --- a/LibMatrix/Helpers/SyncHelper.cs +++ b/LibMatrix/Helpers/SyncHelper.cs @@ -15,15 +15,19 @@ 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)}"; // Console.WriteLine("Calling: " + url); logger?.LogInformation("SyncHelper: Calling: {}", url); try { - return await homeserver._httpClient.GetFromJsonAsync(url, cancellationToken: cancellationToken ?? CancellationToken.None); + return await homeserver?._httpClient?.GetFromJsonAsync(url, cancellationToken: cancellationToken ?? CancellationToken.None)!; } catch (TaskCanceledException) { Console.WriteLine("Sync cancelled!"); -- cgit 1.4.1