Merge branch 'mkirk/gallery-review'

pull/1/head
Michael Kirk 7 years ago
commit 0e70515223

@ -10,6 +10,7 @@
#import <AxolotlKit/PreKeyBundle.h>
#import <Curve25519Kit/Randomness.h>
#import <SignalMessaging/Environment.h>
#import <SignalServiceKit/NSDate+OWS.h>
#import <SignalServiceKit/OWSBatchMessageProcessor.h>
#import <SignalServiceKit/OWSDisappearingConfigurationUpdateInfoMessage.h>
#import <SignalServiceKit/OWSDisappearingMessagesConfiguration.h>
@ -1200,7 +1201,7 @@ NS_ASSUME_NONNULL_BEGIN
for (NSUInteger i = 0; i < counter; i++) {
// Random time within last n years. Helpful for filling out a media gallery over time.
double yearsMillis = 4.0 * 365.0 * 24.0 * 60.0 * 60.0 * 1000.0;
double yearsMillis = 4.0 * kYearsInMillis;
uint64_t millisAgo = (uint64_t)(((double)arc4random() / ((double)0xffffffff)) * yearsMillis);
uint64_t timestamp = [NSDate ows_millisecondTimeStamp] - millisAgo;

@ -155,7 +155,7 @@ public class MediaTileViewController: UICollectionViewController, MediaGalleryCe
return 0
}
if sectionIdx == kLoadNewerSectionIdx {
if sectionIdx == loadNewerSectionIdx {
// load more recent
return 0
}
@ -187,7 +187,7 @@ public class MediaTileViewController: UICollectionViewController, MediaGalleryCe
let title = NSLocalizedString("GALLERY_TILES_LOADING_OLDER_LABEL", comment: "Label indicating loading is in progress")
sectionHeader.configure(title: title)
return sectionHeader
case kLoadNewerSectionIdx:
case loadNewerSectionIdx:
guard let sectionHeader = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: MediaGalleryLoadingHeader.reuseIdentifier, for: indexPath) as? MediaGalleryLoadingHeader else {
owsFail("\(logTag) in \(#function) unable to build section header for kLoadOlderSectionIdx")
@ -223,8 +223,8 @@ public class MediaTileViewController: UICollectionViewController, MediaGalleryCe
case kLoadOlderSectionIdx:
owsFail("\(logTag) in \(#function) unexpected cell for kLoadOlderSectionIdx")
return defaultCell
case kLoadNewerSectionIdx:
owsFail("\(logTag) in \(#function) unexpected cell for kLoadNewerSectionIdx")
case loadNewerSectionIdx:
owsFail("\(logTag) in \(#function) unexpected cell for loadNewerSectionIdx")
return defaultCell
default:
guard let sectionDate = self.galleryDates[safe: indexPath.section - 1] else {
@ -269,7 +269,7 @@ public class MediaTileViewController: UICollectionViewController, MediaGalleryCe
return CGSize.zero
}
return mediaGalleryDataSource.hasFetchedOldest ? CGSize.zero : CGSize(width: 0, height: 100)
case kLoadNewerSectionIdx:
case loadNewerSectionIdx:
// Show "loading newer..." iff there is still more recent data to be fetched
guard let mediaGalleryDataSource = self.mediaGalleryDataSource else {
owsFail("\(logTag) in \(#function) mediaGalleryDataSource was unexpectedly nil")
@ -311,7 +311,7 @@ public class MediaTileViewController: UICollectionViewController, MediaGalleryCe
var isFetchingMoreData: Bool = false
let kLoadOlderSectionIdx = 0
var kLoadNewerSectionIdx: Int {
var loadNewerSectionIdx: Int {
return galleryDates.count + 1
}

@ -243,7 +243,7 @@ NS_ASSUME_NONNULL_BEGIN
NSString *filename = filePath.lastPathComponent.stringByDeletingPathExtension;
NSString *containingDir = filePath.stringByDeletingLastPathComponent;
NSString *newFilename = [filename stringByAppendingString:@"-thumbnail"];
NSString *newFilename = [filename stringByAppendingString:@"-signal-ios-thumbnail"];
return [[containingDir stringByAppendingPathComponent:newFilename] stringByAppendingPathExtension:@"jpg"];
}
@ -260,12 +260,22 @@ NS_ASSUME_NONNULL_BEGIN
- (void)removeFileWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
NSError *error;
NSString *_Nullable thumbnailPath = self.thumbnailPath;
if (thumbnailPath) {
[[NSFileManager defaultManager] removeItemAtPath:thumbnailPath error:&error];
if (error) {
DDLogError(@"%@ remove thumbnail errored with: %@", self.logTag, error);
}
}
NSString *_Nullable filePath = self.filePath;
if (!filePath) {
OWSFail(@"%@ Missing path for attachment.", self.logTag);
return;
}
NSError *error;
[[NSFileManager defaultManager] removeItemAtPath:filePath error:&error];
if (error) {
@ -345,7 +355,8 @@ NS_ASSUME_NONNULL_BEGIN
}
if (![[NSFileManager defaultManager] fileExistsAtPath:self.mediaURL.path]) {
OWSFail(@"%@ while generating thumbnail, source file doesn't exist: %@", self.logTag, self.mediaURL) return;
OWSFail(@"%@ while generating thumbnail, source file doesn't exist: %@", self.logTag, self.mediaURL);
return;
}
// TODO proper resolution?
@ -353,6 +364,11 @@ NS_ASSUME_NONNULL_BEGIN
UIImage *_Nullable result;
if (self.isImage || self.isAnimated) {
if (![NSData ows_isValidImageAtPath:self.filePath]) {
DDLogWarn(@"%@ skipping thumbnail generation for invalid image at path: %@", self.logTag, self.filePath);
return;
}
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((__bridge CFURLRef)self.mediaURL, NULL);
OWSAssert(imageSource != NULL) NSDictionary *imageOptions = @{
(NSString const *)kCGImageSourceCreateThumbnailFromImageIfAbsent : (NSNumber const *)kCFBooleanTrue,

@ -17,6 +17,7 @@ extern const NSTimeInterval kMonthInterval;
#define kDayInMs (kHourInMs * 24)
#define kWeekInMs (kDayInMs * 7)
#define kMonthInMs (kDayInMs * 30)
#define kYearsInMs (kDayInMs * 365)
@interface NSDate (OWS)

Loading…
Cancel
Save