Store media size from attachment pointer protos.

pull/2/head
Matthew Chen 6 years ago
parent 07cb44c9ef
commit c180d20dcd

@ -3802,7 +3802,8 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
sourceFilename:@"test.mp3"
caption:nil
albumMessageId:nil
attachmentType:TSAttachmentTypeDefault];
attachmentType:TSAttachmentTypeDefault
mediaSize:CGSizeZero];
pointer.state = TSAttachmentPointerStateFailed;
[pointer saveWithTransaction:transaction];
// MJK - should be safe to remove this senderTimestamp
@ -4701,7 +4702,8 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
sourceFilename:fakeAssetLoader.filename
caption:nil
albumMessageId:nil
attachmentType:TSAttachmentTypeDefault];
attachmentType:TSAttachmentTypeDefault
mediaSize:CGSizeZero];
attachmentPointer.state = TSAttachmentPointerStateFailed;
[attachmentPointer saveWithTransaction:transaction];
return attachmentPointer;

@ -1,5 +1,5 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
#import "TSAttachment.h"
@ -36,6 +36,8 @@ typedef NS_ENUM(NSUInteger, TSAttachmentPointerState) {
// messages received from other clients
@property (nullable, nonatomic, readonly) NSData *digest;
@property (nonatomic, readonly) CGSize mediaSize;
// Non-nil for attachments which need "lazy backup restore."
- (nullable OWSBackupFragment *)lazyRestoreFragment;
@ -49,7 +51,8 @@ typedef NS_ENUM(NSUInteger, TSAttachmentPointerState) {
sourceFilename:(nullable NSString *)sourceFilename
caption:(nullable NSString *)caption
albumMessageId:(nullable NSString *)albumMessageId
attachmentType:(TSAttachmentType)attachmentType NS_DESIGNATED_INITIALIZER;
attachmentType:(TSAttachmentType)attachmentType
mediaSize:(CGSize)mediaSize NS_DESIGNATED_INITIALIZER;
- (instancetype)initForRestoreWithAttachmentStream:(TSAttachmentStream *)attachmentStream NS_DESIGNATED_INITIALIZER;

@ -1,5 +1,5 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
#import "TSAttachmentPointer.h"
@ -12,6 +12,15 @@
NS_ASSUME_NONNULL_BEGIN
@interface TSAttachmentStream (TSAttachmentPointer)
- (CGSize)cachedImageSize;
@end
#pragma mark -
@interface TSAttachmentPointer ()
// Optional property. Only set for attachments which need "lazy backup restore."
@ -53,6 +62,7 @@ NS_ASSUME_NONNULL_BEGIN
caption:(nullable NSString *)caption
albumMessageId:(nullable NSString *)albumMessageId
attachmentType:(TSAttachmentType)attachmentType
mediaSize:(CGSize)mediaSize
{
self = [super initWithServerId:serverId
encryptionKey:key
@ -69,6 +79,7 @@ NS_ASSUME_NONNULL_BEGIN
_state = TSAttachmentPointerStateEnqueued;
self.attachmentType = attachmentType;
_pointerType = TSAttachmentPointerTypeIncoming;
_mediaSize = mediaSize;
return self;
}
@ -89,6 +100,7 @@ NS_ASSUME_NONNULL_BEGIN
_state = TSAttachmentPointerStateEnqueued;
self.attachmentType = attachmentStream.attachmentType;
_pointerType = TSAttachmentPointerTypeRestoring;
_mediaSize = (attachmentStream.shouldHaveImageSize ? attachmentStream.cachedImageSize : CGSizeZero);
return self;
}
@ -129,6 +141,12 @@ NS_ASSUME_NONNULL_BEGIN
albumMessageId = albumMessage.uniqueId;
}
CGSize mediaSize = CGSizeZero;
if (attachmentProto.hasWidth && attachmentProto.hasHeight && attachmentProto.width > 0
&& attachmentProto.height > 0) {
mediaSize = CGSizeMake(attachmentProto.width, attachmentProto.height);
}
TSAttachmentPointer *pointer = [[TSAttachmentPointer alloc] initWithServerId:attachmentProto.id
key:attachmentProto.key
digest:digest
@ -137,7 +155,8 @@ NS_ASSUME_NONNULL_BEGIN
sourceFilename:attachmentProto.fileName
caption:caption
albumMessageId:albumMessageId
attachmentType:attachmentType];
attachmentType:attachmentType
mediaSize:mediaSize];
return pointer;
}

@ -526,6 +526,19 @@ typedef void (^OWSLoadedThumbnailSuccess)(OWSLoadedThumbnail *loadedThumbnail);
}
}
- (CGSize)cachedImageSize
{
OWSAssertDebug(self.shouldHaveImageSize);
@synchronized(self) {
if (self.cachedImageWidth && self.cachedImageHeight) {
return CGSizeMake(self.cachedImageWidth.floatValue, self.cachedImageHeight.floatValue);
} else {
return CGSizeZero;
}
}
}
#pragma mark - Update With...
- (void)applyChangeAsyncToLatestCopyWithChangeBlock:(void (^)(TSAttachmentStream *))changeBlock

Loading…
Cancel
Save