diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.m index 076bfcda5..22e749602 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.m @@ -62,9 +62,9 @@ NS_ASSUME_NONNULL_BEGIN - (CGFloat)audioDurationSeconds { - OWSAssert(self.viewItem.audioDurationSeconds); + OWSAssert(self.viewItem.audioDurationSeconds > 0.f); - return [self.viewItem.audioDurationSeconds floatValue]; + return self.viewItem.audioDurationSeconds; } - (AudioPlaybackState)audioPlaybackState diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h index 8d0c19d6d..bfece31d8 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h @@ -72,7 +72,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType); @property (nonatomic, weak) OWSAudioMessageView *lastAudioMessageView; -@property (nonatomic, readonly, nullable) NSNumber *audioDurationSeconds; +@property (nonatomic, readonly) CGFloat audioDurationSeconds; - (CGFloat)audioProgressSeconds; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m index 99be46755..d920a1ed3 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m @@ -47,7 +47,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) @property (nonatomic) AudioPlaybackState audioPlaybackState; @property (nonatomic) CGFloat audioProgressSeconds; -@property (nonatomic, nullable) NSNumber *audioDurationSeconds; +@property (nonatomic) CGFloat audioDurationSeconds; #pragma mark - View State @@ -396,7 +396,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) } else if ([self.attachmentStream isAudio]) { CGFloat audioDurationSeconds = [self.attachmentStream audioDurationSeconds]; if (audioDurationSeconds > 0) { - self.audioDurationSeconds = @(audioDurationSeconds); + self.audioDurationSeconds = audioDurationSeconds; self.messageCellType = OWSMessageCellType_Audio; } else { self.messageCellType = OWSMessageCellType_GenericAttachment; diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m b/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m index bf8b4bdeb..5c6a74003 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m @@ -408,23 +408,21 @@ NS_ASSUME_NONNULL_BEGIN self.cachedImageWidth = @(imageSize.width); self.cachedImageHeight = @(imageSize.height); - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - [self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - - NSString *collection = [[self class] collection]; - TSAttachmentStream *latestInstance = [transaction objectForKey:self.uniqueId inCollection:collection]; - if (latestInstance) { - latestInstance.cachedImageWidth = @(imageSize.width); - latestInstance.cachedImageHeight = @(imageSize.height); - [latestInstance saveWithTransaction:transaction]; - } else { - // 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 - // _very_ rare. - OWSFail(@"%@ Attachment not yet saved.", self.logTag); - } - }]; - }); + [self.dbReadWriteConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + + NSString *collection = [[self class] collection]; + TSAttachmentStream *latestInstance = [transaction objectForKey:self.uniqueId inCollection:collection]; + if (latestInstance) { + latestInstance.cachedImageWidth = @(imageSize.width); + latestInstance.cachedImageHeight = @(imageSize.height); + [latestInstance saveWithTransaction:transaction]; + } else { + // 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 + // _very_ rare. + OWSFail(@"%@ Attachment not yet saved.", self.logTag); + } + }]; return imageSize; } @@ -460,21 +458,19 @@ NS_ASSUME_NONNULL_BEGIN CGFloat audioDurationSeconds = [self calculateAudioDurationSeconds]; self.cachedAudioDurationSeconds = @(audioDurationSeconds); - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - [self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - NSString *collection = [[self class] collection]; - TSAttachmentStream *latestInstance = [transaction objectForKey:self.uniqueId inCollection:collection]; - if (latestInstance) { - latestInstance.cachedAudioDurationSeconds = @(audioDurationSeconds); - [latestInstance saveWithTransaction:transaction]; - } else { - // 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 - // _very_ rare. - OWSFail(@"%@ Attachment not yet saved.", self.logTag); - } - }]; - }); + [self.dbReadWriteConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + NSString *collection = [[self class] collection]; + TSAttachmentStream *latestInstance = [transaction objectForKey:self.uniqueId inCollection:collection]; + if (latestInstance) { + latestInstance.cachedAudioDurationSeconds = @(audioDurationSeconds); + [latestInstance saveWithTransaction:transaction]; + } else { + // 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 + // _very_ rare. + OWSFail(@"%@ Attachment not yet saved.", self.logTag); + } + }]; return audioDurationSeconds; }