|
|
|
@ -19,9 +19,11 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
// changes in the file path generation logic don't break existing attachments.
|
|
|
|
|
@property (nullable, nonatomic) NSString *localRelativeFilePath;
|
|
|
|
|
|
|
|
|
|
// These properties should only be accessed on the main thread.
|
|
|
|
|
// These properties should only be accessed while synchronized on self.
|
|
|
|
|
@property (nullable, nonatomic) NSNumber *cachedImageWidth;
|
|
|
|
|
@property (nullable, nonatomic) NSNumber *cachedImageHeight;
|
|
|
|
|
|
|
|
|
|
// This property should only be accessed on the main thread.
|
|
|
|
|
@property (nullable, nonatomic) NSNumber *cachedAudioDurationSeconds;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
@ -105,10 +107,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
if (attachmentSchemaVersion < 4) {
|
|
|
|
|
// Legacy image sizes don't correctly reflect image orientation.
|
|
|
|
|
@synchronized(self)
|
|
|
|
|
{
|
|
|
|
|
self.cachedImageWidth = nil;
|
|
|
|
|
self.cachedImageHeight = nil;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)ensureFilePath
|
|
|
|
|
{
|
|
|
|
@ -390,15 +395,25 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)shouldHaveImageSize
|
|
|
|
|
{
|
|
|
|
|
return ([self isVideo] || [self isImage] || [self isAnimated]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (CGSize)imageSize
|
|
|
|
|
{
|
|
|
|
|
OWSAssertIsOnMainThread();
|
|
|
|
|
OWSAssert(self.shouldHaveImageSize);
|
|
|
|
|
|
|
|
|
|
@synchronized(self)
|
|
|
|
|
{
|
|
|
|
|
if (self.cachedImageWidth && self.cachedImageHeight) {
|
|
|
|
|
return CGSizeMake(self.cachedImageWidth.floatValue, self.cachedImageHeight.floatValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CGSize imageSize = [self calculateImageSize];
|
|
|
|
|
if (imageSize.width <= 0 || imageSize.height <= 0) {
|
|
|
|
|
return CGSizeZero;
|
|
|
|
|
}
|
|
|
|
|
self.cachedImageWidth = @(imageSize.width);
|
|
|
|
|
self.cachedImageHeight = @(imageSize.height);
|
|
|
|
|
|
|
|
|
@ -420,6 +435,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
return imageSize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (CGFloat)calculateAudioDurationSeconds
|
|
|
|
|
{
|
|
|
|
|