mirror of
				https://github.com/immich-app/immich.git
				synced 2025-11-04 03:27:09 -05:00 
			
		
		
		
	fix: get all assets for the Recents album on iOS (#22956)
This commit is contained in:
		
							parent
							
								
									b3055d2e94
								
							
						
					
					
						commit
						7b7d91a5e1
					
				@ -530,14 +530,10 @@
 | 
				
			|||||||
			inputFileListPaths = (
 | 
								inputFileListPaths = (
 | 
				
			||||||
				"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist",
 | 
									"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist",
 | 
				
			||||||
			);
 | 
								);
 | 
				
			||||||
			inputPaths = (
 | 
					 | 
				
			||||||
			);
 | 
					 | 
				
			||||||
			name = "[CP] Copy Pods Resources";
 | 
								name = "[CP] Copy Pods Resources";
 | 
				
			||||||
			outputFileListPaths = (
 | 
								outputFileListPaths = (
 | 
				
			||||||
				"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist",
 | 
									"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist",
 | 
				
			||||||
			);
 | 
								);
 | 
				
			||||||
			outputPaths = (
 | 
					 | 
				
			||||||
			);
 | 
					 | 
				
			||||||
			runOnlyForDeploymentPostprocessing = 0;
 | 
								runOnlyForDeploymentPostprocessing = 0;
 | 
				
			||||||
			shellPath = /bin/sh;
 | 
								shellPath = /bin/sh;
 | 
				
			||||||
			shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
 | 
								shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
 | 
				
			||||||
@ -566,14 +562,10 @@
 | 
				
			|||||||
			inputFileListPaths = (
 | 
								inputFileListPaths = (
 | 
				
			||||||
				"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
 | 
									"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
 | 
				
			||||||
			);
 | 
								);
 | 
				
			||||||
			inputPaths = (
 | 
					 | 
				
			||||||
			);
 | 
					 | 
				
			||||||
			name = "[CP] Embed Pods Frameworks";
 | 
								name = "[CP] Embed Pods Frameworks";
 | 
				
			||||||
			outputFileListPaths = (
 | 
								outputFileListPaths = (
 | 
				
			||||||
				"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
 | 
									"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
 | 
				
			||||||
			);
 | 
								);
 | 
				
			||||||
			outputPaths = (
 | 
					 | 
				
			||||||
			);
 | 
					 | 
				
			||||||
			runOnlyForDeploymentPostprocessing = 0;
 | 
								runOnlyForDeploymentPostprocessing = 0;
 | 
				
			||||||
			shellPath = /bin/sh;
 | 
								shellPath = /bin/sh;
 | 
				
			||||||
			shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
 | 
								shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
 | 
				
			||||||
 | 
				
			|||||||
@ -103,7 +103,9 @@ class NativeSyncApiImpl: ImmichPlugin, NativeSyncApi, FlutterPlugin {
 | 
				
			|||||||
        let options = PHFetchOptions()
 | 
					        let options = PHFetchOptions()
 | 
				
			||||||
        options.sortDescriptors = [NSSortDescriptor(key: "modificationDate", ascending: false)]
 | 
					        options.sortDescriptors = [NSSortDescriptor(key: "modificationDate", ascending: false)]
 | 
				
			||||||
        options.includeHiddenAssets = false
 | 
					        options.includeHiddenAssets = false
 | 
				
			||||||
        let assets = PHAsset.fetchAssets(in: album, options: options)
 | 
					        
 | 
				
			||||||
 | 
					        let assets = getAssetsFromAlbum(in: album, options: options)
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        let isCloud = album.assetCollectionSubtype == .albumCloudShared || album.assetCollectionSubtype == .albumMyPhotoStream
 | 
					        let isCloud = album.assetCollectionSubtype == .albumCloudShared || album.assetCollectionSubtype == .albumMyPhotoStream
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        var domainAlbum = PlatformAlbum(
 | 
					        var domainAlbum = PlatformAlbum(
 | 
				
			||||||
@ -201,7 +203,7 @@ class NativeSyncApiImpl: ImmichPlugin, NativeSyncApi, FlutterPlugin {
 | 
				
			|||||||
        let options = PHFetchOptions()
 | 
					        let options = PHFetchOptions()
 | 
				
			||||||
        options.predicate = NSPredicate(format: "localIdentifier IN %@", assets.map(\.id))
 | 
					        options.predicate = NSPredicate(format: "localIdentifier IN %@", assets.map(\.id))
 | 
				
			||||||
        options.includeHiddenAssets = false
 | 
					        options.includeHiddenAssets = false
 | 
				
			||||||
        let result = PHAsset.fetchAssets(in: album, options: options)
 | 
					        let result = self.getAssetsFromAlbum(in: album, options: options)
 | 
				
			||||||
        result.enumerateObjects { (asset, _, _) in
 | 
					        result.enumerateObjects { (asset, _, _) in
 | 
				
			||||||
          albumAssets[asset.localIdentifier, default: []].append(album.localIdentifier)
 | 
					          albumAssets[asset.localIdentifier, default: []].append(album.localIdentifier)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -219,7 +221,7 @@ class NativeSyncApiImpl: ImmichPlugin, NativeSyncApi, FlutterPlugin {
 | 
				
			|||||||
    var ids: [String] = []
 | 
					    var ids: [String] = []
 | 
				
			||||||
    let options = PHFetchOptions()
 | 
					    let options = PHFetchOptions()
 | 
				
			||||||
    options.includeHiddenAssets = false
 | 
					    options.includeHiddenAssets = false
 | 
				
			||||||
    let assets = PHAsset.fetchAssets(in: album, options: options)
 | 
					    let assets = getAssetsFromAlbum(in: album, options: options)
 | 
				
			||||||
    assets.enumerateObjects { (asset, _, _) in
 | 
					    assets.enumerateObjects { (asset, _, _) in
 | 
				
			||||||
      ids.append(asset.localIdentifier)
 | 
					      ids.append(asset.localIdentifier)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -236,7 +238,7 @@ class NativeSyncApiImpl: ImmichPlugin, NativeSyncApi, FlutterPlugin {
 | 
				
			|||||||
    let options = PHFetchOptions()
 | 
					    let options = PHFetchOptions()
 | 
				
			||||||
    options.predicate = NSPredicate(format: "creationDate > %@ OR modificationDate > %@", date, date)
 | 
					    options.predicate = NSPredicate(format: "creationDate > %@ OR modificationDate > %@", date, date)
 | 
				
			||||||
    options.includeHiddenAssets = false
 | 
					    options.includeHiddenAssets = false
 | 
				
			||||||
    let assets = PHAsset.fetchAssets(in: album, options: options)
 | 
					    let assets = getAssetsFromAlbum(in: album, options: options)
 | 
				
			||||||
    return Int64(assets.count)
 | 
					    return Int64(assets.count)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
@ -253,7 +255,7 @@ class NativeSyncApiImpl: ImmichPlugin, NativeSyncApi, FlutterPlugin {
 | 
				
			|||||||
      options.predicate = NSPredicate(format: "creationDate > %@ OR modificationDate > %@", date, date)
 | 
					      options.predicate = NSPredicate(format: "creationDate > %@ OR modificationDate > %@", date, date)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    let result = PHAsset.fetchAssets(in: album, options: options)
 | 
					    let result = getAssetsFromAlbum(in: album, options: options)
 | 
				
			||||||
    if(result.count == 0) {
 | 
					    if(result.count == 0) {
 | 
				
			||||||
      return []
 | 
					      return []
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -375,4 +377,13 @@ class NativeSyncApiImpl: ImmichPlugin, NativeSyncApi, FlutterPlugin {
 | 
				
			|||||||
      PHAssetResourceManager.default().cancelDataRequest(requestId)
 | 
					      PHAssetResourceManager.default().cancelDataRequest(requestId)
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  private func getAssetsFromAlbum(in album: PHAssetCollection, options: PHFetchOptions) -> PHFetchResult<PHAsset> {
 | 
				
			||||||
 | 
					    // Ensure to actually getting all assets for the Recents album
 | 
				
			||||||
 | 
					    if (album.assetCollectionSubtype == .smartAlbumUserLibrary) {
 | 
				
			||||||
 | 
					      return PHAsset.fetchAssets(with: options)
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      return PHAsset.fetchAssets(in: album, options: options)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user