Tidy files.

This commit is contained in:
Matthew Chen 2018-07-30 10:22:45 -04:00
parent ed47c0a6d1
commit 8f55f53329
9 changed files with 56 additions and 13 deletions

View file

@ -68,6 +68,7 @@ class ConversationConfigurationSyncOperation: OWSOperation {
self.dbConnection.readWrite { transaction in
let messageData: Data = syncMessage.buildPlainTextAttachmentData(with: transaction)
dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData)
dataSource?.setShouldDeleteOnDeallocation()
}
guard let attachmentDataSource = dataSource else {
@ -89,6 +90,7 @@ class ConversationConfigurationSyncOperation: OWSOperation {
self.dbConnection.read { transaction in
let messageData: Data = syncMessage.buildPlainTextAttachmentData(with: transaction)
dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData)
dataSource?.setShouldDeleteOnDeallocation()
}
guard let attachmentDataSource = dataSource else {

View file

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

View file

@ -3948,9 +3948,9 @@ typedef enum : NSUInteger {
if (newGroupModel.groupImage) {
NSData *data = UIImagePNGRepresentation(newGroupModel.groupImage);
DataSource *_Nullable dataSource = [DataSourceValue dataSourceWithData:data fileExtension:@"png"];
[self.messageSender enqueueAttachment:dataSource
[dataSource setShouldDeleteOnDeallocation];
[self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeImagePng
sourceFilename:nil
inMessage:message
success:^{
DDLogDebug(@"%@ Successfully sent group update with avatar", self.logTag);

View file

@ -104,6 +104,7 @@ NS_ASSUME_NONNULL_BEGIN
dataSource = [DataSourceValue
dataSourceWithSyncMessageData:[syncContactsMessage
buildPlainTextAttachmentDataWithTransaction:transaction]];
[dataSource setShouldDeleteOnDeallocation];
}];
[self.messageSender enqueueTemporaryAttachment:dataSource
@ -124,6 +125,7 @@ NS_ASSUME_NONNULL_BEGIN
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
dataSource = [DataSourceValue
dataSourceWithSyncMessageData:[syncGroupsMessage buildPlainTextAttachmentDataWithTransaction:transaction]];
[dataSource setShouldDeleteOnDeallocation];
}];
[self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeApplicationOctetStream

View file

@ -490,12 +490,12 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
NSData *data = UIImagePNGRepresentation(model.groupImage);
DataSource *_Nullable dataSource =
[DataSourceValue dataSourceWithData:data fileExtension:@"png"];
[self.messageSender enqueueAttachment:dataSource
contentType:OWSMimeTypeImagePng
sourceFilename:nil
inMessage:message
success:successHandler
failure:failureHandler];
[dataSource setShouldDeleteOnDeallocation];
[self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeImagePng
inMessage:message
success:successHandler
failure:failureHandler];
} else {
[self.messageSender enqueueMessage:message success:successHandler failure:failureHandler];
}

View file

@ -126,7 +126,7 @@ NSString *const kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
__block NSData *messageData;
__block NSData *lastMessageData;
[self.editingDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
[self.editingDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
messageData = [syncContactsMessage buildPlainTextAttachmentDataWithTransaction:transaction];
lastMessageData = [transaction objectForKey:kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
inCollection:kOWSPrimaryStorageOWSContactsSyncingCollection];
@ -140,6 +140,7 @@ NSString *const kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
self.isRequestInFlight = YES;
DataSource *dataSource = [DataSourceValue dataSourceWithSyncMessageData:messageData];
[dataSource setShouldDeleteOnDeallocation];
[self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeApplicationOctetStream
inMessage:syncContactsMessage

View file

@ -354,6 +354,41 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
return self;
}
- (void)dealloc
{
[self cleanUpTemporaryAttachmentsIfNecessary];
}
// Each message has the responsibility for eagerly cleaning up its attachments.
// Normally this is done in [TSMessage removeWithTransaction], but that doesn't
// apply for "transient", unsaved messages (i.e. shouldBeSaved == NO). These
// messages should clean up their attachments upon deallocation.
- (void)cleanUpTemporaryAttachmentsIfNecessary
{
if (self.shouldBeSaved) {
// Message in not transient; no need to clean up attachments.
return;
}
NSArray<NSString *> *_Nullable attachmentIds = self.attachmentIds;
if (attachmentIds.count < 1) {
return;
}
[self.dbReadWriteConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (NSString *attachmentId in attachmentIds) {
// We need to fetch each attachment, since [TSAttachment removeWithTransaction:] does important work.
TSAttachment *_Nullable attachment =
[TSAttachment fetchObjectWithUniqueID:attachmentId transaction:transaction];
if (!attachment) {
OWSCFail(@"%@ couldn't load interaction's attachment for deletion.", TSOutgoingMessage.logTag);
continue;
}
[attachment removeWithTransaction:transaction];
};
}];
}
#pragma mark -
- (TSOutgoingMessageState)messageState
{
TSOutgoingMessageState newMessageState =

View file

@ -658,6 +658,7 @@ NS_ASSUME_NONNULL_BEGIN
DataSource *dataSource = [DataSourceValue
dataSourceWithSyncMessageData:[syncContactsMessage
buildPlainTextAttachmentDataWithTransaction:transaction]];
[dataSource setShouldDeleteOnDeallocation];
[self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeApplicationOctetStream
inMessage:syncContactsMessage
@ -674,6 +675,7 @@ NS_ASSUME_NONNULL_BEGIN
DataSource *dataSource = [DataSourceValue
dataSourceWithSyncMessageData:[syncGroupsMessage
buildPlainTextAttachmentDataWithTransaction:transaction]];
[dataSource setShouldDeleteOnDeallocation];
[self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeApplicationOctetStream
inMessage:syncGroupsMessage
@ -825,9 +827,9 @@ NS_ASSUME_NONNULL_BEGIN
if (gThread.groupModel.groupImage) {
NSData *data = UIImagePNGRepresentation(gThread.groupModel.groupImage);
DataSource *_Nullable dataSource = [DataSourceValue dataSourceWithData:data fileExtension:@"png"];
[self.messageSender enqueueAttachment:dataSource
[dataSource setShouldDeleteOnDeallocation];
[self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeImagePng
sourceFilename:nil
inMessage:message
success:^{
DDLogDebug(@"%@ Successfully sent group update with avatar", self.logTag);

View file

@ -102,7 +102,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) NSString *fileExtension;
// This property is lazy-populated.
@property (nonatomic) NSString *cachedFilePath;
@property (nonatomic, nullable) NSString *cachedFilePath;
@end
@ -113,7 +113,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)dealloc
{
if (self.shouldDeleteOnDeallocation) {
NSString *filePath = self.cachedFilePath;
NSString *_Nullable filePath = self.cachedFilePath;
if (filePath) {
dispatch_async(dispatch_get_main_queue(), ^{
NSError *error;