Bubble collapse.

pull/1/head
Matthew Chen 7 years ago
parent 8a74e10208
commit 8d74c68f9d

@ -505,6 +505,7 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
- (nullable id)tryToLoadCellMedia:(nullable id (^)(void))loadCellMediaBlock - (nullable id)tryToLoadCellMedia:(nullable id (^)(void))loadCellMediaBlock
mediaView:(UIView *)mediaView mediaView:(UIView *)mediaView
cacheKey:(NSString *)cacheKey cacheKey:(NSString *)cacheKey
shouldSkipCache:(BOOL)shouldSkipCache
{ {
OWSAssert(self.attachmentStream); OWSAssert(self.attachmentStream);
OWSAssert(mediaView); OWSAssert(mediaView);
@ -525,7 +526,9 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
cellMedia = loadCellMediaBlock(); cellMedia = loadCellMediaBlock();
if (cellMedia) { if (cellMedia) {
DDLogVerbose(@"%@ cell media cache miss", self.logTag); DDLogVerbose(@"%@ cell media cache miss", self.logTag);
if (!shouldSkipCache) {
[cellMediaCache setObject:cellMedia forKey:cacheKey]; [cellMediaCache setObject:cellMedia forKey:cacheKey];
}
} else { } else {
DDLogError(@"%@ Failed to load cell media: %@", [self logTag], [self.attachmentStream mediaURL]); DDLogError(@"%@ Failed to load cell media: %@", [self logTag], [self.attachmentStream mediaURL]);
self.viewItem.didCellMediaFailToLoad = YES; self.viewItem.didCellMediaFailToLoad = YES;
@ -804,12 +807,17 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
if (stillImageView.image) { if (stillImageView.image) {
return; return;
} }
// Don't cache large still images.
const NSUInteger kMaxCachableSize = 1024 * 1024;
BOOL shouldSkipCache =
[OWSFileSystem fileSizeOfPath:strongSelf.attachmentStream.filePath].unsignedIntegerValue < kMaxCachableSize;
stillImageView.image = [strongSelf tryToLoadCellMedia:^{ stillImageView.image = [strongSelf tryToLoadCellMedia:^{
OWSCAssert([strongSelf.attachmentStream isImage]); OWSCAssert([strongSelf.attachmentStream isImage]);
return strongSelf.attachmentStream.image; return strongSelf.attachmentStream.image;
} }
mediaView:stillImageView mediaView:stillImageView
cacheKey:strongSelf.attachmentStream.uniqueId]; cacheKey:strongSelf.attachmentStream.uniqueId
shouldSkipCache:shouldSkipCache];
}; };
self.unloadCellContentBlock = ^{ self.unloadCellContentBlock = ^{
stillImageView.image = nil; stillImageView.image = nil;
@ -849,7 +857,8 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
return animatedImage; return animatedImage;
} }
mediaView:animatedImageView mediaView:animatedImageView
cacheKey:strongSelf.attachmentStream.uniqueId]; cacheKey:strongSelf.attachmentStream.uniqueId
shouldSkipCache:NO];
}; };
self.unloadCellContentBlock = ^{ self.unloadCellContentBlock = ^{
animatedImageView.image = nil; animatedImageView.image = nil;
@ -918,7 +927,8 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
return strongSelf.attachmentStream.image; return strongSelf.attachmentStream.image;
} }
mediaView:stillImageView mediaView:stillImageView
cacheKey:strongSelf.attachmentStream.uniqueId]; cacheKey:strongSelf.attachmentStream.uniqueId
shouldSkipCache:NO];
}; };
self.unloadCellContentBlock = ^{ self.unloadCellContentBlock = ^{
stillImageView.image = nil; stillImageView.image = nil;
@ -1071,7 +1081,7 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
CGFloat contentAspectRatio = self.mediaSize.width / self.mediaSize.height; CGFloat contentAspectRatio = self.mediaSize.width / self.mediaSize.height;
// Clamp the aspect ratio so that very thin/wide content is presented // Clamp the aspect ratio so that very thin/wide content is presented
// in a reasonable way. // in a reasonable way.
const CGFloat minAspectRatio = 0.25f; const CGFloat minAspectRatio = 0.35f;
const CGFloat maxAspectRatio = 1 / minAspectRatio; const CGFloat maxAspectRatio = 1 / minAspectRatio;
contentAspectRatio = MAX(minAspectRatio, MIN(maxAspectRatio, contentAspectRatio)); contentAspectRatio = MAX(minAspectRatio, MIN(maxAspectRatio, contentAspectRatio));

@ -86,8 +86,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
[self ensureViewState:transaction]; [self ensureViewState:transaction];
// OWSAssert(self.hasViewState);
return self; return self;
} }
@ -107,8 +105,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
[self clearCachedLayoutState]; [self clearCachedLayoutState];
[self ensureViewState:transaction]; [self ensureViewState:transaction];
// OWSAssert(self.hasViewState);
} }
- (BOOL)hasText - (BOOL)hasText

