parent
b3d17ea192
commit
d8ae5841d6
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
[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);
|
||||
}
|
||||
}];
|
||||
});
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue