Clear and restart uploads when a subscription is purchased

This commit is contained in:
Vishnu Mohandas 2021-02-02 23:55:43 +05:30
parent 38b2df9c58
commit 86f97e9c66
2 changed files with 14 additions and 9 deletions

View file

@ -45,6 +45,7 @@ class SyncService {
SyncService._privateConstructor() {
Bus.instance.on<SubscriptionPurchasedEvent>().listen((event) {
_uploader.clearQueue();
sync();
});

View file

@ -106,17 +106,21 @@ class FileUploader {
}
}
void clearQueue() {
final uploadsToBeRemoved = List<int>();
_queue.entries
.where((entry) => entry.value.status == UploadStatus.not_started)
.forEach((pendingUpload) {
uploadsToBeRemoved.add(pendingUpload.key);
});
for (final id in uploadsToBeRemoved) {
_queue.remove(id).completer.completeError(SyncStopRequestedError());
}
}
void _pollQueue() {
if (SyncService.instance.shouldStopSync()) {
final uploadsToBeRemoved = List<int>();
_queue.entries
.where((entry) => entry.value.status == UploadStatus.not_started)
.forEach((pendingUpload) {
uploadsToBeRemoved.add(pendingUpload.key);
});
for (final id in uploadsToBeRemoved) {
_queue.remove(id).completer.completeError(SyncStopRequestedError());
}
clearQueue();
}
if (_queue.length > 0 && _currentlyUploading < _maximumConcurrentUploads) {
final firstPendingEntry = _queue.entries