@ -60,7 +60,7 @@ NS_ASSUME_NONNULL_BEGIN
[DebugUIMessages fakeAllTextAction:thread], [DebugUIMessages fakeAllTextAction:thread],
[DebugUIMessages fakeRandomTextAction:thread], [DebugUIMessages fakeRandomTextAction:thread],
// Exemplary // Exemplary
[DebugUIMessages allExemplaryAction:thread], [DebugUIMessages allFakeAction:thread],
]) { ]) {
[items addObject:[OWSTableItem itemWithTitle:action.label [items addObject:[OWSTableItem itemWithTitle:action.label
actionBlock:^{ actionBlock:^{
@ -89,9 +89,13 @@ NS_ASSUME_NONNULL_BEGIN
// actionBlock:^{ // actionBlock:^{
// [DebugUIMessages sendSelectedMediaTypeInThread:thread]; // [DebugUIMessages sendSelectedMediaTypeInThread:thread];
// }], // }],
[OWSTableItem itemWithTitle:@"Select Action" [OWSTableItem itemWithTitle:@"Select Fake"
actionBlock:^{ actionBlock:^{
[DebugUIMessages selectExemplaryAction:thread]; [DebugUIMessages selectFakeAction:thread];
}],
[OWSTableItem itemWithTitle:@"Select Send Media"
actionBlock:^{
[DebugUIMessages selectSendMediaAction:thread];
}], }],
#pragma mark - Misc. #pragma mark - Misc.
@ -360,6 +364,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)sendAttachment:(NSString *)filePath + (void)sendAttachment:(NSString *)filePath
thread:(TSThread *)thread thread:(TSThread *)thread
label:(NSString *)label
hasCaption:(BOOL)hasCaption
success:(nullable void (^)(void))success success:(nullable void (^)(void))success
failure:(nullable void (^)(void))failure failure:(nullable void (^)(void))failure
{ {
@ -373,9 +379,18 @@ NS_ASSUME_NONNULL_BEGIN
[dataSource setSourceFilename:filename]; [dataSource setSourceFilename:filename];
SignalAttachment *attachment = SignalAttachment *attachment =
[SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType imageQuality:TSImageQualityOriginal]; [SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType imageQuality:TSImageQualityOriginal];
if (arc4random_uniform(100) > 50) {
attachment.captionText = [self randomCaptionText]; NSString *messageBody = nil;
if (hasCaption) {
// We want a message body that is "more than one line on all devices,
// using all dynamic type sizes."
NSString *sampleText = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, "
@"consectetur adipiscing elit.";
messageBody = [[label stringByAppendingString:@" "] stringByAppendingString:sampleText];
messageBody = [messageBody stringByAppendingString:@" 🔤"];
} }
attachment.captionText = messageBody;
OWSAssert(attachment); OWSAssert(attachment);
if ([attachment hasError]) { if ([attachment hasError]) {
@ -423,50 +438,72 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(thread); OWSAssert(thread);
NSArray<DebugUIMessagesAction *> *actions = @[ NSArray<DebugUIMessagesAction *> *actions = @[
[self sendJpegAction:thread], [self sendJpegAction:thread hasCaption:NO],
[self sendGifAction:thread], [self sendJpegAction:thread hasCaption:YES],
[self sendMp3Action:thread], [self sendGifAction:thread hasCaption:NO],
[self sendMp4Action:thread], [self sendGifAction:thread hasCaption:YES],
[self sendMp3Action:thread hasCaption:NO],
[self sendMp3Action:thread hasCaption:YES],
[self sendMp4Action:thread hasCaption:NO],
[self sendMp4Action:thread hasCaption:YES],
]; ];
return actions; return actions;
} }
+ (DebugUIMessagesAction *)sendJpegAction:(TSThread *)thread + (DebugUIMessagesAction *)sendJpegAction:(TSThread *)thread hasCaption:(BOOL)hasCaption
{ {
OWSAssert(thread); OWSAssert(thread);
return [self sendMediaAction:@"Send Jpeg" fakeAssetLoader:[DebugUIMessagesAssetLoader jpegInstance] thread:thread]; return [self sendMediaAction:@"Send Jpeg"
hasCaption:hasCaption
fakeAssetLoader:[DebugUIMessagesAssetLoader jpegInstance]
thread:thread];
} }
+ (DebugUIMessagesAction *)sendGifAction:(TSThread *)thread + (DebugUIMessagesAction *)sendGifAction:(TSThread *)thread hasCaption:(BOOL)hasCaption
{ {
OWSAssert(thread); OWSAssert(thread);
return [self sendMediaAction:@"Send Gif" fakeAssetLoader:[DebugUIMessagesAssetLoader gifInstance] thread:thread]; return [self sendMediaAction:@"Send Gif"
hasCaption:hasCaption
fakeAssetLoader:[DebugUIMessagesAssetLoader gifInstance]
thread:thread];
} }
+ (DebugUIMessagesAction *)sendMp3Action:(TSThread *)thread + (DebugUIMessagesAction *)sendMp3Action:(TSThread *)thread hasCaption:(BOOL)hasCaption
{ {
OWSAssert(thread); OWSAssert(thread);
return [self sendMediaAction:@"Send Mp3" fakeAssetLoader:[DebugUIMessagesAssetLoader mp3Instance] thread:thread]; return [self sendMediaAction:@"Send Mp3"
hasCaption:hasCaption
fakeAssetLoader:[DebugUIMessagesAssetLoader mp3Instance]
thread:thread];
} }
+ (DebugUIMessagesAction *)sendMp4Action:(TSThread *)thread + (DebugUIMessagesAction *)sendMp4Action:(TSThread *)thread hasCaption:(BOOL)hasCaption
{ {
OWSAssert(thread); OWSAssert(thread);
return [self sendMediaAction:@"Send Mp4" fakeAssetLoader:[DebugUIMessagesAssetLoader mp4Instance] thread:thread]; return [self sendMediaAction:@"Send Mp4"
hasCaption:hasCaption
fakeAssetLoader:[DebugUIMessagesAssetLoader mp4Instance]
thread:thread];
} }
+ (DebugUIMessagesAction *)sendMediaAction:(NSString *)label + (DebugUIMessagesAction *)sendMediaAction:(NSString *)labelParam
hasCaption:(BOOL)hasCaption
fakeAssetLoader:(DebugUIMessagesAssetLoader *)fakeAssetLoader fakeAssetLoader:(DebugUIMessagesAssetLoader *)fakeAssetLoader
thread:(TSThread *)thread thread:(TSThread *)thread
{ {
OWSAssert(label.length > 0); OWSAssert(labelParam.length > 0);
OWSAssert(fakeAssetLoader); OWSAssert(fakeAssetLoader);
OWSAssert(thread); OWSAssert(thread);
NSString *label = labelParam;
if (hasCaption) {
label = [label stringByAppendingString:@" 🔤"];
}
return [DebugUIMessagesSingleAction return [DebugUIMessagesSingleAction
actionWithLabel:label actionWithLabel:label
staggeredActionBlock:^(NSUInteger index, staggeredActionBlock:^(NSUInteger index,
@ -475,7 +512,12 @@ NS_ASSUME_NONNULL_BEGIN
ActionFailureBlock failure) { ActionFailureBlock failure) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
OWSAssert(fakeAssetLoader.filePath.length > 0); OWSAssert(fakeAssetLoader.filePath.length > 0);
[self sendAttachment:fakeAssetLoader.filePath thread:thread success:success failure:failure]; [self sendAttachment:fakeAssetLoader.filePath
thread:thread
label:label
hasCaption:hasCaption
success:success
failure:failure];
}); });
} }
prepareBlock:fakeAssetLoader.prepareBlock]; prepareBlock:fakeAssetLoader.prepareBlock];
@ -485,7 +527,7 @@ NS_ASSUME_NONNULL_BEGIN
{ {
OWSAssert(thread); OWSAssert(thread);
return [DebugUIMessagesGroupAction allGroupActionWithLabel:@"Send All Media" return [DebugUIMessagesGroupAction allGroupActionWithLabel:@"All Send Media"
subactions:[self allSendMediaActions:thread]]; subactions:[self allSendMediaActions:thread]];
} }
@ -493,10 +535,17 @@ NS_ASSUME_NONNULL_BEGIN
{ {
OWSAssert(thread); OWSAssert(thread);
return [DebugUIMessagesGroupAction randomGroupActionWithLabel:@"Send Random Media" return [DebugUIMessagesGroupAction randomGroupActionWithLabel:@"Random Send Media"
subactions:[self allSendMediaActions:thread]]; subactions:[self allSendMediaActions:thread]];
} }
+ (void)selectSendMediaAction:(TSThread *)thread
{
OWSAssert(thread);
[self selectActionUI:[self allSendMediaActions:thread] label:@"Select Send Media"];
}
#pragma mark - Fake Outgoing Media #pragma mark - Fake Outgoing Media
+ (DebugUIMessagesAction *)fakeOutgoingJpegAction:(TSThread *)thread + (DebugUIMessagesAction *)fakeOutgoingJpegAction:(TSThread *)thread
@ -1669,7 +1718,7 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Exemplary #pragma mark - Exemplary
+ (NSArray<DebugUIMessagesAction *> *)allExemplaryActions:(TSThread *)thread includeLabels:(BOOL)includeLabels + (NSArray<DebugUIMessagesAction *> *)allFakeActions:(TSThread *)thread includeLabels:(BOOL)includeLabels
{ {
OWSAssert(thread); OWSAssert(thread);
@ -1679,21 +1728,28 @@ NS_ASSUME_NONNULL_BEGIN
return actions; return actions;
} }
+ (DebugUIMessagesAction *)allExemplaryAction:(TSThread *)thread + (DebugUIMessagesAction *)allFakeAction:(TSThread *)thread
{ {
OWSAssert(thread); OWSAssert(thread);
return [DebugUIMessagesGroupAction allGroupActionWithLabel:@"Exemplary Permutations" return [DebugUIMessagesGroupAction allGroupActionWithLabel:@"All Fake"
subactions:[self allExemplaryActions:thread includeLabels:YES]]; subactions:[self allFakeActions:thread includeLabels:YES]];
} }
+ (void)selectExemplaryAction:(TSThread *)thread + (void)selectFakeAction:(TSThread *)thread
{ {
OWSAssertIsOnMainThread() OWSAssert(thread); OWSAssertIsOnMainThread();
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Select Action" OWSAssert(thread);
message:nil
preferredStyle:UIAlertControllerStyleActionSheet]; [self selectActionUI:[self allFakeActions:thread includeLabels:NO] label:@"Select Fake"];
for (DebugUIMessagesAction *action in [self allExemplaryActions:thread includeLabels:NO]) { }
+ (void)selectActionUI:(NSArray<DebugUIMessagesAction *> *)actions label:(NSString *)label
{
OWSAssertIsOnMainThread();
UIAlertController *alert =
[UIAlertController alertControllerWithTitle:label message:nil preferredStyle:UIAlertControllerStyleActionSheet];
for (DebugUIMessagesAction *action in actions) {
[alert addAction:[UIAlertAction actionWithTitle:action.label [alert addAction:[UIAlertAction actionWithTitle:action.label
style:UIAlertActionStyleDefault style:UIAlertActionStyleDefault
handler:^(UIAlertAction *ignore) { handler:^(UIAlertAction *ignore) {

@ -349,7 +349,7 @@ NS_ASSUME_NONNULL_BEGIN
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
instance = [DebugUIMessagesAssetLoader instance = [DebugUIMessagesAssetLoader
fakeAssetLoaderWithUrl:@"https://s3.amazonaws.com/ows-data/example_attachment_media/random-mp3.mp3" fakeAssetLoaderWithUrl:@"https://s3.amazonaws.com/ows-data/example_attachment_media/random-mp3.mp3"
mimeType:@"audio/mpeg"]; mimeType:@"audio/mp3"];
}); });
return instance; return instance;
} }

@ -572,21 +572,21 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();
OWSAssert([self isAudio]); OWSAssert([self isAudio]);
return 0;
// NSError *error;
// AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:self.mediaURL error:&error];
// if (error && [error.domain isEqualToString:NSOSStatusErrorDomain]
// && (error.code == kAudioFileInvalidFileError || error.code == kAudioFileStreamError_InvalidFile)) {
// // Ignore "invalid audio file" errors.
// return 0.f;
// }
// if (!error) {
// return (CGFloat)[audioPlayer duration];
// } else {
// OWSFail(@"Could not find audio duration: %@", self.mediaURL);
// return 0; // return 0;
// }
NSError *error;
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:self.mediaURL error:&error];
if (error && [error.domain isEqualToString:NSOSStatusErrorDomain]
&& (error.code == kAudioFileInvalidFileError || error.code == kAudioFileStreamError_InvalidFile)) {
// Ignore "invalid audio file" errors.
return 0.f;
}
if (!error) {
return (CGFloat)[audioPlayer duration];
} else {
OWSFail(@"Could not find audio duration: %@", self.mediaURL);
return 0;
}
} }
- (CGFloat)audioDurationSeconds - (CGFloat)audioDurationSeconds

Loading…
Cancel
Save