From db2294888797c6391cbd52a35f1dcc01e3727cb0 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 12 Feb 2019 15:06:15 -0700 Subject: [PATCH 1/2] Fix crash after deleting message w/ link preview --- Signal/src/views/LinkPreviewView.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Signal/src/views/LinkPreviewView.swift b/Signal/src/views/LinkPreviewView.swift index 9360513af..d61ed8135 100644 --- a/Signal/src/views/LinkPreviewView.swift +++ b/Signal/src/views/LinkPreviewView.swift @@ -211,7 +211,8 @@ public class LinkPreviewSent: NSObject, LinkPreviewState { return nil } guard let image = UIImage(contentsOfFile: imageFilepath) else { - owsFail("Could not load image: \(imageFilepath)") + owsFailDebug("Could not load image: \(imageFilepath)") + return nil } return image } From 38da911d4f32555910da0bee9c86dc5fca212acc Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 12 Feb 2019 15:28:55 -0700 Subject: [PATCH 2/2] Don't crash when user has 0 saved photos --- .../PhotoLibrary/PhotoLibrary.swift | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) 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..