From dfc39b4a1d7cc114345e95b67058b6458dc93ce5 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 30 Jul 2018 11:00:56 -0400 Subject: [PATCH] Tidy files. --- ...nversationConfigurationSyncOperation.swift | 4 ++-- .../Jobs/MultiDeviceProfileKeyUpdateJob.swift | 3 +-- .../ConversationViewController.m | 11 ++++------ .../ViewControllers/DebugUI/DebugUIMessages.m | 12 ++++------- .../DebugUI/DebugUISyncMessages.m | 7 +++---- .../ViewControllers/NewGroupViewController.m | 5 ++--- .../attachments/SignalAttachment.swift | 14 ++++++------- SignalMessaging/contacts/OWSContactsSyncing.m | 3 +-- .../src/Messages/OWSMessageManager.m | 9 +++----- SignalServiceKit/src/Util/DataSource.h | 14 ++++--------- SignalServiceKit/src/Util/DataSource.m | 21 ++++++------------- .../ShareViewController.swift | 3 +-- 12 files changed, 38 insertions(+), 68 deletions(-) diff --git a/Signal/src/Jobs/ConversationConfigurationSyncOperation.swift b/Signal/src/Jobs/ConversationConfigurationSyncOperation.swift index 3565ece84..6c7681073 100644 --- a/Signal/src/Jobs/ConversationConfigurationSyncOperation.swift +++ b/Signal/src/Jobs/ConversationConfigurationSyncOperation.swift @@ -67,7 +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, shouldDeleteOnDeallocation: true) + dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData) } guard let attachmentDataSource = dataSource else { @@ -88,7 +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, shouldDeleteOnDeallocation: true) + dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData) } guard let attachmentDataSource = dataSource else { diff --git a/Signal/src/Jobs/MultiDeviceProfileKeyUpdateJob.swift b/Signal/src/Jobs/MultiDeviceProfileKeyUpdateJob.swift index d976bd922..c8f3df93e 100644 --- a/Signal/src/Jobs/MultiDeviceProfileKeyUpdateJob.swift +++ b/Signal/src/Jobs/MultiDeviceProfileKeyUpdateJob.swift @@ -50,8 +50,7 @@ import SignalMessaging var dataSource: DataSource? = nil self.editingDatabaseConnection.readWrite { transaction in - dataSource = DataSourceValue.dataSource(withSyncMessageData: syncContactsMessage.buildPlainTextAttachmentData(with: transaction), - shouldDeleteOnDeallocation: true) + dataSource = DataSourceValue.dataSource(withSyncMessageData: syncContactsMessage.buildPlainTextAttachmentData(with: transaction)) } guard let attachmentDataSource = dataSource else { diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 5f6b20ff9..d8df0518c 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -3099,9 +3099,8 @@ typedef enum : NSUInteger { } OWSAssertIsOnMainThread(); - DataSource *_Nullable dataSource = [DataSourceValue dataSourceWithData:imageData - utiType:dataUTI - shouldDeleteOnDeallocation:YES]; + DataSource *_Nullable dataSource = + [DataSourceValue dataSourceWithData:imageData utiType:dataUTI]; [dataSource setSourceFilename:filename]; SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource dataUTI:dataUTI @@ -3940,8 +3939,7 @@ typedef enum : NSUInteger { if (newGroupModel.groupImage) { NSData *data = UIImagePNGRepresentation(newGroupModel.groupImage); - DataSource *_Nullable dataSource = - [DataSourceValue dataSourceWithData:data fileExtension:@"png" shouldDeleteOnDeallocation:YES]; + DataSource *_Nullable dataSource = [DataSourceValue dataSourceWithData:data fileExtension:@"png"]; [self.messageSender enqueueTemporaryAttachment:dataSource contentType:OWSMimeTypeImagePng inMessage:message @@ -4433,8 +4431,7 @@ typedef enum : NSUInteger { TSOutgoingMessage *message; if ([text lengthOfBytesUsingEncoding:NSUTF8StringEncoding] >= kOversizeTextMessageSizeThreshold) { - DataSource *_Nullable dataSource = - [DataSourceValue dataSourceWithOversizeText:text shouldDeleteOnDeallocation:YES]; + DataSource *_Nullable dataSource = [DataSourceValue dataSourceWithOversizeText:text]; 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 diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m index 32d30c8f5..7648b91c8 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m @@ -3324,8 +3324,7 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac { OWSMessageSender *messageSender = [Environment current].messageSender; NSString *message = [self randomOversizeText]; - DataSource *_Nullable dataSource = - [DataSourceValue dataSourceWithOversizeText:message shouldDeleteOnDeallocation:YES]; + DataSource *_Nullable dataSource = [DataSourceValue dataSourceWithOversizeText:message]; SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource dataUTI:kOversizeTextAttachmentUTI]; [ThreadUtil sendMessageWithAttachment:attachment @@ -3355,9 +3354,8 @@ 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 - shouldDeleteOnDeallocation:YES]; + DataSource *_Nullable dataSource = + [DataSourceValue dataSourceWithData:[self createRandomNSDataOfSize:length] utiType:uti]; SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource dataUTI:uti imageQuality:TSImageQualityOriginal]; @@ -4364,9 +4362,7 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac NSString *utiType = (NSString *)kUTTypeData; const NSUInteger kDataLength = 32; DataSource *_Nullable dataSource = - [DataSourceValue dataSourceWithData:[self createRandomNSDataOfSize:kDataLength] - utiType:utiType - shouldDeleteOnDeallocation:YES]; + [DataSourceValue dataSourceWithData:[self createRandomNSDataOfSize:kDataLength] utiType:utiType]; [dataSource setSourceFilename:filename]; SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType imageQuality:TSImageQualityOriginal]; diff --git a/Signal/src/ViewControllers/DebugUI/DebugUISyncMessages.m b/Signal/src/ViewControllers/DebugUI/DebugUISyncMessages.m index b14e095f8..3cf600cef 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUISyncMessages.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUISyncMessages.m @@ -102,8 +102,8 @@ NS_ASSUME_NONNULL_BEGIN __block DataSource *dataSource; [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { dataSource = [DataSourceValue - dataSourceWithSyncMessageData:[syncContactsMessage buildPlainTextAttachmentDataWithTransaction:transaction] - shouldDeleteOnDeallocation:YES]; + dataSourceWithSyncMessageData:[syncContactsMessage + buildPlainTextAttachmentDataWithTransaction:transaction]]; }]; [self.messageSender enqueueTemporaryAttachment:dataSource @@ -123,8 +123,7 @@ NS_ASSUME_NONNULL_BEGIN __block DataSource *dataSource; [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { dataSource = [DataSourceValue - dataSourceWithSyncMessageData:[syncGroupsMessage buildPlainTextAttachmentDataWithTransaction:transaction] - shouldDeleteOnDeallocation:YES]; + dataSourceWithSyncMessageData:[syncGroupsMessage buildPlainTextAttachmentDataWithTransaction:transaction]]; }]; [self.messageSender enqueueTemporaryAttachment:dataSource contentType:OWSMimeTypeApplicationOctetStream diff --git a/Signal/src/ViewControllers/NewGroupViewController.m b/Signal/src/ViewControllers/NewGroupViewController.m index 70ccc4845..26d7681f4 100644 --- a/Signal/src/ViewControllers/NewGroupViewController.m +++ b/Signal/src/ViewControllers/NewGroupViewController.m @@ -488,9 +488,8 @@ 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" - shouldDeleteOnDeallocation:YES]; + DataSource *_Nullable dataSource = + [DataSourceValue dataSourceWithData:data fileExtension:@"png"]; [self.messageSender enqueueTemporaryAttachment:dataSource contentType:OWSMimeTypeImagePng inMessage:message diff --git a/SignalMessaging/attachments/SignalAttachment.swift b/SignalMessaging/attachments/SignalAttachment.swift index ba6020853..1382e5385 100644 --- a/SignalMessaging/attachments/SignalAttachment.swift +++ b/SignalMessaging/attachments/SignalAttachment.swift @@ -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, shouldDeleteOnDeallocation: false) + let dataSource = DataSourceValue.dataSource(with: data, utiType: dataUTI) // 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, shouldDeleteOnDeallocation: false) + let dataSource = DataSourceValue.dataSource(with: data, utiType: dataUTI) 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, shouldDeleteOnDeallocation: false) + let dataSource = DataSourceValue.dataSource(with: data, utiType: dataUTI) 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, shouldDeleteOnDeallocation: false) + let dataSource = DataSourceValue.dataSource(with: data, utiType: dataUTI) 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", shouldDeleteOnDeallocation: false) else { + guard let dataSource = DataSourceValue.dataSource(with: jpgImageData, fileExtension: "jpg") 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, shouldDeleteOnDeallocation: false) else { + guard let dataSource = DataSourceValue.dataSource(with: mutableData as Data, utiType: attachment.dataUTI) else { attachment.error = .couldNotRemoveMetadata return attachment } @@ -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, shouldDeleteOnDeallocation: false) + let dataSource = DataSourceValue.dataSource(withOversizeText: text) return newAttachment(dataSource: dataSource, dataUTI: kOversizeTextAttachmentUTI, validUTISet: nil, diff --git a/SignalMessaging/contacts/OWSContactsSyncing.m b/SignalMessaging/contacts/OWSContactsSyncing.m index efc9aaca4..dbd5f4fd0 100644 --- a/SignalMessaging/contacts/OWSContactsSyncing.m +++ b/SignalMessaging/contacts/OWSContactsSyncing.m @@ -139,8 +139,7 @@ NSString *const kOWSPrimaryStorageOWSContactsSyncingLastMessageKey self.isRequestInFlight = YES; - DataSource *dataSource = - [DataSourceValue dataSourceWithSyncMessageData:messageData shouldDeleteOnDeallocation:YES]; + DataSource *dataSource = [DataSourceValue dataSourceWithSyncMessageData:messageData]; [self.messageSender enqueueTemporaryAttachment:dataSource contentType:OWSMimeTypeApplicationOctetStream inMessage:syncContactsMessage diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index d46089d3a..db16d84bd 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -657,8 +657,7 @@ NS_ASSUME_NONNULL_BEGIN profileManager:self.profileManager]; DataSource *dataSource = [DataSourceValue dataSourceWithSyncMessageData:[syncContactsMessage - buildPlainTextAttachmentDataWithTransaction:transaction] - shouldDeleteOnDeallocation:YES]; + buildPlainTextAttachmentDataWithTransaction:transaction]]; [self.messageSender enqueueTemporaryAttachment:dataSource contentType:OWSMimeTypeApplicationOctetStream inMessage:syncContactsMessage @@ -674,8 +673,7 @@ NS_ASSUME_NONNULL_BEGIN OWSSyncGroupsMessage *syncGroupsMessage = [[OWSSyncGroupsMessage alloc] init]; DataSource *dataSource = [DataSourceValue dataSourceWithSyncMessageData:[syncGroupsMessage - buildPlainTextAttachmentDataWithTransaction:transaction] - shouldDeleteOnDeallocation:YES]; + buildPlainTextAttachmentDataWithTransaction:transaction]]; [self.messageSender enqueueTemporaryAttachment:dataSource contentType:OWSMimeTypeApplicationOctetStream inMessage:syncGroupsMessage @@ -826,8 +824,7 @@ NS_ASSUME_NONNULL_BEGIN if (gThread.groupModel.groupImage) { NSData *data = UIImagePNGRepresentation(gThread.groupModel.groupImage); - DataSource *_Nullable dataSource = - [DataSourceValue dataSourceWithData:data fileExtension:@"png" shouldDeleteOnDeallocation:YES]; + DataSource *_Nullable dataSource = [DataSourceValue dataSourceWithData:data fileExtension:@"png"]; [self.messageSender enqueueTemporaryAttachment:dataSource contentType:OWSMimeTypeImagePng inMessage:message diff --git a/SignalServiceKit/src/Util/DataSource.h b/SignalServiceKit/src/Util/DataSource.h index c2fe276b7..74ba0fc25 100755 --- a/SignalServiceKit/src/Util/DataSource.h +++ b/SignalServiceKit/src/Util/DataSource.h @@ -37,19 +37,13 @@ NS_ASSUME_NONNULL_BEGIN @interface DataSourceValue : DataSource -+ (nullable DataSource *)dataSourceWithData:(NSData *)data - fileExtension:(NSString *)fileExtension - shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation; ++ (nullable DataSource *)dataSourceWithData:(NSData *)data fileExtension:(NSString *)fileExtension; -+ (nullable DataSource *)dataSourceWithData:(NSData *)data - utiType:(NSString *)utiType - shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation; ++ (nullable DataSource *)dataSourceWithData:(NSData *)data utiType:(NSString *)utiType; -+ (nullable DataSource *)dataSourceWithOversizeText:(NSString *_Nullable)text - shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation; ++ (nullable DataSource *)dataSourceWithOversizeText:(NSString *_Nullable)text; -+ (DataSource *)dataSourceWithSyncMessageData:(NSData *)data - shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation; ++ (DataSource *)dataSourceWithSyncMessageData:(NSData *)data; + (DataSource *)emptyDataSource; diff --git a/SignalServiceKit/src/Util/DataSource.m b/SignalServiceKit/src/Util/DataSource.m index 65a08efb0..fcebd4511 100755 --- a/SignalServiceKit/src/Util/DataSource.m +++ b/SignalServiceKit/src/Util/DataSource.m @@ -123,7 +123,6 @@ NS_ASSUME_NONNULL_BEGIN + (nullable DataSource *)dataSourceWithData:(NSData *)data fileExtension:(NSString *)fileExtension - shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation { OWSAssert(data); @@ -134,43 +133,35 @@ NS_ASSUME_NONNULL_BEGIN DataSourceValue *instance = [DataSourceValue new]; instance.dataValue = data; instance.fileExtension = fileExtension; - instance.shouldDeleteOnDeallocation = shouldDeleteOnDeallocation; + instance.shouldDeleteOnDeallocation = YES; return instance; } + (nullable DataSource *)dataSourceWithData:(NSData *)data utiType:(NSString *)utiType - shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation { NSString *fileExtension = [MIMETypeUtil fileExtensionForUTIType:utiType]; - return [self dataSourceWithData:data - fileExtension:fileExtension - shouldDeleteOnDeallocation:shouldDeleteOnDeallocation]; + return [self dataSourceWithData:data fileExtension:fileExtension]; } + (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 - shouldDeleteOnDeallocation:shouldDeleteOnDeallocation]; + return [self dataSourceWithData:data fileExtension:kOversizeTextAttachmentFileExtension]; } -+ (DataSource *)dataSourceWithSyncMessageData:(NSData *)data shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation ++ (DataSource *)dataSourceWithSyncMessageData:(NSData *)data { - return [self dataSourceWithData:data - fileExtension:kSyncMessageFileExtension - shouldDeleteOnDeallocation:shouldDeleteOnDeallocation]; + return [self dataSourceWithData:data fileExtension:kSyncMessageFileExtension]; } + (DataSource *)emptyDataSource { - return [self dataSourceWithData:[NSData new] fileExtension:@"bin" shouldDeleteOnDeallocation:YES]; + return [self dataSourceWithData:[NSData new] fileExtension:@"bin"]; } - (NSData *)data diff --git a/SignalShareExtension/ShareViewController.swift b/SignalShareExtension/ShareViewController.swift index 7af487377..932aa22e3 100644 --- a/SignalShareExtension/ShareViewController.swift +++ b/SignalShareExtension/ShareViewController.swift @@ -634,8 +634,7 @@ 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, - shouldDeleteOnDeallocation: true) + return DataSourceValue.dataSource(withOversizeText: urlString) } else if UTTypeConformsTo(utiType as CFString, kUTTypeText) { // Share text as oversize text messages. //