fix: Use correct files to discard after local consumption

This commit is contained in:
Anton Stubenbord
2023-10-10 01:26:14 +02:00
parent f3df4c2685
commit 8dadaa42e3
4 changed files with 16 additions and 12 deletions

View File

@@ -44,6 +44,7 @@ class DocumentUploadCubit extends Cubit<DocumentUploadState> {
Iterable<int> 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<DocumentUploadState> {
tags: tags,
createdAt: createdAt,
asn: asn,
onProgressChanged: onProgressChanged,
);
if (taskId != null) {
_tasksNotifier.listenToTaskChanges(taskId);

View File

@@ -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<void> addFiles({
/// from the user's consumption directory. Returns the newly added files copied to the consumption directory.
Future<List<File>> addFiles({
required List<File> files,
required String userId,
}) async {
if (files.isEmpty) {
return;
return [];
}
final consumptionDirectory =
await FileService.getConsumptionDirectory(userId: userId);
final List<File> 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.

View File

@@ -141,13 +141,13 @@ class _EventListenerShellState extends State<EventListenerShell>
if (files.isNotEmpty) {
final userId = context.read<LocalUserAccount>().id;
final notifier = context.read<ConsumptionChangeNotifier>();
await notifier.addFiles(
final addedLocalFiles = await notifier.addFiles(
files: files,
userId: userId,
);
consumeLocalFiles(
context,
files: files,
files: addedLocalFiles,
userId: userId,
exitAppAfterConsumed: true,
);

View File

@@ -14,6 +14,7 @@ abstract class PaperlessDocumentsApi {
int? correspondent,
Iterable<int> tags = const [],
int? asn,
void Function(double progress)? onProgressChanged,
});
Future<DocumentModel> update(DocumentModel doc);
Future<int> findNextAsn();