Merge branch 'charlesmchen/messageViewPerf2'

pull/1/head
Matthew Chen 8 years ago
commit 497d15d8a8

@ -136,7 +136,7 @@ CHECKOUT OPTIONS:
:commit: 7054e4b13ee5bcd6d524adb6dc9a726e8c466308 :commit: 7054e4b13ee5bcd6d524adb6dc9a726e8c466308
:git: https://github.com/WhisperSystems/JSQMessagesViewController.git :git: https://github.com/WhisperSystems/JSQMessagesViewController.git
SignalServiceKit: SignalServiceKit:
:commit: d61235825680e9b563f28cbbbaf6772c19f85674 :commit: 289fd4f0cc918055cdecb34710a101b087d646d0
:git: https://github.com/WhisperSystems/SignalServiceKit.git :git: https://github.com/WhisperSystems/SignalServiceKit.git
SocketRocket: SocketRocket:
:commit: 877ac7438be3ad0b45ef5ca3969574e4b97112bf :commit: 877ac7438be3ad0b45ef5ca3969574e4b97112bf

@ -41,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
_attachment = attachment; _attachment = attachment;
_attachmentId = attachment.uniqueId; _attachmentId = attachment.uniqueId;
_incoming = incoming; _incoming = incoming;
_imageSize = attachment.mediaURL ? [self sizeOfImageAtURL:attachment.mediaURL] : CGSizeZero; _imageSize = [attachment cachedImageSizeWithoutTransaction];
} }
return self; return self;

@ -266,6 +266,11 @@ NS_ASSUME_NONNULL_BEGIN
NSString *utiType = [MIMETypeUtil utiTypeForMIMEType:self.attachment.contentType]; NSString *utiType = [MIMETypeUtil utiTypeForMIMEType:self.attachment.contentType];
OWSAssert(utiType.length > 0); OWSAssert(utiType.length > 0);
NSData *data = [NSData dataWithContentsOfURL:self.attachment.mediaURL]; NSData *data = [NSData dataWithContentsOfURL:self.attachment.mediaURL];
if (!data) {
OWSAssert(data);
DDLogError(@"%@ Could not load data: %@", [self tag], [self.attachment mediaURL]);
return;
}
[UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType]; [UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType];
} else { } else {
// Shouldn't get here, as only supported actions should be exposed via canPerformEditingAction // Shouldn't get here, as only supported actions should be exposed via canPerformEditingAction
@ -290,6 +295,18 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -57,8 +57,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) uint64_t expiresAtSeconds; @property (nonatomic) uint64_t expiresAtSeconds;
@property (nonatomic) uint32_t expiresInSeconds; @property (nonatomic) uint32_t expiresInSeconds;
@property (nonatomic, copy) NSDate *messageDate; @property (nonatomic) NSDate *messageDate;
@property (nonatomic, retain) NSString *messageBody; @property (nonatomic) NSString *messageBody;
@property (nonatomic) NSString *interactionUniqueId; @property (nonatomic) NSString *interactionUniqueId;

@ -41,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
_attachment = attachment; _attachment = attachment;
_attachmentId = attachment.uniqueId; _attachmentId = attachment.uniqueId;
_incoming = incoming; _incoming = incoming;
_imageSize = attachment.mediaURL ? [self sizeOfImageAtURL:attachment.mediaURL] : CGSizeZero; _imageSize = [attachment cachedImageSizeWithoutTransaction];
return self; return self;
} }

