diff --git a/Signal/src/ViewControllers/PhotoLibrary/PhotoLibrary.swift b/Signal/src/ViewControllers/PhotoLibrary/PhotoLibrary.swift index 0a2d13729..077934954 100644 --- a/Signal/src/ViewControllers/PhotoLibrary/PhotoLibrary.swift +++ b/Signal/src/ViewControllers/PhotoLibrary/PhotoLibrary.swift @@ -291,7 +291,9 @@ class PhotoLibrary: NSObject, PHPhotoLibraryChangeObserver { var collections = [PhotoCollection]() var collectionIds = Set() - let processPHCollection: (PHCollection) -> Void = { (collection) in + let processPHCollection: ((collection: PHCollection, hideIfEmpty: Bool)) -> Void = { arg in + let (collection, hideIfEmpty) = arg + // De-duplicate by id. let collectionId = collection.localIdentifier guard !collectionIds.contains(collectionId) else { @@ -304,15 +306,14 @@ class PhotoLibrary: NSObject, PHPhotoLibraryChangeObserver { return } let photoCollection = PhotoCollection(collection: assetCollection) - // Hide empty collections. - guard photoCollection.contents().assetCount > 0 else { + guard !hideIfEmpty || photoCollection.contents().assetCount > 0 else { return } collections.append(photoCollection) } - let processPHAssetCollections: (PHFetchResult) -> Void = { (fetchResult) in - // undocumented constant + let processPHAssetCollections: ((fetchResult: PHFetchResult, hideIfEmpty: Bool)) -> Void = { arg in + let (fetchResult, hideIfEmpty) = arg fetchResult.enumerateObjects { (assetCollection, _, _) in // We're already sorting albums by last-updated. "Recently Added" is mostly redundant @@ -320,33 +321,40 @@ class PhotoLibrary: NSObject, PHPhotoLibraryChangeObserver { return } + // undocumented constant let kRecentlyDeletedAlbumSubtype = PHAssetCollectionSubtype(rawValue: 1000000201) guard assetCollection.assetCollectionSubtype != kRecentlyDeletedAlbumSubtype else { return } - processPHCollection(assetCollection) + processPHCollection((collection: assetCollection, hideIfEmpty: hideIfEmpty)) } } - let processPHCollections: (PHFetchResult) -> Void = { (fetchResult) in + let processPHCollections: ((fetchResult: PHFetchResult, hideIfEmpty: Bool)) -> Void = { arg in + let (fetchResult, hideIfEmpty) = arg + for index in 0..