diff --git a/src/Messages/Attachments/TSAttachment.h b/src/Messages/Attachments/TSAttachment.h index d26bc74c4..717af1386 100644 --- a/src/Messages/Attachments/TSAttachment.h +++ b/src/Messages/Attachments/TSAttachment.h @@ -31,15 +31,20 @@ typedef NS_ENUM(NSUInteger, TSAttachmentType) { @property (atomic, readwrite) BOOL isDownloaded; @property (nonatomic) TSAttachmentType attachmentType; +// Represents the "nominal" filename sent or received in the protos, +// not the filename on disk. +@property (nonatomic, readonly, nullable) NSString *filename; + // This constructor is used for new instances of TSAttachmentPointer, // i.e. undownloaded incoming attachments. - (instancetype)initWithServerId:(UInt64)serverId encryptionKey:(NSData *)encryptionKey - contentType:(NSString *)contentType; + contentType:(NSString *)contentType + filename:(nullable NSString *)filename; // This constructor is used for new instances of TSAttachmentStream // that represent new, un-uploaded outgoing attachments. -- (instancetype)initWithContentType:(NSString *)contentType; +- (instancetype)initWithContentType:(NSString *)contentType filename:(nullable NSString *)filename; // This constructor is used for new instances of TSAttachmentStream // that represent downloaded incoming attachments. diff --git a/src/Messages/Attachments/TSAttachment.m b/src/Messages/Attachments/TSAttachment.m index 53f3f830b..dfcbccbe9 100644 --- a/src/Messages/Attachments/TSAttachment.m +++ b/src/Messages/Attachments/TSAttachment.m @@ -22,6 +22,7 @@ NSUInteger const TSAttachmentSchemaVersion = 3; - (instancetype)initWithServerId:(UInt64)serverId encryptionKey:(NSData *)encryptionKey contentType:(NSString *)contentType + filename:(nullable NSString *)filename { self = [super init]; if (!self) { @@ -32,13 +33,14 @@ NSUInteger const TSAttachmentSchemaVersion = 3; _encryptionKey = encryptionKey; _contentType = contentType; _attachmentSchemaVersion = TSAttachmentSchemaVersion; + _filename = filename; return self; } // This constructor is used for new instances of TSAttachmentStream // that represent new, un-uploaded outgoing attachments. -- (instancetype)initWithContentType:(NSString *)contentType +- (instancetype)initWithContentType:(NSString *)contentType filename:(nullable NSString *)filename { self = [super init]; if (!self) { @@ -47,6 +49,7 @@ NSUInteger const TSAttachmentSchemaVersion = 3; _contentType = contentType; _attachmentSchemaVersion = TSAttachmentSchemaVersion; + _filename = filename; return self; } @@ -64,6 +67,7 @@ NSUInteger const TSAttachmentSchemaVersion = 3; _serverId = pointer.serverId; _encryptionKey = pointer.encryptionKey; _contentType = pointer.contentType; + _filename = pointer.filename; _attachmentSchemaVersion = TSAttachmentSchemaVersion; return self; diff --git a/src/Messages/Attachments/TSAttachmentPointer.h b/src/Messages/Attachments/TSAttachmentPointer.h index 106a1ad88..423f5a021 100644 --- a/src/Messages/Attachments/TSAttachmentPointer.h +++ b/src/Messages/Attachments/TSAttachmentPointer.h @@ -28,7 +28,6 @@ typedef NS_ENUM(NSUInteger, TSAttachmentPointerState) { attachmentType:(TSAttachmentType)attachmentType NS_DESIGNATED_INITIALIZER; @property (nonatomic, readonly) NSString *relay; -@property (nonatomic, readonly, nullable) NSString *filename; @property (atomic) TSAttachmentPointerState state; // Though now required, `digest` may be null for pre-existing records or from diff --git a/src/Messages/Attachments/TSAttachmentPointer.m b/src/Messages/Attachments/TSAttachmentPointer.m index a2998a5a5..e1c34ac96 100644 --- a/src/Messages/Attachments/TSAttachmentPointer.m +++ b/src/Messages/Attachments/TSAttachmentPointer.m @@ -33,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN filename:(nullable NSString *)filename attachmentType:(TSAttachmentType)attachmentType { - self = [super initWithServerId:serverId encryptionKey:key contentType:contentType]; + self = [super initWithServerId:serverId encryptionKey:key contentType:contentType filename:filename]; if (!self) { return self; } @@ -41,7 +41,6 @@ NS_ASSUME_NONNULL_BEGIN _digest = digest; _state = TSAttachmentPointerStateEnqueued; _relay = relay; - _filename = filename; self.attachmentType = attachmentType; return self; diff --git a/src/Messages/Attachments/TSAttachmentStream.h b/src/Messages/Attachments/TSAttachmentStream.h index 389d820e1..e7219560e 100644 --- a/src/Messages/Attachments/TSAttachmentStream.h +++ b/src/Messages/Attachments/TSAttachmentStream.h @@ -24,8 +24,6 @@ NS_ASSUME_NONNULL_BEGIN // This only applies for attachments being uploaded. @property (atomic) BOOL isUploaded; -@property (nonatomic, readonly, nullable) NSString *filename; - #if TARGET_OS_IPHONE - (nullable UIImage *)image; #endif diff --git a/src/Messages/Attachments/TSAttachmentStream.m b/src/Messages/Attachments/TSAttachmentStream.m index 9c6799b4a..d2c9f4073 100644 --- a/src/Messages/Attachments/TSAttachmentStream.m +++ b/src/Messages/Attachments/TSAttachmentStream.m @@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithContentType:(NSString *)contentType filename:(NSString *)filename { - self = [super initWithContentType:contentType]; + self = [super initWithContentType:contentType filename:filename]; if (!self) { return self; } @@ -24,7 +24,6 @@ NS_ASSUME_NONNULL_BEGIN // state, but this constructor is used only for new outgoing // attachments which haven't been uploaded yet. _isUploaded = NO; - _filename = filename; return self; } @@ -43,7 +42,6 @@ NS_ASSUME_NONNULL_BEGIN // state, but this constructor is used only for new incoming // attachments which don't need to be uploaded. _isUploaded = YES; - _filename = pointer.filename; self.attachmentType = pointer.attachmentType; return self;