Skip to content

Commit

Permalink
fix(mobile): do not removed not backup asset when selecting the corre…
Browse files Browse the repository at this point in the history
…spond options (immich-app#13256)

* fixed the local ids selecting issue

* code: updated impl inside deleteLocalOnlyAssets

* fix: used png instead of jpg to maintain picture quality

* Revert "fix: used png instead of jpg to maintain picture quality"

This reverts commit 04f2ed5.

* fix: update logic from code-review perspective

* refractor (mobile) : Dart fix applied

* fix (mobile) : Updated multi grid as per requirement

---------

Co-authored-by: Alex <alex.tran1502@gmail.com>
  • Loading branch information
2 people authored and yosit committed Nov 21, 2024
1 parent 93a7b69 commit 491846e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
22 changes: 18 additions & 4 deletions mobile/lib/providers/asset.provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,34 +84,48 @@ class AssetNotifier extends StateNotifier<bool> {
_deleteInProgress = true;
state = true;
try {
// Filter the assets based on the backed-up status
final assets = onlyBackedUp
? deleteAssets.where((e) => e.storage == AssetState.merged)
: deleteAssets;

if (assets.isEmpty) {
return false; // No assets to delete
}

// Proceed with local deletion of the filtered assets
final localDeleted = await _deleteLocalAssets(assets);

if (localDeleted.isNotEmpty) {
final localOnlyIds = deleteAssets
final localOnlyIds = assets
.where((e) => e.storage == AssetState.local)
.map((e) => e.id)
.toList();
// Update merged assets to remote only

// Update merged assets to remote-only
final mergedAssets =
deleteAssets.where((e) => e.storage == AssetState.merged).map((e) {
assets.where((e) => e.storage == AssetState.merged).map((e) {
e.localId = null;
return e;
}).toList();

// Update the local database
await _db.writeTxn(() async {
if (mergedAssets.isNotEmpty) {
await _db.assets.putAll(mergedAssets);
await _db.assets
.putAll(mergedAssets); // Use the filtered merged assets
}
await _db.exifInfos.deleteAll(localOnlyIds);
await _db.assets.deleteAll(localOnlyIds);
});

return true;
}
} finally {
_deleteInProgress = false;
state = false;
}

return false;
}

Expand Down
14 changes: 13 additions & 1 deletion mobile/lib/widgets/asset_grid/multiselect_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,30 @@ class MultiselectGrid extends HookConsumerWidget {
void onDeleteLocal(bool onlyBackedUp) async {
processing.value = true;
try {
// Select only the local assets from the selection
final localIds = selection.value.where((a) => a.isLocal).toList();

// Delete only the backed-up assets if 'onlyBackedUp' is true
final isDeleted = await ref
.read(assetProvider.notifier)
.deleteLocalOnlyAssets(localIds, onlyBackedUp: onlyBackedUp);

if (isDeleted) {
// Show a toast with the correct number of deleted assets
final deletedCount = localIds
.where(
(e) => !onlyBackedUp || e.isRemote,
) // Only count backed-up assets
.length;

ImmichToast.show(
context: context,
msg: 'assets_removed_permanently_from_device'
.tr(args: ["${localIds.length}"]),
.tr(args: ["$deletedCount"]),
gravity: ToastGravity.BOTTOM,
);

// Reset the selection
selectionEnabledHook.value = false;
}
} finally {
Expand Down

0 comments on commit 491846e

Please sign in to comment.