Merge branch 'nico/sane-initial-sync-timeout' into 'main'
fix: The initial sync waiting for a long time in some cases See merge request famedly/company/frontend/famedlysdk!1121
This commit is contained in:
commit
831ab2c851
|
|
@ -1439,7 +1439,8 @@ class Client extends MatrixApi {
|
||||||
'Successfully connected as ${userID.localpart} with ${homeserver.toString()}',
|
'Successfully connected as ${userID.localpart} with ${homeserver.toString()}',
|
||||||
);
|
);
|
||||||
|
|
||||||
final syncFuture = _sync();
|
/// Timeout of 0, so that we don't see a spinner for 30 seconds.
|
||||||
|
final syncFuture = _sync(timeout: Duration.zero);
|
||||||
if (waitForFirstSync) {
|
if (waitForFirstSync) {
|
||||||
await syncFuture;
|
await syncFuture;
|
||||||
}
|
}
|
||||||
|
|
@ -1499,8 +1500,11 @@ class Client extends MatrixApi {
|
||||||
return _sync();
|
return _sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _sync() {
|
/// Pass a timeout to set how long the server waits before sending an empty response.
|
||||||
final currentSync = _currentSync ??= _innerSync().whenComplete(() {
|
/// (Corresponds to the timeout param on the /sync request.)
|
||||||
|
Future<void> _sync({Duration? timeout}) {
|
||||||
|
final currentSync =
|
||||||
|
_currentSync ??= _innerSync(timeout: timeout).whenComplete(() {
|
||||||
_currentSync = null;
|
_currentSync = null;
|
||||||
if (_backgroundSync && isLogged() && !_disposed) {
|
if (_backgroundSync && isLogged() && !_disposed) {
|
||||||
_sync();
|
_sync();
|
||||||
|
|
@ -1522,7 +1526,9 @@ class Client extends MatrixApi {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _innerSync() async {
|
/// Pass a timeout to set how long the server waits before sending an empty response.
|
||||||
|
/// (Corresponds to the timeout param on the /sync request.)
|
||||||
|
Future<void> _innerSync({Duration? timeout}) async {
|
||||||
await _retryDelay;
|
await _retryDelay;
|
||||||
_retryDelay = Future.delayed(Duration(seconds: syncErrorTimeoutSec));
|
_retryDelay = Future.delayed(Duration(seconds: syncErrorTimeoutSec));
|
||||||
if (!isLogged() || _disposed || _aborted) return;
|
if (!isLogged() || _disposed || _aborted) return;
|
||||||
|
|
@ -1536,7 +1542,7 @@ class Client extends MatrixApi {
|
||||||
final syncRequest = sync(
|
final syncRequest = sync(
|
||||||
filter: syncFilterId,
|
filter: syncFilterId,
|
||||||
since: prevBatch,
|
since: prevBatch,
|
||||||
timeout: prevBatch != null ? 30000 : null,
|
timeout: timeout?.inMilliseconds ?? 30000,
|
||||||
setPresence: syncPresence,
|
setPresence: syncPresence,
|
||||||
).then((v) => Future<SyncUpdate?>.value(v)).catchError((e) {
|
).then((v) => Future<SyncUpdate?>.value(v)).catchError((e) {
|
||||||
syncError = e;
|
syncError = e;
|
||||||
|
|
|
||||||
|
|
@ -1850,7 +1850,7 @@ class FakeMatrixApi extends BaseClient {
|
||||||
},
|
},
|
||||||
'/client/v3/sync?filter=%7B%22room%22%3A%7B%22include_leave%22%3Atrue%2C%22timeline%22%3A%7B%22limit%22%3A10%7D%7D%7D&timeout=0':
|
'/client/v3/sync?filter=%7B%22room%22%3A%7B%22include_leave%22%3Atrue%2C%22timeline%22%3A%7B%22limit%22%3A10%7D%7D%7D&timeout=0':
|
||||||
(var req) => archiveSyncResponse,
|
(var req) => archiveSyncResponse,
|
||||||
'/client/v3/sync?filter=1234': (var req) => syncResponse,
|
'/client/v3/sync?filter=1234&timeout=0': (var req) => syncResponse,
|
||||||
'/client/v3/sync?filter=1234&since=1234&full_state=false&set_presence=unavailable&timeout=15':
|
'/client/v3/sync?filter=1234&since=1234&full_state=false&set_presence=unavailable&timeout=15':
|
||||||
(var req) => syncResponse,
|
(var req) => syncResponse,
|
||||||
'/client/v3/register/available?username=testuser': (var req) =>
|
'/client/v3/register/available?username=testuser': (var req) =>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue