Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent b3d17ea192
commit d8ae5841d6

@ -62,9 +62,9 @@ NS_ASSUME_NONNULL_BEGIN
- (CGFloat)audioDurationSeconds - (CGFloat)audioDurationSeconds
{ {
OWSAssert(self.viewItem.audioDurationSeconds); OWSAssert(self.viewItem.audioDurationSeconds > 0.f);
return [self.viewItem.audioDurationSeconds floatValue]; return self.viewItem.audioDurationSeconds;
} }
- (AudioPlaybackState)audioPlaybackState - (AudioPlaybackState)audioPlaybackState

@ -72,7 +72,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);
@property (nonatomic, weak) OWSAudioMessageView *lastAudioMessageView; @property (nonatomic, weak) OWSAudioMessageView *lastAudioMessageView;
@property (nonatomic, readonly, nullable) NSNumber *audioDurationSeconds; @property (nonatomic, readonly) CGFloat audioDurationSeconds;
- (CGFloat)audioProgressSeconds; - (CGFloat)audioProgressSeconds;

@ -47,7 +47,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
@property (nonatomic) AudioPlaybackState audioPlaybackState; @property (nonatomic) AudioPlaybackState audioPlaybackState;
@property (nonatomic) CGFloat audioProgressSeconds; @property (nonatomic) CGFloat audioProgressSeconds;
@property (nonatomic, nullable) NSNumber *audioDurationSeconds; @property (nonatomic) CGFloat audioDurationSeconds;
#pragma mark - View State #pragma mark - View State
@ -396,7 +396,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
} else if ([self.attachmentStream isAudio]) { } else if ([self.attachmentStream isAudio]) {
CGFloat audioDurationSeconds = [self.attachmentStream audioDurationSeconds]; CGFloat audioDurationSeconds = [self.attachmentStream audioDurationSeconds];
if (audioDurationSeconds > 0) { if (audioDurationSeconds > 0) {
self.audioDurationSeconds = @(audioDurationSeconds); self.audioDurationSeconds = audioDurationSeconds;
self.messageCellType = OWSMessageCellType_Audio; self.messageCellType = OWSMessageCellType_Audio;
} else { } else {
self.messageCellType = OWSMessageCellType_GenericAttachment; self.messageCellType = OWSMessageCellType_GenericAttachment;

@ -408,23 +408,21 @@ NS_ASSUME_NONNULL_BEGIN
self.cachedImageWidth = @(imageSize.width); self.cachedImageWidth = @(imageSize.width);
self.cachedImageHeight = @(imageSize.height); self.cachedImageHeight = @(imageSize.height);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self.dbReadWriteConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
NSString *collection = [[self class] collection];
NSString *collection = [[self class] collection]; TSAttachmentStream *latestInstance = [transaction objectForKey:self.uniqueId inCollection:collection];
TSAttachmentStream *latestInstance = [transaction objectForKey:self.uniqueId inCollection:collection]; if (latestInstance) {
if (latestInstance) { latestInstance.cachedImageWidth = @(imageSize.width);
latestInstance.cachedImageWidth = @(imageSize.width); latestInstance.cachedImageHeight = @(imageSize.height);
latestInstance.cachedImageHeight = @(imageSize.height); [latestInstance saveWithTransaction:transaction];
[latestInstance saveWithTransaction:transaction]; } else {
} else { // This message has not yet been saved or has been deleted; do nothing.
// This message has not yet been saved or has been deleted; do nothing. // This isn't an error per se, but these race conditions should be
// This isn't an error per se, but these race conditions should be // _very_ rare.
// _very_ rare. OWSFail(@"%@ Attachment not yet saved.", self.logTag);
OWSFail(@"%@ Attachment not yet saved.", self.logTag); }
} }];
}];
});
return imageSize; return imageSize;
} }
@ -460,21 +458,19 @@ NS_ASSUME_NONNULL_BEGIN
CGFloat audioDurationSeconds = [self calculateAudioDurationSeconds]; CGFloat audioDurationSeconds = [self calculateAudioDurationSeconds];
self.cachedAudioDurationSeconds = @(audioDurationSeconds); self.cachedAudioDurationSeconds = @(audioDurationSeconds);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self.dbReadWriteConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { NSString *collection = [[self class] collection];
NSString *collection = [[self class] collection]; TSAttachmentStream *latestInstance = [transaction objectForKey:self.uniqueId inCollection:collection];
TSAttachmentStream *latestInstance = [transaction objectForKey:self.uniqueId inCollection:collection]; if (latestInstance) {
if (latestInstance) { latestInstance.cachedAudioDurationSeconds = @(audioDurationSeconds);
latestInstance.cachedAudioDurationSeconds = @(audioDurationSeconds); [latestInstance saveWithTransaction:transaction];
[latestInstance saveWithTransaction:transaction]; } else {
} else { // This message has not yet been saved or has been deleted; do nothing.
// This message has not yet been saved or has been deleted; do nothing. // This isn't an error per se, but these race conditions should be
// This isn't an error per se, but these race conditions should be // _very_ rare.
// _very_ rare. OWSFail(@"%@ Attachment not yet saved.", self.logTag);
OWSFail(@"%@ Attachment not yet saved.", self.logTag); }
} }];
}];
});
return audioDurationSeconds; return audioDurationSeconds;
} }

Loading…
Cancel
Save