Skip to content

High performance self-hosted photo and video management solution.

fix(mobile): LivePhoto video not uploaded during manual asset upload (#3732)

shalong-tanwend1e74a28d9af
diff --git a/mobile/lib/modules/backup/providers/manual_upload.provider.dart b/mobile/lib/modules/backup/providers/manual_upload.provider.dart
index 3a335a7b1f..6d585e289a 100644
--- a/mobile/lib/modules/backup/providers/manual_upload.provider.dart
+++ b/mobile/lib/modules/backup/providers/manual_upload.provider.dart
@@ -149,16 +149,30 @@ class ManualUploadNotifier extends StateNotifier<ManualUploadState> {
}
Future<bool> _startUpload(Iterable<Asset> allManualUploads) async {
+ bool hasErrors = false;
try {
_backupProvider.updateBackupProgress(BackUpProgressEnum.manualInProgress);
if (ref.read(galleryPermissionNotifier.notifier).hasPermission) {
await PhotoManager.clearFileCache();
- Set<AssetEntity> allUploadAssets = allManualUploads
- .where((e) => e.isLocal && e.local != null)
- .map((e) => e.local!)
- .toSet();
+ // We do not have 1:1 mapping of all AssetEntity fields to Asset. This results in cases
+ // where platform specific fields such as `subtype` used to detect platform specific assets such as
+ // LivePhoto in iOS is lost when we directly fetch the local asset from Asset using Asset.local
+ List<AssetEntity?> allAssetsFromDevice = await Future.wait(
+ allManualUploads
+ // Filter local only assets
+ .where((e) => e.isLocal && !e.isRemote)
+ .map((e) => e.local!.obtainForNewProperties()),
+ );
+
+ if (allAssetsFromDevice.length != allManualUploads.length) {
+ _log.warning(
+ '[_startUpload] Refreshed upload list -> ${allManualUploads.length - allAssetsFromDevice.length} asset will not be uploaded',
+ );
+ }
+
+ Set<AssetEntity> allUploadAssets = allAssetsFromDevice.nonNulls.toSet();
if (allUploadAssets.isEmpty) {
debugPrint("[_startUpload] No Assets to upload - Abort Process");
@@ -213,7 +227,7 @@ class ManualUploadNotifier extends StateNotifier<ManualUploadState> {
'[_startUpload] Manual Upload Completed - success: ${state.successfulUploads},'
' failed: ${state.totalAssetsToUpload - state.successfulUploads}',
);
- bool hasErrors = false;
+
// User cancelled upload
if (!ok && state.cancelToken.isCancelled) {
await _localNotificationService.showOrUpdateManualUploadStatus(
@@ -237,32 +251,29 @@ class ManualUploadNotifier extends StateNotifier<ManualUploadState> {
presentBanner: true,
);
}
-
- _backupProvider.updateBackupProgress(BackUpProgressEnum.idle);
- _handleAppInActivity();
- await _backupProvider.notifyBackgroundServiceCanRun();
- return !hasErrors;
} else {
openAppSettings();
debugPrint("[_startUpload] Do not have permission to the gallery");
}
} catch (e) {
debugPrint("ERROR _startUpload: ${e.toString()}");
+ hasErrors = true;
+ } finally {
+ _backupProvider.updateBackupProgress(BackUpProgressEnum.idle);
+ _handleAppInActivity();
+ await _localNotificationService.closeNotification(
+ LocalNotificationService.manualUploadDetailedNotificationID,
+ );
+ await _backupProvider.notifyBackgroundServiceCanRun();
}
- _backupProvider.updateBackupProgress(BackUpProgressEnum.idle);
- _handleAppInActivity();
- await _localNotificationService.closeNotification(
- LocalNotificationService.manualUploadDetailedNotificationID,
- );
- await _backupProvider.notifyBackgroundServiceCanRun();
- return false;
+ return !hasErrors;
}
void _handleAppInActivity() {
final appState = ref.read(appStateProvider.notifier).getAppState();
// The app is currently in background. Perform the necessary cleanups which
// are on-hold for upload completion
- if (appState != AppStateEnum.active || appState != AppStateEnum.resumed) {
+ if (appState != AppStateEnum.active && appState != AppStateEnum.resumed) {
ref.read(appStateProvider.notifier).handleAppInactivity();
}
}
diff --git a/mobile/pubspec.yaml b/mobile/pubspec.yaml
index dc90a5373c..d1790b6f3e 100644
--- a/mobile/pubspec.yaml
+++ b/mobile/pubspec.yaml
@@ -6,7 +6,7 @@ version: 1.73.0+96
isar_version: &isar_version 3.1.0+1
environment:
- sdk: ">=3.0.0-0 <4.0.0"
+ sdk: ">=3.0.0 <4.0.0"
dependencies:
flutter: