Tidy files.

pull/1/head
Matthew Chen 7 years ago
parent 2c19474397
commit e6bc37d941

@ -67,8 +67,7 @@ class ConversationConfigurationSyncOperation: OWSOperation {
var dataSource: DataSource? = nil var dataSource: DataSource? = nil
self.dbConnection.readWrite { transaction in self.dbConnection.readWrite { transaction in
let messageData: Data = syncMessage.buildPlainTextAttachmentData(with: transaction) let messageData: Data = syncMessage.buildPlainTextAttachmentData(with: transaction)
dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData) dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData, shouldDeleteOnDeallocation: true)
dataSource?.setShouldDeleteOnDeallocation()
} }
guard let attachmentDataSource = dataSource else { guard let attachmentDataSource = dataSource else {
@ -89,8 +88,7 @@ class ConversationConfigurationSyncOperation: OWSOperation {
var dataSource: DataSource? = nil var dataSource: DataSource? = nil
self.dbConnection.read { transaction in self.dbConnection.read { transaction in
let messageData: Data = syncMessage.buildPlainTextAttachmentData(with: transaction) let messageData: Data = syncMessage.buildPlainTextAttachmentData(with: transaction)
dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData) dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData, shouldDeleteOnDeallocation: true)
dataSource?.setShouldDeleteOnDeallocation()
} }
guard let attachmentDataSource = dataSource else { guard let attachmentDataSource = dataSource else {

@ -50,8 +50,8 @@ import SignalMessaging
var dataSource: DataSource? = nil var dataSource: DataSource? = nil
self.editingDatabaseConnection.readWrite { transaction in self.editingDatabaseConnection.readWrite { transaction in
dataSource = DataSourceValue.dataSource(withSyncMessageData: syncContactsMessage.buildPlainTextAttachmentData(with: transaction)) dataSource = DataSourceValue.dataSource(withSyncMessageData: syncContactsMessage.buildPlainTextAttachmentData(with: transaction),
dataSource?.setShouldDeleteOnDeallocation() shouldDeleteOnDeallocation: true)
} }
guard let attachmentDataSource = dataSource else { guard let attachmentDataSource = dataSource else {

@ -2884,7 +2884,7 @@ typedef enum : NSUInteger {
OWSAssert(type); OWSAssert(type);
OWSAssert(filename); OWSAssert(filename);
DataSource *_Nullable dataSource = [DataSourcePath dataSourceWithURL:url]; DataSource *_Nullable dataSource = [DataSourcePath dataSourceWithURL:url shouldDeleteOnDeallocation:NO];
if (!dataSource) { if (!dataSource) {
OWSFail(@"%@ attachment data was unexpectedly empty for picked document url: %@", self.logTag, url); OWSFail(@"%@ attachment data was unexpectedly empty for picked document url: %@", self.logTag, url);
@ -3099,8 +3099,9 @@ typedef enum : NSUInteger {
} }
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();
DataSource *_Nullable dataSource = DataSource *_Nullable dataSource = [DataSourceValue dataSourceWithData:imageData
[DataSourceValue dataSourceWithData:imageData utiType:dataUTI]; utiType:dataUTI
shouldDeleteOnDeallocation:YES];
[dataSource setSourceFilename:filename]; [dataSource setSourceFilename:filename];
SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource
dataUTI:dataUTI dataUTI:dataUTI
@ -3186,7 +3187,8 @@ typedef enum : NSUInteger {
presentFromViewController:self presentFromViewController:self
canCancel:YES canCancel:YES
backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) { backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
DataSource *dataSource = [DataSourcePath dataSourceWithURL:movieURL]; DataSource *dataSource =
[DataSourcePath dataSourceWithURL:movieURL shouldDeleteOnDeallocation:NO];
dataSource.sourceFilename = filename; dataSource.sourceFilename = filename;
VideoCompressionResult *compressionResult = VideoCompressionResult *compressionResult =
[SignalAttachment compressVideoAsMp4WithDataSource:dataSource [SignalAttachment compressVideoAsMp4WithDataSource:dataSource
@ -3667,7 +3669,8 @@ typedef enum : NSUInteger {
return; return;
} }
DataSource *_Nullable dataSource = [DataSourcePath dataSourceWithURL:self.audioRecorder.url]; DataSource *_Nullable dataSource =
[DataSourcePath dataSourceWithURL:self.audioRecorder.url shouldDeleteOnDeallocation:YES];
self.audioRecorder = nil; self.audioRecorder = nil;
if (!dataSource) { if (!dataSource) {
@ -3679,8 +3682,6 @@ typedef enum : NSUInteger {
NSString *filename = [NSLocalizedString(@"VOICE_MESSAGE_FILE_NAME", @"Filename for voice messages.") NSString *filename = [NSLocalizedString(@"VOICE_MESSAGE_FILE_NAME", @"Filename for voice messages.")
stringByAppendingPathExtension:@"m4a"]; stringByAppendingPathExtension:@"m4a"];
[dataSource setSourceFilename:filename]; [dataSource setSourceFilename:filename];
// Remove temporary file when complete.
[dataSource setShouldDeleteOnDeallocation];
SignalAttachment *attachment = SignalAttachment *attachment =
[SignalAttachment voiceMessageAttachmentWithDataSource:dataSource dataUTI:(NSString *)kUTTypeMPEG4Audio]; [SignalAttachment voiceMessageAttachmentWithDataSource:dataSource dataUTI:(NSString *)kUTTypeMPEG4Audio];
DDLogVerbose(@"%@ voice memo duration: %f, file size: %zd", self.logTag, durationSeconds, [dataSource dataLength]); DDLogVerbose(@"%@ voice memo duration: %f, file size: %zd", self.logTag, durationSeconds, [dataSource dataLength]);
@ -3939,8 +3940,8 @@ typedef enum : NSUInteger {
if (newGroupModel.groupImage) { if (newGroupModel.groupImage) {
NSData *data = UIImagePNGRepresentation(newGroupModel.groupImage); NSData *data = UIImagePNGRepresentation(newGroupModel.groupImage);
DataSource *_Nullable dataSource = [DataSourceValue dataSourceWithData:data fileExtension:@"png"]; DataSource *_Nullable dataSource =
[dataSource setShouldDeleteOnDeallocation]; [DataSourceValue dataSourceWithData:data fileExtension:@"png" shouldDeleteOnDeallocation:YES];
[self.messageSender enqueueTemporaryAttachment:dataSource [self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeImagePng contentType:OWSMimeTypeImagePng
inMessage:message inMessage:message
@ -4432,7 +4433,8 @@ typedef enum : NSUInteger {
TSOutgoingMessage *message; TSOutgoingMessage *message;
if ([text lengthOfBytesUsingEncoding:NSUTF8StringEncoding] >= kOversizeTextMessageSizeThreshold) { if ([text lengthOfBytesUsingEncoding:NSUTF8StringEncoding] >= kOversizeTextMessageSizeThreshold) {
DataSource *_Nullable dataSource = [DataSourceValue dataSourceWithOversizeText:text]; DataSource *_Nullable dataSource =
[DataSourceValue dataSourceWithOversizeText:text shouldDeleteOnDeallocation:YES];
SignalAttachment *attachment = SignalAttachment *attachment =
[SignalAttachment attachmentWithDataSource:dataSource dataUTI:kOversizeTextAttachmentUTI]; [SignalAttachment attachmentWithDataSource:dataSource dataUTI:kOversizeTextAttachmentUTI];
// TODO we should redundantly send the first n chars in the body field so it can be viewed // TODO we should redundantly send the first n chars in the body field so it can be viewed

@ -351,7 +351,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSMessageSender *messageSender = [Environment current].messageSender; OWSMessageSender *messageSender = [Environment current].messageSender;
NSString *filename = [filePath lastPathComponent]; NSString *filename = [filePath lastPathComponent];
NSString *utiType = [MIMETypeUtil utiTypeForFileExtension:filename.pathExtension]; NSString *utiType = [MIMETypeUtil utiTypeForFileExtension:filename.pathExtension];
DataSource *_Nullable dataSource = [DataSourcePath dataSourceWithFilePath:filePath]; DataSource *_Nullable dataSource = [DataSourcePath dataSourceWithFilePath:filePath shouldDeleteOnDeallocation:NO];
[dataSource setSourceFilename:filename]; [dataSource setSourceFilename:filename];
SignalAttachment *attachment = SignalAttachment *attachment =
[SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType imageQuality:TSImageQualityOriginal]; [SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType imageQuality:TSImageQualityOriginal];
@ -1701,7 +1701,7 @@ NS_ASSUME_NONNULL_BEGIN
NSString *filename = [filePath lastPathComponent]; NSString *filename = [filePath lastPathComponent];
NSString *utiType = [MIMETypeUtil utiTypeForFileExtension:filename.pathExtension]; NSString *utiType = [MIMETypeUtil utiTypeForFileExtension:filename.pathExtension];
DataSource *_Nullable dataSource = [DataSourcePath dataSourceWithFilePath:filePath]; DataSource *_Nullable dataSource = [DataSourcePath dataSourceWithFilePath:filePath shouldDeleteOnDeallocation:NO];
[dataSource setSourceFilename:filename]; [dataSource setSourceFilename:filename];
SignalAttachment *attachment = SignalAttachment *attachment =
[SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType imageQuality:TSImageQualityOriginal]; [SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType imageQuality:TSImageQualityOriginal];
@ -3324,7 +3324,8 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
{ {
OWSMessageSender *messageSender = [Environment current].messageSender; OWSMessageSender *messageSender = [Environment current].messageSender;
NSString *message = [self randomOversizeText]; NSString *message = [self randomOversizeText];
DataSource *_Nullable dataSource = [DataSourceValue dataSourceWithOversizeText:message]; DataSource *_Nullable dataSource =
[DataSourceValue dataSourceWithOversizeText:message shouldDeleteOnDeallocation:YES];
SignalAttachment *attachment = SignalAttachment *attachment =
[SignalAttachment attachmentWithDataSource:dataSource dataUTI:kOversizeTextAttachmentUTI]; [SignalAttachment attachmentWithDataSource:dataSource dataUTI:kOversizeTextAttachmentUTI];
[ThreadUtil sendMessageWithAttachment:attachment [ThreadUtil sendMessageWithAttachment:attachment
@ -3354,8 +3355,9 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
+ (void)sendRandomAttachment:(TSThread *)thread uti:(NSString *)uti length:(NSUInteger)length + (void)sendRandomAttachment:(TSThread *)thread uti:(NSString *)uti length:(NSUInteger)length
{ {
OWSMessageSender *messageSender = [Environment current].messageSender; OWSMessageSender *messageSender = [Environment current].messageSender;
DataSource *_Nullable dataSource = DataSource *_Nullable dataSource = [DataSourceValue dataSourceWithData:[self createRandomNSDataOfSize:length]
[DataSourceValue dataSourceWithData:[self createRandomNSDataOfSize:length] utiType:uti]; utiType:uti
shouldDeleteOnDeallocation:YES];
SignalAttachment *attachment = SignalAttachment *attachment =
[SignalAttachment attachmentWithDataSource:dataSource dataUTI:uti imageQuality:TSImageQualityOriginal]; [SignalAttachment attachmentWithDataSource:dataSource dataUTI:uti imageQuality:TSImageQualityOriginal];
@ -4362,7 +4364,9 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
NSString *utiType = (NSString *)kUTTypeData; NSString *utiType = (NSString *)kUTTypeData;
const NSUInteger kDataLength = 32; const NSUInteger kDataLength = 32;
DataSource *_Nullable dataSource = DataSource *_Nullable dataSource =
[DataSourceValue dataSourceWithData:[self createRandomNSDataOfSize:kDataLength] utiType:utiType]; [DataSourceValue dataSourceWithData:[self createRandomNSDataOfSize:kDataLength]
utiType:utiType
shouldDeleteOnDeallocation:YES];
[dataSource setSourceFilename:filename]; [dataSource setSourceFilename:filename];
SignalAttachment *attachment = SignalAttachment *attachment =
[SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType imageQuality:TSImageQualityOriginal]; [SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType imageQuality:TSImageQualityOriginal];
@ -4593,7 +4597,8 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
OWSAssert(transaction); OWSAssert(transaction);
if (isAttachmentDownloaded) { if (isAttachmentDownloaded) {
DataSource *dataSource = [DataSourcePath dataSourceWithFilePath:fakeAssetLoader.filePath]; DataSource *dataSource =
[DataSourcePath dataSourceWithFilePath:fakeAssetLoader.filePath shouldDeleteOnDeallocation:NO];
NSString *filename = dataSource.sourceFilename; NSString *filename = dataSource.sourceFilename;
// To support "fake missing" attachments, we sometimes lie about the // To support "fake missing" attachments, we sometimes lie about the
// length of the data. // length of the data.

@ -233,7 +233,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSMessageSender *messageSender = [Environment current].messageSender; OWSMessageSender *messageSender = [Environment current].messageSender;
NSString *utiType = [MIMETypeUtil utiTypeForFileExtension:fileName.pathExtension]; NSString *utiType = [MIMETypeUtil utiTypeForFileExtension:fileName.pathExtension];
DataSource *_Nullable dataSource = [DataSourcePath dataSourceWithFilePath:filePath]; DataSource *_Nullable dataSource = [DataSourcePath dataSourceWithFilePath:filePath shouldDeleteOnDeallocation:YES];
[dataSource setSourceFilename:fileName]; [dataSource setSourceFilename:fileName];
SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType]; SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType];
NSData *databasePassword = [OWSPrimaryStorage.sharedManager databasePassword]; NSData *databasePassword = [OWSPrimaryStorage.sharedManager databasePassword];
@ -262,7 +262,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSMessageSender *messageSender = [Environment current].messageSender; OWSMessageSender *messageSender = [Environment current].messageSender;
NSString *utiType = [MIMETypeUtil utiTypeForFileExtension:fileName.pathExtension]; NSString *utiType = [MIMETypeUtil utiTypeForFileExtension:fileName.pathExtension];
DataSource *_Nullable dataSource = [DataSourcePath dataSourceWithFilePath:filePath]; DataSource *_Nullable dataSource = [DataSourcePath dataSourceWithFilePath:filePath shouldDeleteOnDeallocation:YES];
[dataSource setSourceFilename:fileName]; [dataSource setSourceFilename:fileName];
SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType]; SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType];
if (!attachment || [attachment hasError]) { if (!attachment || [attachment hasError]) {

@ -102,9 +102,8 @@ NS_ASSUME_NONNULL_BEGIN
__block DataSource *dataSource; __block DataSource *dataSource;
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
dataSource = [DataSourceValue dataSource = [DataSourceValue
dataSourceWithSyncMessageData:[syncContactsMessage dataSourceWithSyncMessageData:[syncContactsMessage buildPlainTextAttachmentDataWithTransaction:transaction]
buildPlainTextAttachmentDataWithTransaction:transaction]]; shouldDeleteOnDeallocation:YES];
[dataSource setShouldDeleteOnDeallocation];
}]; }];
[self.messageSender enqueueTemporaryAttachment:dataSource [self.messageSender enqueueTemporaryAttachment:dataSource
@ -124,8 +123,8 @@ NS_ASSUME_NONNULL_BEGIN
__block DataSource *dataSource; __block DataSource *dataSource;
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
dataSource = [DataSourceValue dataSource = [DataSourceValue
dataSourceWithSyncMessageData:[syncGroupsMessage buildPlainTextAttachmentDataWithTransaction:transaction]]; dataSourceWithSyncMessageData:[syncGroupsMessage buildPlainTextAttachmentDataWithTransaction:transaction]
[dataSource setShouldDeleteOnDeallocation]; shouldDeleteOnDeallocation:YES];
}]; }];
[self.messageSender enqueueTemporaryAttachment:dataSource [self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeApplicationOctetStream contentType:OWSMimeTypeApplicationOctetStream

@ -370,7 +370,8 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
} }
let filePath = asset.filePath let filePath = asset.filePath
guard let dataSource = DataSourcePath.dataSource(withFilePath: filePath) else { guard let dataSource = DataSourcePath.dataSource(withFilePath: filePath,
shouldDeleteOnDeallocation: false) else {
owsFail("\(strongSelf.TAG) couldn't load asset.") owsFail("\(strongSelf.TAG) couldn't load asset.")
return return
} }

@ -488,9 +488,9 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if (model.groupImage) { if (model.groupImage) {
NSData *data = UIImagePNGRepresentation(model.groupImage); NSData *data = UIImagePNGRepresentation(model.groupImage);
DataSource *_Nullable dataSource = DataSource *_Nullable dataSource = [DataSourceValue dataSourceWithData:data
[DataSourceValue dataSourceWithData:data fileExtension:@"png"]; fileExtension:@"png"
[dataSource setShouldDeleteOnDeallocation]; shouldDeleteOnDeallocation:YES];
[self.messageSender enqueueTemporaryAttachment:dataSource [self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeImagePng contentType:OWSMimeTypeImagePng
inMessage:message inMessage:message

@ -519,7 +519,7 @@ public class SignalAttachment: NSObject {
owsFail("\(logTag) Missing expected pasteboard data for UTI: \(dataUTI)") owsFail("\(logTag) Missing expected pasteboard data for UTI: \(dataUTI)")
return nil return nil
} }
let dataSource = DataSourceValue.dataSource(with: data, utiType: dataUTI) let dataSource = DataSourceValue.dataSource(with: data, utiType: dataUTI, shouldDeleteOnDeallocation: false)
// Pasted images _SHOULD _NOT_ be resized, if possible. // Pasted images _SHOULD _NOT_ be resized, if possible.
return attachment(dataSource: dataSource, dataUTI: dataUTI, imageQuality: .medium) return attachment(dataSource: dataSource, dataUTI: dataUTI, imageQuality: .medium)
} }
@ -530,7 +530,7 @@ public class SignalAttachment: NSObject {
owsFail("\(logTag) Missing expected pasteboard data for UTI: \(dataUTI)") owsFail("\(logTag) Missing expected pasteboard data for UTI: \(dataUTI)")
return nil return nil
} }
let dataSource = DataSourceValue.dataSource(with: data, utiType: dataUTI) let dataSource = DataSourceValue.dataSource(with: data, utiType: dataUTI, shouldDeleteOnDeallocation: false)
return videoAttachment(dataSource: dataSource, dataUTI: dataUTI) return videoAttachment(dataSource: dataSource, dataUTI: dataUTI)
} }
} }
@ -540,7 +540,7 @@ public class SignalAttachment: NSObject {
owsFail("\(logTag) Missing expected pasteboard data for UTI: \(dataUTI)") owsFail("\(logTag) Missing expected pasteboard data for UTI: \(dataUTI)")
return nil return nil
} }
let dataSource = DataSourceValue.dataSource(with: data, utiType: dataUTI) let dataSource = DataSourceValue.dataSource(with: data, utiType: dataUTI, shouldDeleteOnDeallocation: false)
return audioAttachment(dataSource: dataSource, dataUTI: dataUTI) return audioAttachment(dataSource: dataSource, dataUTI: dataUTI)
} }
} }
@ -550,7 +550,7 @@ public class SignalAttachment: NSObject {
owsFail("\(logTag) Missing expected pasteboard data for UTI: \(dataUTI)") owsFail("\(logTag) Missing expected pasteboard data for UTI: \(dataUTI)")
return nil return nil
} }
let dataSource = DataSourceValue.dataSource(with: data, utiType: dataUTI) let dataSource = DataSourceValue.dataSource(with: data, utiType: dataUTI, shouldDeleteOnDeallocation: false)
return genericAttachment(dataSource: dataSource, dataUTI: dataUTI) return genericAttachment(dataSource: dataSource, dataUTI: dataUTI)
} }
@ -723,7 +723,7 @@ public class SignalAttachment: NSObject {
return attachment return attachment
} }
guard let dataSource = DataSourceValue.dataSource(with: jpgImageData, fileExtension: "jpg") else { guard let dataSource = DataSourceValue.dataSource(with: jpgImageData, fileExtension: "jpg", shouldDeleteOnDeallocation: false) else {
attachment.error = .couldNotConvertToJpeg attachment.error = .couldNotConvertToJpeg
return attachment return attachment
} }
@ -892,7 +892,7 @@ public class SignalAttachment: NSObject {
} }
if CGImageDestinationFinalize(destination) { if CGImageDestinationFinalize(destination) {
guard let dataSource = DataSourceValue.dataSource(with: mutableData as Data, utiType: attachment.dataUTI) else { guard let dataSource = DataSourceValue.dataSource(with: mutableData as Data, utiType: attachment.dataUTI, shouldDeleteOnDeallocation: false) else {
attachment.error = .couldNotRemoveMetadata attachment.error = .couldNotRemoveMetadata
return attachment return attachment
} }
@ -980,7 +980,8 @@ public class SignalAttachment: NSObject {
let baseFilename = dataSource.sourceFilename let baseFilename = dataSource.sourceFilename
let mp4Filename = baseFilename?.filenameWithoutExtension.appendingFileExtension("mp4") let mp4Filename = baseFilename?.filenameWithoutExtension.appendingFileExtension("mp4")
guard let dataSource = DataSourcePath.dataSource(with: exportURL) else { guard let dataSource = DataSourcePath.dataSource(with: exportURL,
shouldDeleteOnDeallocation: true) else {
owsFail("Failed to build data source for exported video URL") owsFail("Failed to build data source for exported video URL")
let attachment = SignalAttachment(dataSource: DataSourceValue.emptyDataSource(), dataUTI: dataUTI) let attachment = SignalAttachment(dataSource: DataSourceValue.emptyDataSource(), dataUTI: dataUTI)
attachment.error = .couldNotConvertToMpeg4 attachment.error = .couldNotConvertToMpeg4
@ -988,7 +989,6 @@ public class SignalAttachment: NSObject {
return return
} }
dataSource.setShouldDeleteOnDeallocation()
dataSource.sourceFilename = mp4Filename dataSource.sourceFilename = mp4Filename
let attachment = SignalAttachment(dataSource: dataSource, dataUTI: kUTTypeMPEG4 as String) let attachment = SignalAttachment(dataSource: dataSource, dataUTI: kUTTypeMPEG4 as String)
@ -1070,7 +1070,7 @@ public class SignalAttachment: NSObject {
// NOTE: The attachment returned by this method may not be valid. // NOTE: The attachment returned by this method may not be valid.
// Check the attachment's error property. // Check the attachment's error property.
private class func oversizeTextAttachment(text: String?) -> SignalAttachment { private class func oversizeTextAttachment(text: String?) -> SignalAttachment {
let dataSource = DataSourceValue.dataSource(withOversizeText: text) let dataSource = DataSourceValue.dataSource(withOversizeText: text, shouldDeleteOnDeallocation: false)
return newAttachment(dataSource: dataSource, return newAttachment(dataSource: dataSource,
dataUTI: kOversizeTextAttachmentUTI, dataUTI: kOversizeTextAttachmentUTI,
validUTISet: nil, validUTISet: nil,

@ -139,8 +139,8 @@ NSString *const kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
self.isRequestInFlight = YES; self.isRequestInFlight = YES;
DataSource *dataSource = [DataSourceValue dataSourceWithSyncMessageData:messageData]; DataSource *dataSource =
[dataSource setShouldDeleteOnDeallocation]; [DataSourceValue dataSourceWithSyncMessageData:messageData shouldDeleteOnDeallocation:YES];
[self.messageSender enqueueTemporaryAttachment:dataSource [self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeApplicationOctetStream contentType:OWSMimeTypeApplicationOctetStream
inMessage:syncContactsMessage inMessage:syncContactsMessage

@ -657,8 +657,8 @@ NS_ASSUME_NONNULL_BEGIN
profileManager:self.profileManager]; profileManager:self.profileManager];
DataSource *dataSource = [DataSourceValue DataSource *dataSource = [DataSourceValue
dataSourceWithSyncMessageData:[syncContactsMessage dataSourceWithSyncMessageData:[syncContactsMessage
buildPlainTextAttachmentDataWithTransaction:transaction]]; buildPlainTextAttachmentDataWithTransaction:transaction]
[dataSource setShouldDeleteOnDeallocation]; shouldDeleteOnDeallocation:YES];
[self.messageSender enqueueTemporaryAttachment:dataSource [self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeApplicationOctetStream contentType:OWSMimeTypeApplicationOctetStream
inMessage:syncContactsMessage inMessage:syncContactsMessage
@ -674,8 +674,8 @@ NS_ASSUME_NONNULL_BEGIN
OWSSyncGroupsMessage *syncGroupsMessage = [[OWSSyncGroupsMessage alloc] init]; OWSSyncGroupsMessage *syncGroupsMessage = [[OWSSyncGroupsMessage alloc] init];
DataSource *dataSource = [DataSourceValue DataSource *dataSource = [DataSourceValue
dataSourceWithSyncMessageData:[syncGroupsMessage dataSourceWithSyncMessageData:[syncGroupsMessage
buildPlainTextAttachmentDataWithTransaction:transaction]]; buildPlainTextAttachmentDataWithTransaction:transaction]
[dataSource setShouldDeleteOnDeallocation]; shouldDeleteOnDeallocation:YES];
[self.messageSender enqueueTemporaryAttachment:dataSource [self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeApplicationOctetStream contentType:OWSMimeTypeApplicationOctetStream
inMessage:syncGroupsMessage inMessage:syncGroupsMessage
@ -826,8 +826,8 @@ NS_ASSUME_NONNULL_BEGIN
if (gThread.groupModel.groupImage) { if (gThread.groupModel.groupImage) {
NSData *data = UIImagePNGRepresentation(gThread.groupModel.groupImage); NSData *data = UIImagePNGRepresentation(gThread.groupModel.groupImage);
DataSource *_Nullable dataSource = [DataSourceValue dataSourceWithData:data fileExtension:@"png"]; DataSource *_Nullable dataSource =
[dataSource setShouldDeleteOnDeallocation]; [DataSourceValue dataSourceWithData:data fileExtension:@"png" shouldDeleteOnDeallocation:YES];
[self.messageSender enqueueTemporaryAttachment:dataSource [self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeImagePng contentType:OWSMimeTypeImagePng
inMessage:message inMessage:message

@ -29,10 +29,6 @@ NS_ASSUME_NONNULL_BEGIN
// Returns YES on success. // Returns YES on success.
- (BOOL)writeToPath:(NSString *)dstFilePath; - (BOOL)writeToPath:(NSString *)dstFilePath;
// If called, this data source will try to delete its on-disk contents
// when it is deallocated.
- (void)setShouldDeleteOnDeallocation;
- (BOOL)isValidImage; - (BOOL)isValidImage;
@end @end
@ -41,13 +37,19 @@ NS_ASSUME_NONNULL_BEGIN
@interface DataSourceValue : DataSource @interface DataSourceValue : DataSource
+ (nullable DataSource *)dataSourceWithData:(NSData *)data fileExtension:(NSString *)fileExtension; + (nullable DataSource *)dataSourceWithData:(NSData *)data
fileExtension:(NSString *)fileExtension
shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation;
+ (nullable DataSource *)dataSourceWithData:(NSData *)data utiType:(NSString *)utiType; + (nullable DataSource *)dataSourceWithData:(NSData *)data
utiType:(NSString *)utiType
shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation;
+ (nullable DataSource *)dataSourceWithOversizeText:(NSString *_Nullable)text; + (nullable DataSource *)dataSourceWithOversizeText:(NSString *_Nullable)text
shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation;
+ (DataSource *)dataSourceWithSyncMessageData:(NSData *)data; + (DataSource *)dataSourceWithSyncMessageData:(NSData *)data
shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation;
+ (DataSource *)emptyDataSource; + (DataSource *)emptyDataSource;
@ -57,9 +59,10 @@ NS_ASSUME_NONNULL_BEGIN
@interface DataSourcePath : DataSource @interface DataSourcePath : DataSource
+ (nullable DataSource *)dataSourceWithURL:(NSURL *)fileUrl; + (nullable DataSource *)dataSourceWithURL:(NSURL *)fileUrl shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation;
+ (nullable DataSource *)dataSourceWithFilePath:(NSString *)filePath; + (nullable DataSource *)dataSourceWithFilePath:(NSString *)filePath
shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation;
@end @end

@ -60,11 +60,6 @@ NS_ASSUME_NONNULL_BEGIN
return NO; return NO;
} }
- (void)setShouldDeleteOnDeallocation
{
self.shouldDeleteOnDeallocation = YES;
}
- (BOOL)isValidImage - (BOOL)isValidImage
{ {
NSString *_Nullable dataPath = [self dataPathIfOnDisk]; NSString *_Nullable dataPath = [self dataPathIfOnDisk];
@ -126,7 +121,9 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
+ (nullable DataSource *)dataSourceWithData:(NSData *)data fileExtension:(NSString *)fileExtension + (nullable DataSource *)dataSourceWithData:(NSData *)data
fileExtension:(NSString *)fileExtension
shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation
{ {
OWSAssert(data); OWSAssert(data);
@ -137,35 +134,43 @@ NS_ASSUME_NONNULL_BEGIN
DataSourceValue *instance = [DataSourceValue new]; DataSourceValue *instance = [DataSourceValue new];
instance.dataValue = data; instance.dataValue = data;
instance.fileExtension = fileExtension; instance.fileExtension = fileExtension;
// Always try to clean up temp files created by this instance. instance.shouldDeleteOnDeallocation = shouldDeleteOnDeallocation;
[instance setShouldDeleteOnDeallocation];
return instance; return instance;
} }
+ (nullable DataSource *)dataSourceWithData:(NSData *)data utiType:(NSString *)utiType + (nullable DataSource *)dataSourceWithData:(NSData *)data
utiType:(NSString *)utiType
shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation
{ {
NSString *fileExtension = [MIMETypeUtil fileExtensionForUTIType:utiType]; NSString *fileExtension = [MIMETypeUtil fileExtensionForUTIType:utiType];
return [self dataSourceWithData:data fileExtension:fileExtension]; return [self dataSourceWithData:data
fileExtension:fileExtension
shouldDeleteOnDeallocation:shouldDeleteOnDeallocation];
} }
+ (nullable DataSource *)dataSourceWithOversizeText:(NSString *_Nullable)text + (nullable DataSource *)dataSourceWithOversizeText:(NSString *_Nullable)text
shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation
{ {
if (!text) { if (!text) {
return nil; return nil;
} }
NSData *data = [text.filterStringForDisplay dataUsingEncoding:NSUTF8StringEncoding]; NSData *data = [text.filterStringForDisplay dataUsingEncoding:NSUTF8StringEncoding];
return [self dataSourceWithData:data fileExtension:kOversizeTextAttachmentFileExtension]; return [self dataSourceWithData:data
fileExtension:kOversizeTextAttachmentFileExtension
shouldDeleteOnDeallocation:shouldDeleteOnDeallocation];
} }
+ (DataSource *)dataSourceWithSyncMessageData:(NSData *)data + (DataSource *)dataSourceWithSyncMessageData:(NSData *)data shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation
{ {
return [self dataSourceWithData:data fileExtension:kSyncMessageFileExtension]; return [self dataSourceWithData:data
fileExtension:kSyncMessageFileExtension
shouldDeleteOnDeallocation:shouldDeleteOnDeallocation];
} }
+ (DataSource *)emptyDataSource + (DataSource *)emptyDataSource
{ {
return [self dataSourceWithData:[NSData new] fileExtension:@"bin"]; return [self dataSourceWithData:[NSData new] fileExtension:@"bin" shouldDeleteOnDeallocation:YES];
} }
- (NSData *)data - (NSData *)data
@ -269,7 +274,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
+ (nullable DataSource *)dataSourceWithURL:(NSURL *)fileUrl + (nullable DataSource *)dataSourceWithURL:(NSURL *)fileUrl shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation
{ {
OWSAssert(fileUrl); OWSAssert(fileUrl);
@ -278,10 +283,12 @@ NS_ASSUME_NONNULL_BEGIN
} }
DataSourcePath *instance = [DataSourcePath new]; DataSourcePath *instance = [DataSourcePath new];
instance.filePath = fileUrl.path; instance.filePath = fileUrl.path;
instance.shouldDeleteOnDeallocation = shouldDeleteOnDeallocation;
return instance; return instance;
} }
+ (nullable DataSource *)dataSourceWithFilePath:(NSString *)filePath + (nullable DataSource *)dataSourceWithFilePath:(NSString *)filePath
shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation
{ {
OWSAssert(filePath); OWSAssert(filePath);
@ -291,7 +298,7 @@ NS_ASSUME_NONNULL_BEGIN
DataSourcePath *instance = [DataSourcePath new]; DataSourcePath *instance = [DataSourcePath new];
instance.filePath = filePath; instance.filePath = filePath;
OWSAssert(!instance.shouldDeleteOnDeallocation); instance.shouldDeleteOnDeallocation = shouldDeleteOnDeallocation;
return instance; return instance;
} }

@ -634,15 +634,18 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
// NOTE: SharingThreadPickerViewController will try to unpack them // NOTE: SharingThreadPickerViewController will try to unpack them
// and send them as normal text messages if possible. // and send them as normal text messages if possible.
let urlString = url.absoluteString let urlString = url.absoluteString
return DataSourceValue.dataSource(withOversizeText: urlString) return DataSourceValue.dataSource(withOversizeText: urlString,
shouldDeleteOnDeallocation: true)
} else if UTTypeConformsTo(utiType as CFString, kUTTypeText) { } else if UTTypeConformsTo(utiType as CFString, kUTTypeText) {
// Share text as oversize text messages. // Share text as oversize text messages.
// //
// NOTE: SharingThreadPickerViewController will try to unpack them // NOTE: SharingThreadPickerViewController will try to unpack them
// and send them as normal text messages if possible. // and send them as normal text messages if possible.
return DataSourcePath.dataSource(with: url) return DataSourcePath.dataSource(with: url,
shouldDeleteOnDeallocation: false)
} else { } else {
guard let dataSource = DataSourcePath.dataSource(with: url) else { guard let dataSource = DataSourcePath.dataSource(with: url,
shouldDeleteOnDeallocation: false) else {
return nil return nil
} }

Loading…
Cancel
Save