diff --git a/src/Messages/Attachments/OWSAttachmentsProcessor.m b/src/Messages/Attachments/OWSAttachmentsProcessor.m index 1cd27dc0e..fabf2bc62 100644 --- a/src/Messages/Attachments/OWSAttachmentsProcessor.m +++ b/src/Messages/Attachments/OWSAttachmentsProcessor.m @@ -92,7 +92,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f; digest:digest contentType:attachmentProto.contentType relay:relay - filename:attachmentProto.fileName + sourceFilename:attachmentProto.fileName attachmentType:attachmentType]; [attachmentIds addObject:pointer.uniqueId]; diff --git a/src/Messages/Attachments/TSAttachment.h b/src/Messages/Attachments/TSAttachment.h index 717af1386..015a3f14c 100644 --- a/src/Messages/Attachments/TSAttachment.h +++ b/src/Messages/Attachments/TSAttachment.h @@ -31,20 +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, +// Represents the "source" filename sent or received in the protos, // not the filename on disk. -@property (nonatomic, readonly, nullable) NSString *filename; +@property (nonatomic, readonly, nullable) NSString *sourceFilename; // This constructor is used for new instances of TSAttachmentPointer, // i.e. undownloaded incoming attachments. - (instancetype)initWithServerId:(UInt64)serverId encryptionKey:(NSData *)encryptionKey contentType:(NSString *)contentType - filename:(nullable NSString *)filename; + sourceFilename:(nullable NSString *)sourceFilename; // This constructor is used for new instances of TSAttachmentStream // that represent new, un-uploaded outgoing attachments. -- (instancetype)initWithContentType:(NSString *)contentType filename:(nullable NSString *)filename; +- (instancetype)initWithContentType:(NSString *)contentType sourceFilename:(nullable NSString *)sourceFilename; // 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 2cd0510fd..c82cfda1d 100644 --- a/src/Messages/Attachments/TSAttachment.m +++ b/src/Messages/Attachments/TSAttachment.m @@ -22,7 +22,7 @@ NSUInteger const TSAttachmentSchemaVersion = 3; - (instancetype)initWithServerId:(UInt64)serverId encryptionKey:(NSData *)encryptionKey contentType:(NSString *)contentType - filename:(nullable NSString *)filename + sourceFilename:(nullable NSString *)sourceFilename { self = [super init]; if (!self) { @@ -33,14 +33,14 @@ NSUInteger const TSAttachmentSchemaVersion = 3; _encryptionKey = encryptionKey; _contentType = contentType; _attachmentSchemaVersion = TSAttachmentSchemaVersion; - _filename = filename; + _sourceFilename = sourceFilename; return self; } // This constructor is used for new instances of TSAttachmentStream // that represent new, un-uploaded outgoing attachments. -- (instancetype)initWithContentType:(NSString *)contentType filename:(nullable NSString *)filename +- (instancetype)initWithContentType:(NSString *)contentType sourceFilename:(nullable NSString *)sourceFilename { self = [super init]; if (!self) { @@ -49,7 +49,7 @@ NSUInteger const TSAttachmentSchemaVersion = 3; _contentType = contentType; _attachmentSchemaVersion = TSAttachmentSchemaVersion; - _filename = filename; + _sourceFilename = sourceFilename; return self; } @@ -67,7 +67,7 @@ NSUInteger const TSAttachmentSchemaVersion = 3; _serverId = pointer.serverId; _encryptionKey = pointer.encryptionKey; _contentType = pointer.contentType; - _filename = pointer.filename; + _sourceFilename = pointer.sourceFilename; _attachmentSchemaVersion = TSAttachmentSchemaVersion; return self; @@ -85,6 +85,12 @@ NSUInteger const TSAttachmentSchemaVersion = 3; _attachmentSchemaVersion = TSAttachmentSchemaVersion; } + if (!_sourceFilename) { + // renamed _filename to _sourceFilename + _sourceFilename = [coder decodeObjectForKey:@"filename"]; + OWSAssert(_sourceFilename || [_sourceFilename isKindOfClass:[NSString class]]); + } + return self; } @@ -107,9 +113,9 @@ NSUInteger const TSAttachmentSchemaVersion = 3; return [NSString stringWithFormat:@"📽 %@", attachmentString]; } else if ([MIMETypeUtil isAudio:self.contentType]) { - // a missing filename is the legacy way to determin if an audio attachment is a voice note vs. other arbitrary - // audio attachments. - if (self.isVoiceMessage || !self.filename || self.filename.length == 0) { + // a missing filename is the legacy way to determine if an audio attachment is + // a voice note vs. other arbitrary audio attachments. + if (self.isVoiceMessage || !self.sourceFilename || self.sourceFilename.length == 0) { attachmentString = NSLocalizedString(@"ATTACHMENT_TYPE_VOICE_MESSAGE", @"Short text label for a voice message attachment, used for thread preview and on lockscreen"); return [NSString stringWithFormat:@"🎤 %@", attachmentString]; diff --git a/src/Messages/Attachments/TSAttachmentPointer.h b/src/Messages/Attachments/TSAttachmentPointer.h index 423f5a021..709eeb1c9 100644 --- a/src/Messages/Attachments/TSAttachmentPointer.h +++ b/src/Messages/Attachments/TSAttachmentPointer.h @@ -24,7 +24,7 @@ typedef NS_ENUM(NSUInteger, TSAttachmentPointerState) { digest:(nullable NSData *)digest contentType:(NSString *)contentType relay:(NSString *)relay - filename:(nullable NSString *)filename + sourceFilename:(nullable NSString *)sourceFilename attachmentType:(TSAttachmentType)attachmentType NS_DESIGNATED_INITIALIZER; @property (nonatomic, readonly) NSString *relay; diff --git a/src/Messages/Attachments/TSAttachmentPointer.m b/src/Messages/Attachments/TSAttachmentPointer.m index e1c34ac96..40334d4fe 100644 --- a/src/Messages/Attachments/TSAttachmentPointer.m +++ b/src/Messages/Attachments/TSAttachmentPointer.m @@ -30,10 +30,10 @@ NS_ASSUME_NONNULL_BEGIN digest:(nullable NSData *)digest contentType:(NSString *)contentType relay:(NSString *)relay - filename:(nullable NSString *)filename + sourceFilename:(nullable NSString *)sourceFilename attachmentType:(TSAttachmentType)attachmentType { - self = [super initWithServerId:serverId encryptionKey:key contentType:contentType filename:filename]; + self = [super initWithServerId:serverId encryptionKey:key contentType:contentType sourceFilename:sourceFilename]; if (!self) { return self; } diff --git a/src/Messages/Attachments/TSAttachmentStream.h b/src/Messages/Attachments/TSAttachmentStream.h index e7219560e..acff25db2 100644 --- a/src/Messages/Attachments/TSAttachmentStream.h +++ b/src/Messages/Attachments/TSAttachmentStream.h @@ -14,7 +14,8 @@ NS_ASSUME_NONNULL_BEGIN @interface TSAttachmentStream : TSAttachment - (instancetype)init NS_UNAVAILABLE; -- (instancetype)initWithContentType:(NSString *)contentType filename:(NSString *)filename NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithContentType:(NSString *)contentType + sourceFilename:(NSString *)sourceFilename NS_DESIGNATED_INITIALIZER; - (instancetype)initWithPointer:(TSAttachmentPointer *)pointer NS_DESIGNATED_INITIALIZER; // Though now required, `digest` may be null for pre-existing records or from diff --git a/src/Messages/Attachments/TSAttachmentStream.m b/src/Messages/Attachments/TSAttachmentStream.m index d2c9f4073..eee5de2dd 100644 --- a/src/Messages/Attachments/TSAttachmentStream.m +++ b/src/Messages/Attachments/TSAttachmentStream.m @@ -12,9 +12,9 @@ NS_ASSUME_NONNULL_BEGIN @implementation TSAttachmentStream -- (instancetype)initWithContentType:(NSString *)contentType filename:(NSString *)filename +- (instancetype)initWithContentType:(NSString *)contentType sourceFilename:(NSString *)sourceFilename { - self = [super initWithContentType:contentType filename:filename]; + self = [super initWithContentType:contentType sourceFilename:sourceFilename]; if (!self) { return self; } @@ -116,7 +116,7 @@ NS_ASSUME_NONNULL_BEGIN { return [MIMETypeUtil filePathForAttachment:self.uniqueId ofMIMEType:self.contentType - filename:self.filename + filename:self.sourceFilename inFolder:[[self class] attachmentsFolder]]; } diff --git a/src/Messages/Interactions/TSOutgoingMessage.h b/src/Messages/Interactions/TSOutgoingMessage.h index 80fc2874f..fabe81ccc 100644 --- a/src/Messages/Interactions/TSOutgoingMessage.h +++ b/src/Messages/Interactions/TSOutgoingMessage.h @@ -89,7 +89,7 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) { @property (atomic, readonly) BOOL hasSyncedTranscript; @property (atomic, readonly) NSString *customMessage; @property (atomic, readonly) NSString *mostRecentFailureText; -// A map of attachment id-to-filename. +// A map of attachment id-to-"source" filename. @property (nonatomic, readonly) NSMutableDictionary *attachmentFilenameMap; @property (atomic, readonly) TSGroupMetaMessage groupMetaMessage; diff --git a/src/Messages/Interactions/TSOutgoingMessage.m b/src/Messages/Interactions/TSOutgoingMessage.m index 8765ceee6..c2adb595a 100644 --- a/src/Messages/Interactions/TSOutgoingMessage.m +++ b/src/Messages/Interactions/TSOutgoingMessage.m @@ -435,8 +435,8 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec if (!attachmentWasGroupAvatar) { NSMutableArray *attachments = [NSMutableArray new]; for (NSString *attachmentId in self.attachmentIds) { - NSString *filename = self.attachmentFilenameMap[attachmentId]; - [attachments addObject:[self buildAttachmentProtoForAttachmentId:attachmentId filename:filename]]; + NSString *sourceFilename = self.attachmentFilenameMap[attachmentId]; + [attachments addObject:[self buildAttachmentProtoForAttachmentId:attachmentId filename:sourceFilename]]; } [builder setAttachmentsArray:attachments]; } diff --git a/src/Messages/OWSMessageSender.h b/src/Messages/OWSMessageSender.h index d562aa60a..588318a59 100644 --- a/src/Messages/OWSMessageSender.h +++ b/src/Messages/OWSMessageSender.h @@ -71,7 +71,7 @@ NS_SWIFT_NAME(MessageSender) */ - (void)sendAttachmentData:(NSData *)attachmentData contentType:(NSString *)contentType - filename:(nullable NSString *)filename + sourceFilename:(nullable NSString *)sourceFilename inMessage:(TSOutgoingMessage *)outgoingMessage success:(void (^)())successHandler failure:(void (^)(NSError *error))failureHandler; diff --git a/src/Messages/OWSMessageSender.m b/src/Messages/OWSMessageSender.m index dbe48de18..5e57f92a4 100644 --- a/src/Messages/OWSMessageSender.m +++ b/src/Messages/OWSMessageSender.m @@ -493,7 +493,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; [self sendAttachmentData:attachmentData contentType:contentType - filename:nil + sourceFilename:nil inMessage:message success:successWithDeleteHandler failure:failureWithDeleteHandler]; @@ -501,7 +501,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; - (void)sendAttachmentData:(NSData *)data contentType:(NSString *)contentType - filename:(nullable NSString *)filename + sourceFilename:(nullable NSString *)sourceFilename inMessage:(TSOutgoingMessage *)message success:(void (^)())successHandler failure:(void (^)(NSError *error))failureHandler @@ -515,7 +515,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; dispatch_async([OWSDispatch attachmentsQueue], ^{ TSAttachmentStream *attachmentStream = - [[TSAttachmentStream alloc] initWithContentType:contentType filename:filename]; + [[TSAttachmentStream alloc] initWithContentType:contentType sourceFilename:sourceFilename]; if (message.isVoiceMessage) { attachmentStream.attachmentType = TSAttachmentTypeVoiceMessage; } @@ -529,8 +529,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; [attachmentStream save]; [message.attachmentIds addObject:attachmentStream.uniqueId]; - if (filename) { - message.attachmentFilenameMap[attachmentStream.uniqueId] = filename; + if (sourceFilename) { + message.attachmentFilenameMap[attachmentStream.uniqueId] = sourceFilename; } [message save]; diff --git a/src/Messages/TSMessagesManager.m b/src/Messages/TSMessagesManager.m index e7652c291..56237871c 100644 --- a/src/Messages/TSMessagesManager.m +++ b/src/Messages/TSMessagesManager.m @@ -758,7 +758,7 @@ NS_ASSUME_NONNULL_BEGIN if (gThread.groupModel.groupImage) { [self.messageSender sendAttachmentData:UIImagePNGRepresentation(gThread.groupModel.groupImage) contentType:OWSMimeTypeImagePng - filename:nil + sourceFilename:nil inMessage:message success:^{ DDLogDebug(@"%@ Successfully sent group update with avatar", self.tag);