From 812c7dde829add9bbfbe83fb15d92063a5d5fa5c Mon Sep 17 00:00:00 2001 From: Krille Date: Mon, 29 Jul 2024 16:02:19 +0200 Subject: [PATCH] refactor: Do not set default timeout for initialSync --- lib/src/client.dart | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index c7405121..c4988093 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -2283,16 +2283,18 @@ class Client extends MatrixApi { // The timeout we send to the server for the sync loop. It says to the // server that we want to receive an empty sync response after this // amount of time if nothing happens. - timeout ??= const Duration(seconds: 30); + if (prevBatch != null) timeout ??= const Duration(seconds: 30); - await ensureNotSoftLoggedOut(timeout * 2); + await ensureNotSoftLoggedOut( + timeout == null ? const Duration(minutes: 1) : (timeout * 2), + ); await _checkSyncFilter(); final syncRequest = sync( filter: syncFilterId, since: prevBatch, - timeout: timeout.inMilliseconds, + timeout: timeout?.inMilliseconds, setPresence: syncPresence, ).then((v) => Future.value(v)).catchError((e) { if (e is MatrixException) { @@ -2308,11 +2310,13 @@ class Client extends MatrixApi { // The timeout for the response from the server. If we do not set a sync // timeout (for initial sync) we give the server a longer time to // responde. - final responseTimeout = timeout == Duration.zero - ? const Duration(minutes: 2) - : timeout + const Duration(seconds: 10); + final responseTimeout = + timeout == null ? null : timeout + const Duration(seconds: 10); + + final syncResp = responseTimeout == null + ? await syncRequest + : await syncRequest.timeout(responseTimeout); - final syncResp = await syncRequest.timeout(responseTimeout); onSyncStatus.add(SyncStatusUpdate(SyncStatus.processing)); if (syncResp == null) throw syncError ?? 'Unknown sync error'; if (_currentSyncId != syncRequest.hashCode) {