diff --git a/app/lib/controller/collection_items_controller.dart b/app/lib/controller/collection_items_controller.dart index 9d152c86..2db893fc 100644 --- a/app/lib/controller/collection_items_controller.dart +++ b/app/lib/controller/collection_items_controller.dart @@ -375,7 +375,9 @@ class CollectionItemsController { return null; } } else { - return e.copyWith(file: file); + return e.copyWith( + file: file.replacePath(e.file.fdPath), + ); } } else { return e; diff --git a/app/lib/entity/collection/adapter/nc_album.dart b/app/lib/entity/collection/adapter/nc_album.dart index e9a2ee58..facceb00 100644 --- a/app/lib/entity/collection/adapter/nc_album.dart +++ b/app/lib/entity/collection/adapter/nc_album.dart @@ -56,9 +56,7 @@ class CollectionNcAlbumAdapter i, // retain the path such that it is correctly recognized as part of an // album - f?.copyWith( - fdPath: i.path, - ), + f?.replacePath(i.path), ); }).toList(); }); diff --git a/app/lib/entity/file/data_source2.dart b/app/lib/entity/file/data_source2.dart index ed20dfb6..1f24ecf9 100644 --- a/app/lib/entity/file/data_source2.dart +++ b/app/lib/entity/file/data_source2.dart @@ -171,6 +171,10 @@ class FileNpDbDataSource implements FileDataSource2 { @override Future remove(Account account, FileDescriptor f) async { _log.info("[remove] ${f.fdPath}"); + if (file_util.isNcAlbumFile(account, f)) { + // removing from albums, not deleting the file + return; + } await db.deleteFile( account: account.toDb(), file: f.toDbKey(), diff --git a/app/lib/entity/file_descriptor.dart b/app/lib/entity/file_descriptor.dart index cda61fb9..6c3fb5dc 100644 --- a/app/lib/entity/file_descriptor.dart +++ b/app/lib/entity/file_descriptor.dart @@ -135,6 +135,14 @@ extension FileDescriptorExtension on FileDescriptor { isFavorite: fdIsFavorite, ); } + + FileDescriptor replacePath(String newPath) { + if (this is File) { + return (this as File).copyWith(path: newPath); + } else { + return copyWith(fdPath: newPath); + } + } } class FileDescriptorServerIdentityComparator { diff --git a/app/lib/use_case/nc_album/remove_from_nc_album.dart b/app/lib/use_case/nc_album/remove_from_nc_album.dart index 6939aaa1..0e245531 100644 --- a/app/lib/use_case/nc_album/remove_from_nc_album.dart +++ b/app/lib/use_case/nc_album/remove_from_nc_album.dart @@ -5,6 +5,7 @@ import 'package:nc_photos/debug_util.dart'; import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/collection_item.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; +import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/entity/nc_album.dart'; import 'package:nc_photos/use_case/remove.dart'; import 'package:np_codegen/np_codegen.dart'; @@ -41,11 +42,22 @@ class RemoveFromNcAlbum { } }) .cast() + // since nextcloud album uses the DELETE method, we must make sure we + // are "deleting" with an album path, not the actual file path + .where((e) { + if (file_util.isNcAlbumFile(account, e.file)) { + return true; + } else { + _log.warning("[call] Wrong path for files in Nextcloud album"); + return false; + } + }) .toList(); var count = fileItems.length; await Remove(_c)( account, fileItems.map((e) => e.file).toList(), + shouldCleanUp: false, onError: (i, f, e, stackTrace) { --count; try {