π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Handle stale local IDs in download skip flow
ashilkn3da0850c6539
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 95efc97165..9e1abf5db8 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@@ -1103,12 +1103,35 @@ class _FileSelectionActionsWidgetStatereturn;}- final remoteFiles = files.where((file) => file.isRemoteFile).toList();- final skippedFiles = files.where((file) => !file.isRemoteFile).toList();+ final l10n = AppLocalizations.of(context);+ final existingLocalFolderNames = await Future.wait(+ files.map(+ (file) => getExistingLocalFolderNameForDownloadSkipToast(+ file,+ fallbackFolderName: l10n.gallery,+ ),+ ),+ );++ final filesToDownload = <EnteFile>[];+ final skippedFiles = <EnteFile>[];+ String? skippedSingleFolderName;+ for (int i = 0; i < files.length; i++) {+ final file = files[i];+ final existingLocalFolderName = existingLocalFolderNames[i];+ if (existingLocalFolderName != null) {+ skippedFiles.add(file);+ skippedSingleFolderName = existingLocalFolderName;+ continue;+ }+ filesToDownload.add(+ file.isRemoteFile ? file.copyWith() : file.copyWith(localID: null),+ );+ }final skippedFilesCount = skippedFiles.length;- if (remoteFiles.isNotEmpty) {- final totalFiles = remoteFiles.length;+ if (filesToDownload.isNotEmpty) {+ final totalFiles = filesToDownload.length;int downloadedFiles = 0;final dialog = createProgressDialog(@@ -1121,12 +1144,10 @@ class _FileSelectionActionsWidgetStatetry {final taskQueue = SimpleTaskQueue(maxConcurrent: 5);final futures = <Future>[];- for (final file in remoteFiles) {+ for (final file in filesToDownload) {futures.add(taskQueue.add(() async {- // Avoid mutating selected file instances since `localID` is part- // of EnteFile hashCode and selection is maintained in a Set.- await downloadToGallery(file.copyWith());+ await downloadToGallery(file);downloadedFiles++;dialog.update(message: AppLocalizations.of(context).downloading +@@ -1147,19 +1168,14 @@ class _FileSelectionActionsWidgetStateString finalMessage;if (skippedFilesCount > 0) {- final l10n = AppLocalizations.of(context);if (skippedFilesCount == 1) {final skippedFile = skippedFiles.first;- final folderName = await getLocalFolderNameForDownloadSkipToast(- skippedFile,- fallbackFolderName: l10n.gallery,- );finalMessage = l10n.downloadSkippedInSelectionSingleFile(fileName: getDownloadSkipToastFileName(skippedFile,fallbackFileName: l10n.file,),- albumName: folderName,+ albumName: skippedSingleFolderName ?? l10n.gallery,);} else {finalMessage = l10n.downloadSkippedInSelectionMultipleFiles(diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dartindex 8c30ce2272..7689e4433e 100644--- a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart@@ -619,11 +619,12 @@ class FileAppBarState extends State<FileAppBar> {}Future<void> _download(EnteFile file) async {- if (!file.isRemoteFile) {- final folderName = await getLocalFolderNameForDownloadSkipToast(- file,- fallbackFolderName: AppLocalizations.of(context).gallery,- );+ final existingFolderName =+ await getExistingLocalFolderNameForDownloadSkipToast(+ file,+ fallbackFolderName: AppLocalizations.of(context).gallery,+ );+ if (existingFolderName != null) {if (mounted) {final l10n = AppLocalizations.of(context);showToast(@@ -633,7 +634,7 @@ class FileAppBarState extends State<FileAppBar> {file,fallbackFileName: l10n.file,),- albumName: folderName,+ albumName: existingFolderName,),iosLongToastLengthInSec: 4,);@@ -641,6 +642,8 @@ class FileAppBarState extends State<FileAppBar> {return;}+ final fileToDownload =+ !file.isRemoteFile ? file.copyWith(localID: null) : file;final dialog = createProgressDialog(context,context.l10n.downloading,@@ -648,7 +651,7 @@ class FileAppBarState extends State<FileAppBar> {);await dialog.show();try {- await downloadToGallery(file);+ await downloadToGallery(fileToDownload);showToast(context, AppLocalizations.of(context).fileSavedToGallery);await dialog.hide();} catch (e) {diff --git a/mobile/apps/photos/lib/utils/download_skip_toast_util.dart b/mobile/apps/photos/lib/utils/download_skip_toast_util.dartindex a513f5efa4..5111494356 100644--- a/mobile/apps/photos/lib/utils/download_skip_toast_util.dart+++ b/mobile/apps/photos/lib/utils/download_skip_toast_util.dart@@ -13,24 +13,22 @@ String getDownloadSkipToastFileName(: fallbackFileName;}-Future<String> getLocalFolderNameForDownloadSkipToast(+Future<String?> getExistingLocalFolderNameForDownloadSkipToast(EnteFile file, {required String fallbackFolderName,}) async {- final String deviceFolder = (file.deviceFolder ?? "").trim();- if (deviceFolder.isNotEmpty) {- return _getLastPathSegment(deviceFolder);+ if (file.localID == null) {+ return null;}-final asset = await file.getAsset;- if (asset != null && await asset.exists) {- final String relativePath =- (asset.relativePath ?? "").trim().replaceFirst(RegExp(r'[/\\]+$'), '');- if (relativePath.isNotEmpty) {- return _getLastPathSegment(relativePath);- }+ if (asset == null || !(await asset.exists)) {+ return null;+ }+ final String relativePath =+ (asset.relativePath ?? "").trim().replaceFirst(RegExp(r'[/\\]+$'), '');+ if (relativePath.isNotEmpty) {+ return _getLastPathSegment(relativePath);}-return fallbackFolderName;}