@ -24,7 +24,6 @@ NS_ASSUME_NONNULL_BEGIN
@interface TSVideoAttachmentAdapter () @interface TSVideoAttachmentAdapter ()
@property (nonatomic) UIImage *image;
@property (nonatomic, nullable) UIView *cachedMediaView; @property (nonatomic, nullable) UIView *cachedMediaView;
@property (nonatomic) TSAttachmentStream *attachment; @property (nonatomic) TSAttachmentStream *attachment;
@property (nonatomic, nullable) UIButton *audioPlayPauseButton; @property (nonatomic, nullable) UIButton *audioPlayPauseButton;
@ -36,6 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) CGFloat audioProgressSeconds; @property (nonatomic) CGFloat audioProgressSeconds;
@property (nonatomic) CGFloat audioDurationSeconds; @property (nonatomic) CGFloat audioDurationSeconds;
@property (nonatomic) BOOL isPaused; @property (nonatomic) BOOL isPaused;
@property (nonatomic) CGSize imageSize;
// See comments on OWSMessageMediaAdapter. // See comments on OWSMessageMediaAdapter.
@property (nonatomic, nullable, weak) id lastPresentingCell; @property (nonatomic, nullable, weak) id lastPresentingCell;
@ -50,12 +50,12 @@ NS_ASSUME_NONNULL_BEGIN
self = [super initWithFileURL:[attachment mediaURL] isReadyToPlay:YES]; self = [super initWithFileURL:[attachment mediaURL] isReadyToPlay:YES];
if (self) { if (self) {
_image = attachment.image;
_cachedMediaView = nil; _cachedMediaView = nil;
_attachmentId = attachment.uniqueId; _attachmentId = attachment.uniqueId;
_contentType = attachment.contentType; _contentType = attachment.contentType;
_attachment = attachment; _attachment = attachment;
_incoming = incoming; _incoming = incoming;
_imageSize = [attachment cachedImageSizeWithoutTransaction];
} }
return self; return self;
} }
@ -224,7 +224,13 @@ NS_ASSUME_NONNULL_BEGIN
CGSize size = [self mediaViewDisplaySize]; CGSize size = [self mediaViewDisplaySize];
UIImageView *imageView = [[UIImageView alloc] initWithImage:self.image]; UIImage *image = self.attachment.image;
if (!image) {
DDLogError(@"%@ Could not load image: %@", [self tag], [self.attachment mediaURL]);
OWSAssert(0);
return nil;
}
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.contentMode = UIViewContentModeScaleAspectFill; imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.frame = CGRectMake(0.0f, 0.0f, size.width, size.height); imageView.frame = CGRectMake(0.0f, 0.0f, size.width, size.height);
imageView.clipsToBounds = YES; imageView.clipsToBounds = YES;
@ -261,7 +267,7 @@ NS_ASSUME_NONNULL_BEGIN
{ {
OWSAssert([self isAudio]); OWSAssert([self isAudio]);
[self ensureAudioDurationSeconds]; self.audioDurationSeconds = [self.attachment cachedAudioDurationSecondsWithoutTransaction];
CGSize viewSize = [self mediaViewDisplaySize]; CGSize viewSize = [self mediaViewDisplaySize];
UIColor *textColor = [self audioTextColor]; UIColor *textColor = [self audioTextColor];
@ -351,30 +357,13 @@ NS_ASSUME_NONNULL_BEGIN
return mediaView; return mediaView;
} }
- (void)ensureAudioDurationSeconds
{
if (self.audioDurationSeconds == 0.f) {
NSError *error;
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:self.fileURL error:&error];
if (error && [error.domain isEqualToString:NSOSStatusErrorDomain]
&& (error.code == kAudioFileInvalidFileError || error.code == kAudioFileStreamError_InvalidFile)) {
// Ignore "invalid audio file" errors.
return;
}
OWSAssert(!error);
if (!error) {
self.audioDurationSeconds = (CGFloat)[audioPlayer duration];
}
}
}
- (CGSize)mediaViewDisplaySize { - (CGSize)mediaViewDisplaySize {
CGSize size = [super mediaViewDisplaySize]; CGSize size = [super mediaViewDisplaySize];
if ([self isAudio]) { if ([self isAudio]) {
size.width = [self ows_maxMediaBubbleWidth:size]; size.width = [self ows_maxMediaBubbleWidth:size];
size.height = (CGFloat)ceil(self.audioBubbleHeight); size.height = (CGFloat)ceil(self.audioBubbleHeight);
} else if ([self isVideo]) { } else if ([self isVideo]) {
return [self ows_adjustBubbleSize:size forImage:self.image]; return [self ows_adjustBubbleSize:size forImageSize:self.imageSize];
} }
return size; return size;
} }
@ -413,6 +402,11 @@ NS_ASSUME_NONNULL_BEGIN
utiType = (NSString *)kUTTypeVideo; utiType = (NSString *)kUTTypeVideo;
} }
NSData *data = [NSData dataWithContentsOfURL:self.fileURL]; NSData *data = [NSData dataWithContentsOfURL:self.fileURL];
if (!data) {
OWSAssert(data);
DDLogError(@"%@ Could not load data: %@", [self tag], [self.attachment mediaURL]);
return;
}
[UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType]; [UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType];
return; return;
} else if (action == NSSelectorFromString(@"save:")) { } else if (action == NSSelectorFromString(@"save:")) {
@ -431,7 +425,11 @@ NS_ASSUME_NONNULL_BEGIN
} }
NSData *data = [NSData dataWithContentsOfURL:self.fileURL]; NSData *data = [NSData dataWithContentsOfURL:self.fileURL];
OWSAssert(data); if (!data) {
OWSAssert(data);
DDLogError(@"%@ Could not load data: %@", [self tag], [self.attachment mediaURL]);
return;
}
[UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType]; [UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType];
} }
} else { } else {
@ -459,6 +457,18 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -758,11 +758,11 @@ typedef enum : NSUInteger {
[[YapDatabaseViewMappings alloc] initWithGroups:@[ thread.uniqueId ] view:TSMessageDatabaseViewExtensionName]; [[YapDatabaseViewMappings alloc] initWithGroups:@[ thread.uniqueId ] view:TSMessageDatabaseViewExtensionName];
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[self.messageMappings updateWithTransaction:transaction]; [self.messageMappings updateWithTransaction:transaction];
self.page = 0;
[self updateRangeOptionsForPage:self.page];
[self.collectionView reloadData];
}]; }];
self.page = 0;
[self updateRangeOptionsForPage:self.page];
[self updateLoadEarlierVisible]; [self updateLoadEarlierVisible];
[self.collectionView reloadData];
} }
- (BOOL)userLeftGroup - (BOOL)userLeftGroup

Loading…
Cancel
Save