Merge pull request #1591 from famedly/krille/refactor-wait-for-room
refactor: Wait for room in sync until sync process and trigger cleanu…
This commit is contained in:
		
						commit
						c6613323b4
					
				|  | @ -739,10 +739,17 @@ class Client extends MatrixApi { | ||||||
|       leave = true; |       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) || |         invite && (sync.rooms?.invite?.containsKey(roomId) ?? false) || | ||||||
|         join && (sync.rooms?.join?.containsKey(roomId) ?? false) || |         join && (sync.rooms?.join?.containsKey(roomId) ?? false) || | ||||||
|         leave && (sync.rooms?.leave?.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 |   /// Checks if the given user has encryption keys. May query keys from the | ||||||
|  | @ -1659,7 +1666,7 @@ class Client extends MatrixApi { | ||||||
|         Logs().d('Running sync while init isn\'t done yet, dropping request'); |         Logs().d('Running sync while init isn\'t done yet, dropping request'); | ||||||
|         return; |         return; | ||||||
|       } |       } | ||||||
|       dynamic syncError; |       Object? syncError; | ||||||
|       await _checkSyncFilter(); |       await _checkSyncFilter(); | ||||||
|       timeout ??= const Duration(seconds: 30); |       timeout ??= const Duration(seconds: 30); | ||||||
|       final syncRequest = sync( |       final syncRequest = sync( | ||||||
|  | @ -1699,12 +1706,12 @@ class Client extends MatrixApi { | ||||||
|           () async => await _currentTransaction, |           () async => await _currentTransaction, | ||||||
|           syncResp.itemCount, |           syncResp.itemCount, | ||||||
|         ); |         ); | ||||||
|         onSyncStatus.add(SyncStatusUpdate(SyncStatus.cleaningUp)); |  | ||||||
|       } else { |       } else { | ||||||
|         await _handleSync(syncResp, direction: Direction.f); |         await _handleSync(syncResp, direction: Direction.f); | ||||||
|       } |       } | ||||||
|       if (_disposed || _aborted) return; |       if (_disposed || _aborted) return; | ||||||
|       prevBatch = syncResp.nextBatch; |       prevBatch = syncResp.nextBatch; | ||||||
|  |       onSyncStatus.add(SyncStatusUpdate(SyncStatus.cleaningUp)); | ||||||
|       // ignore: unawaited_futures |       // ignore: unawaited_futures | ||||||
|       database?.deleteOldFiles( |       database?.deleteOldFiles( | ||||||
|           DateTime.now().subtract(Duration(days: 30)).millisecondsSinceEpoch); |           DateTime.now().subtract(Duration(days: 30)).millisecondsSinceEpoch); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue