Przeglądaj źródła

Clear and restart uploads when a subscription is purchased

Vishnu Mohandas 4 lat temu
rodzic
commit
86f97e9c66
2 zmienionych plików z 14 dodań i 9 usunięć
  1. 1 0
      lib/services/sync_service.dart
  2. 13 9
      lib/utils/file_uploader.dart

+ 1 - 0
lib/services/sync_service.dart

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

+ 13 - 9
lib/utils/file_uploader.dart

@@ -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