From 8dadaa42e3479ab182ec03ac8ec439992b76c189 Mon Sep 17 00:00:00 2001 From: Anton Stubenbord Date: Tue, 10 Oct 2023 01:26:14 +0200 Subject: [PATCH] fix: Use correct files to discard after local consumption --- .../cubit/document_upload_cubit.dart | 2 ++ .../sharing/cubit/receive_share_cubit.dart | 21 ++++++++++--------- .../view/widgets/event_listener_shell.dart | 4 ++-- .../paperless_documents_api.dart | 1 + 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/features/document_upload/cubit/document_upload_cubit.dart b/lib/features/document_upload/cubit/document_upload_cubit.dart index 86019a9..bfe4f50 100644 --- a/lib/features/document_upload/cubit/document_upload_cubit.dart +++ b/lib/features/document_upload/cubit/document_upload_cubit.dart @@ -44,6 +44,7 @@ class DocumentUploadCubit extends Cubit { Iterable tags = const [], DateTime? createdAt, int? asn, + void Function(double)? onProgressChanged, }) async { final taskId = await _documentApi.create( bytes, @@ -54,6 +55,7 @@ class DocumentUploadCubit extends Cubit { tags: tags, createdAt: createdAt, asn: asn, + onProgressChanged: onProgressChanged, ); if (taskId != null) { _tasksNotifier.listenToTaskChanges(taskId); diff --git a/lib/features/sharing/cubit/receive_share_cubit.dart b/lib/features/sharing/cubit/receive_share_cubit.dart index 19317d4..facaada 100644 --- a/lib/features/sharing/cubit/receive_share_cubit.dart +++ b/lib/features/sharing/cubit/receive_share_cubit.dart @@ -23,27 +23,28 @@ class ConsumptionChangeNotifier extends ChangeNotifier { } /// Creates a local copy of all shared files and reloads all files - /// from the user's consumption directory. - Future addFiles({ + /// from the user's consumption directory. Returns the newly added files copied to the consumption directory. + Future> addFiles({ required List files, required String userId, }) async { if (files.isEmpty) { - return; + return []; } final consumptionDirectory = await FileService.getConsumptionDirectory(userId: userId); + final List localFiles = []; for (final file in files) { - File localFile; - if (file.path.startsWith(consumptionDirectory.path)) { - localFile = file; + if (!file.path.startsWith(consumptionDirectory.path)) { + final localFile = await file + .copy(p.join(consumptionDirectory.path, p.basename(file.path))); + localFiles.add(localFile); } else { - final fileName = p.basename(file.path); - localFile = File(p.join(consumptionDirectory.path, fileName)); - await file.copy(localFile.path); + localFiles.add(file); } } - return loadFromConsumptionDirectory(userId: userId); + await loadFromConsumptionDirectory(userId: userId); + return localFiles; } /// Marks a file as processed by removing it from the queue and deleting the local copy of the file. diff --git a/lib/features/sharing/view/widgets/event_listener_shell.dart b/lib/features/sharing/view/widgets/event_listener_shell.dart index 55f82b6..ff637e2 100644 --- a/lib/features/sharing/view/widgets/event_listener_shell.dart +++ b/lib/features/sharing/view/widgets/event_listener_shell.dart @@ -141,13 +141,13 @@ class _EventListenerShellState extends State if (files.isNotEmpty) { final userId = context.read().id; final notifier = context.read(); - await notifier.addFiles( + final addedLocalFiles = await notifier.addFiles( files: files, userId: userId, ); consumeLocalFiles( context, - files: files, + files: addedLocalFiles, userId: userId, exitAppAfterConsumed: true, ); diff --git a/packages/paperless_api/lib/src/modules/documents_api/paperless_documents_api.dart b/packages/paperless_api/lib/src/modules/documents_api/paperless_documents_api.dart index 09560aa..ccbad6d 100644 --- a/packages/paperless_api/lib/src/modules/documents_api/paperless_documents_api.dart +++ b/packages/paperless_api/lib/src/modules/documents_api/paperless_documents_api.dart @@ -14,6 +14,7 @@ abstract class PaperlessDocumentsApi { int? correspondent, Iterable tags = const [], int? asn, + void Function(double progress)? onProgressChanged, }); Future update(DocumentModel doc); Future findNextAsn();