Skip to content

Commit

Permalink
Merge pull request #1591 from famedly/krille/refactor-wait-for-room
Browse files Browse the repository at this point in the history
refactor: Wait for room in sync until sync process and trigger cleanu…
  • Loading branch information
krille-chan authored Oct 23, 2023
2 parents 49f76b4 + f0e4232 commit eff142f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -739,10 +739,17 @@ class Client extends MatrixApi {
leave = true;
}

return await onSync.stream.firstWhere((sync) =>
// Wait for the next sync where this room appears.
final syncUpdate = await onSync.stream.firstWhere((sync) =>
invite && (sync.rooms?.invite?.containsKey(roomId) ?? false) ||
join && (sync.rooms?.join?.containsKey(roomId) ?? false) ||
leave && (sync.rooms?.leave?.containsKey(roomId) ?? false));

// Wait for this sync to be completely processed.
await onSyncStatus.stream.firstWhere(
(syncStatus) => syncStatus.status == SyncStatus.finished,
);
return syncUpdate;
}

/// Checks if the given user has encryption keys. May query keys from the
Expand Down Expand Up @@ -1659,7 +1666,7 @@ class Client extends MatrixApi {
Logs().d('Running sync while init isn\'t done yet, dropping request');
return;
}
dynamic syncError;
Object? syncError;
await _checkSyncFilter();
timeout ??= const Duration(seconds: 30);
final syncRequest = sync(
Expand Down Expand Up @@ -1699,12 +1706,12 @@ class Client extends MatrixApi {
() async => await _currentTransaction,
syncResp.itemCount,
);
onSyncStatus.add(SyncStatusUpdate(SyncStatus.cleaningUp));
} else {
await _handleSync(syncResp, direction: Direction.f);
}
if (_disposed || _aborted) return;
prevBatch = syncResp.nextBatch;
onSyncStatus.add(SyncStatusUpdate(SyncStatus.cleaningUp));
// ignore: unawaited_futures
database?.deleteOldFiles(
DateTime.now().subtract(Duration(days: 30)).millisecondsSinceEpoch);
Expand Down

0 comments on commit eff142f

Please sign in to comment.