π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] fix device trash deletion state
Priyanshu Dangared534d17b10a8
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dartindex 4acd0e1b88..188168a608 100644--- a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart@@ -1114,7 +1114,15 @@ class _FileSelectionActionsWidgetState(f) => f.isDeviceTrash,);if (isDeviceOnly) {- await permanentlyDeleteFromDeviceTrash(context, widget.selectedFiles);+ final deletedIDs = await permanentlyDeleteFromDeviceTrash(+ context,+ widget.selectedFiles.files.map((f) => f.localID!).toList(),+ );+ widget.selectedFiles.unSelectAll(+ widget.selectedFiles.files+ .where((f) => deletedIDs.contains(f.localID))+ .toSet(),+ );return;}if (await deleteFromEnteTrash(diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dartindex b7ba51c6ca..42fbfbefa7 100644--- a/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart@@ -273,10 +273,11 @@ class FileBottomBarState extends State<FileBottomBar> {),onPressed: () async {if (widget.file.isDeviceTrash) {- final selectedFiles = SelectedFiles()- ..toggleSelection(widget.file);- await permanentlyDeleteFromDeviceTrash(context, selectedFiles);- if (selectedFiles.files.isEmpty) {+ final deletedIDs = await permanentlyDeleteFromDeviceTrash(+ context,+ [widget.file.localID!],+ );+ if (deletedIDs.isNotEmpty) {await widget.onFileRemoved(widget.file);}return;diff --git a/mobile/apps/photos/lib/utils/delete_file_util.dart b/mobile/apps/photos/lib/utils/delete_file_util.dartindex 9913ead3d5..8765cb641f 100644--- a/mobile/apps/photos/lib/utils/delete_file_util.dart+++ b/mobile/apps/photos/lib/utils/delete_file_util.dart@@ -1355,54 +1355,51 @@ class _DeleteConfirmationSheetState extends State<_DeleteConfirmationSheet> {}}-Future<void> permanentlyDeleteFromDeviceTrash(+Future<Set<String>> permanentlyDeleteFromDeviceTrash(BuildContext context,- SelectedFiles selectedFiles,+ List<String> fileIDs,) async {+ (Set<String>, Object?) result = (<String>{}, null);if (!await PhotoManager.canManageMedia()) {- try {- final didDelete = await _deleteFromDeviceTrash(selectedFiles);- if (didDelete && context.mounted) {- await showMediaManagementHintSheet(context);- }- return;- } catch (e) {- if (context.mounted) {- await showGenericErrorDialog(context: context, error: e);- }- return;+ result = await _deleteFromDeviceTrash(fileIDs);+ if (result.$1.isNotEmpty && context.mounted) {+ await showMediaManagementHintSheet(context);}+ } else {+ if (!context.mounted) return result.$1;+ await showBottomSheetComponent<ButtonResult>(+ context: context,+ builder: (_) => PermanentlyDeleteConfirmationSheet(+ onDelete: () async {+ result = await _deleteFromDeviceTrash(fileIDs);+ if (result.$2 != null) {+ throw result.$2!;+ }+ },+ ),+ );}- if (!context.mounted) return;- final result = await showBottomSheetComponent<ButtonResult>(- context: context,- builder: (_) => PermanentlyDeleteConfirmationSheet(- onDelete: () => _deleteFromDeviceTrash(selectedFiles),- ),- );- if (result?.action == ButtonAction.error && context.mounted) {- await showGenericErrorDialog(context: context, error: result!.exception);+ if (result.$2 != null && context.mounted) {+ await showGenericErrorDialog(context: context, error: result.$2!);}+ return result.$1;}-Future<bool> _deleteFromDeviceTrash(SelectedFiles selectedFiles) async {- final fileIDs = selectedFiles.files.map((f) => f.localID!).toList();+Future<(Set<String>, Object?)> _deleteFromDeviceTrash(+ List<String> fileIDs,+) async {final deletedIDs = <String>{};try {for (final batch in fileIDs.chunks(batchSize)) {final result = await PhotoManager.editor.deleteWithIds(batch);deletedIDs.addAll(result);}- return deletedIDs.isNotEmpty;+ return (deletedIDs, null);} catch (e, s) {_logger.severe("failed to delete from device trash:", e, s);- rethrow;+ return (deletedIDs, e);} finally {if (deletedIDs.isNotEmpty) {- final deletedFiles = selectedFiles.files.where(- (f) => deletedIDs.contains(f.localID),- );- selectedFiles.unSelectAll(deletedFiles.toSet());Bus.instance.fire(ForceReloadTrashPageEvent());}}