Tidy files.

This commit is contained in:
Matthew Chen 2018-07-30 10:56:19 -04:00
parent 2c19474397
commit e6bc37d941
14 changed files with 98 additions and 80 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -370,7 +370,8 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
}
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.")
return
}

View File

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

View File

@ -519,7 +519,7 @@ public class SignalAttachment: NSObject {
owsFail("\(logTag) Missing expected pasteboard data for UTI: \(dataUTI)")
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.
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)")
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)
}
}
@ -540,7 +540,7 @@ public class SignalAttachment: NSObject {
owsFail("\(logTag) Missing expected pasteboard data for UTI: \(dataUTI)")
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)
}
}
@ -550,7 +550,7 @@ public class SignalAttachment: NSObject {
owsFail("\(logTag) Missing expected pasteboard data for UTI: \(dataUTI)")
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)
}
@ -723,7 +723,7 @@ public class SignalAttachment: NSObject {
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
return attachment
}
@ -892,7 +892,7 @@ public class SignalAttachment: NSObject {
}
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
return attachment
}
@ -980,7 +980,8 @@ public class SignalAttachment: NSObject {
let baseFilename = dataSource.sourceFilename
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")
let attachment = SignalAttachment(dataSource: DataSourceValue.emptyDataSource(), dataUTI: dataUTI)
attachment.error = .couldNotConvertToMpeg4
@ -988,7 +989,6 @@ public class SignalAttachment: NSObject {
return
}
dataSource.setShouldDeleteOnDeallocation()
dataSource.sourceFilename = mp4Filename
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.
// Check the attachment's error property.
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,
dataUTI: kOversizeTextAttachmentUTI,
validUTISet: nil,

View File

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

View File

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

View File

@ -29,10 +29,6 @@ NS_ASSUME_NONNULL_BEGIN
// Returns YES on success.
- (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;
@end
@ -41,13 +37,19 @@ NS_ASSUME_NONNULL_BEGIN
@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;
@ -57,9 +59,10 @@ NS_ASSUME_NONNULL_BEGIN
@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

View File

@ -60,11 +60,6 @@ NS_ASSUME_NONNULL_BEGIN
return NO;
}
- (void)setShouldDeleteOnDeallocation
{
self.shouldDeleteOnDeallocation = YES;
}
- (BOOL)isValidImage
{
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);
@ -137,35 +134,43 @@ NS_ASSUME_NONNULL_BEGIN
DataSourceValue *instance = [DataSourceValue new];
instance.dataValue = data;
instance.fileExtension = fileExtension;
// Always try to clean up temp files created by this instance.
[instance setShouldDeleteOnDeallocation];
instance.shouldDeleteOnDeallocation = shouldDeleteOnDeallocation;
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];
return [self dataSourceWithData:data fileExtension:fileExtension];
return [self dataSourceWithData:data
fileExtension:fileExtension
shouldDeleteOnDeallocation:shouldDeleteOnDeallocation];
}
+ (nullable DataSource *)dataSourceWithOversizeText:(NSString *_Nullable)text
shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation
{
if (!text) {
return nil;
}
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
{
return [self dataSourceWithData:[NSData new] fileExtension:@"bin"];
return [self dataSourceWithData:[NSData new] fileExtension:@"bin" shouldDeleteOnDeallocation:YES];
}
- (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);
@ -278,10 +283,12 @@ NS_ASSUME_NONNULL_BEGIN
}
DataSourcePath *instance = [DataSourcePath new];
instance.filePath = fileUrl.path;
instance.shouldDeleteOnDeallocation = shouldDeleteOnDeallocation;
return instance;
}
+ (nullable DataSource *)dataSourceWithFilePath:(NSString *)filePath
shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation
{
OWSAssert(filePath);
@ -291,7 +298,7 @@ NS_ASSUME_NONNULL_BEGIN
DataSourcePath *instance = [DataSourcePath new];
instance.filePath = filePath;
OWSAssert(!instance.shouldDeleteOnDeallocation);
instance.shouldDeleteOnDeallocation = shouldDeleteOnDeallocation;
return instance;
}

View File

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