Skip to content

High performance self-hosted photo and video management solution.

fix(mobile): stop trashing assets after deletion cancellation (#32522)

gitTurboflieger3517973b8a31
diff --git a/mobile/lib/presentation/actions/delete.action.dart b/mobile/lib/presentation/actions/delete.action.dart
index cfc1d0c794..dd33db8472 100644
--- a/mobile/lib/presentation/actions/delete.action.dart
+++ b/mobile/lib/presentation/actions/delete.action.dart
@@ -123,7 +123,10 @@ class DeleteAction extends AssetActionBuilder {
final assetService = ref.read(assetServiceProvider);
final message = context.t.trash_action_prompt(count: remoteIds.length);
if (localIds.isNotEmpty) {
- await _cleanupLocalAssets(context, ref, localIds, isLocalOnly: isLocalOnly);
+ final count = await _cleanupLocalAssets(context, ref, localIds, isLocalOnly: isLocalOnly);
+ if (count <= 0) {
+ return null;
+ }
}
await assetService.trash(remoteIds);
diff --git a/mobile/test/unit/presentation/actions/delete_action_test.dart b/mobile/test/unit/presentation/actions/delete_action_test.dart
index df1d9f6e9b..446d3cdbc4 100644
--- a/mobile/test/unit/presentation/actions/delete_action_test.dart
+++ b/mobile/test/unit/presentation/actions/delete_action_test.dart
@@ -99,6 +99,7 @@ void main() {
});
testWidgets('trashes a merged asset and removes its device copy', (tester) async {
+ when(() => cleanupService.deleteLocalAssets(['local'])).thenAnswer((_) async => 1);
final asset = owned(localId: 'local');
await pumpDelete(tester, {asset});
@@ -108,6 +109,35 @@ void main() {
verify(() => assetService.trash([asset.id])).called(1);
});
+ testWidgets('does not trash a merged asset when the MANAGE_MEDIA prompt is cancelled', (tester) async {
+ debugDefaultTargetPlatformOverride = TargetPlatform.android;
+ await StoreService.I.put(StoreKey.manageLocalMediaAndroid, true);
+ final asset = owned(localId: 'local');
+
+ await pumpDelete(tester, {asset});
+ await respondToDialog(tester, confirm: false);
+
+ verifyNever(() => cleanupService.deleteLocalAssets(any()));
+ verifyNever(() => assetService.trash(any()));
+ verifyNever(() => assetService.delete(any()));
+ debugDefaultTargetPlatformOverride = null;
+ });
+
+ testWidgets('does not trash a merged asset when the Android system prompt is cancelled', (tester) async {
+ debugDefaultTargetPlatformOverride = TargetPlatform.android;
+ when(context.repository.permission.getAndroidSdkVersion).thenAnswer((_) async => 30);
+ when(() => cleanupService.deleteLocalAssets(['local'])).thenAnswer((_) async => 0);
+ final asset = owned(localId: 'local');
+
+ await pumpDelete(tester, {asset});
+ await tester.pumpAndSettle();
+
+ verify(() => cleanupService.deleteLocalAssets(['local'])).called(1);
+ verifyNever(() => assetService.trash(any()));
+ verifyNever(() => assetService.delete(any()));
+ debugDefaultTargetPlatformOverride = null;
+ });
+
testWidgets('finishes trashing when the action context is disposed during local cleanup', (tester) async {
final asset = owned(localId: 'local');
final cleanupResult = Completer<int>();
@@ -315,6 +345,7 @@ void main() {
when(context.repository.permission.getAndroidSdkVersion).thenAnswer((_) async => 28);
final backedUp = owned(localId: 'local');
final localOnly = LocalAssetFactory.create();
+ when(() => cleanupService.deleteLocalAssets(['local', localOnly.id])).thenAnswer((_) async => 1);
await pumpDelete(tester, {backedUp, localOnly});
await tester.pump(const Duration(milliseconds: 300));