More thread safety fixes.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 8fbc996bca
commit c3dca21a69

@ -363,16 +363,20 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
hasCheckedContentLength = YES; hasCheckedContentLength = YES;
} }
success:^(NSURLSessionDataTask *_Nonnull task, id _Nullable responseObject) { success:^(NSURLSessionDataTask *_Nonnull task, id _Nullable responseObject) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if (![responseObject isKindOfClass:[NSData class]]) { if (![responseObject isKindOfClass:[NSData class]]) {
DDLogError(@"%@ Failed retrieval of attachment. Response had unexpected format.", self.tag); DDLogError(@"%@ Failed retrieval of attachment. Response had unexpected format.", self.tag);
NSError *error = OWSErrorMakeUnableToProcessServerResponseError(); NSError *error = OWSErrorMakeUnableToProcessServerResponseError();
return failureHandler(task, error); return failureHandler(task, error);
} }
successHandler((NSData *)responseObject); successHandler((NSData *)responseObject);
});
} }
failure:^(NSURLSessionDataTask *_Nullable task, NSError *_Nonnull error) { failure:^(NSURLSessionDataTask *_Nullable task, NSError *_Nonnull error) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
DDLogError(@"Failed to retrieve attachment with error: %@", error.description); DDLogError(@"Failed to retrieve attachment with error: %@", error.description);
return failureHandler(task, error); return failureHandler(task, error);
});
}]; }];
} }

@ -18,6 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
- (NSString *)description; - (NSString *)description;
- (TSThread *)threadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
/** /**
* When an interaction is updated, it often affects the UI for it's containing thread. Touching it's thread will notify * When an interaction is updated, it often affects the UI for it's containing thread. Touching it's thread will notify
* any observers so they can redraw any related UI. * any observers so they can redraw any related UI.

@ -77,6 +77,11 @@ NS_ASSUME_NONNULL_BEGIN
return [TSThread fetchObjectWithUniqueID:self.uniqueThreadId]; return [TSThread fetchObjectWithUniqueID:self.uniqueThreadId];
} }
- (TSThread *)threadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
return [TSThread fetchObjectWithUniqueID:self.uniqueThreadId transaction:transaction];
}
- (void)touchThreadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction - (void)touchThreadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
TSThread *thread = [TSThread fetchObjectWithUniqueID:self.uniqueThreadId transaction:transaction]; TSThread *thread = [TSThread fetchObjectWithUniqueID:self.uniqueThreadId transaction:transaction];

@ -224,14 +224,16 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)becomeConsistentWithConfigurationForMessage:(TSMessage *)message + (void)becomeConsistentWithConfigurationForMessage:(TSMessage *)message
contactsManager:(id<ContactsManagerProtocol>)contactsManager contactsManager:(id<ContactsManagerProtocol>)contactsManager
{ {
dispatch_async(self.serialQueue, ^{
[[self sharedJob] becomeConsistentWithConfigurationForMessage:message contactsManager:contactsManager]; [[self sharedJob] becomeConsistentWithConfigurationForMessage:message contactsManager:contactsManager];
});
} }
- (void)becomeConsistentWithConfigurationForMessage:(TSMessage *)message - (void)becomeConsistentWithConfigurationForMessage:(TSMessage *)message
contactsManager:(id<ContactsManagerProtocol>)contactsManager contactsManager:(id<ContactsManagerProtocol>)contactsManager
{ {
OWSAssert(message);
OWSAssert(contactsManager);
dispatch_async(OWSDisappearingMessagesJob.serialQueue, ^{
// Become eventually consistent in the case that the remote changed their settings at the same time. // Become eventually consistent in the case that the remote changed their settings at the same time.
// Also in case remote doesn't support expiring messages // Also in case remote doesn't support expiring messages
OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration = OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration =
@ -249,8 +251,8 @@ NS_ASSUME_NONNULL_BEGIN
} }
} else if (message.expiresInSeconds != disappearingMessagesConfiguration.durationSeconds) { } else if (message.expiresInSeconds != disappearingMessagesConfiguration.durationSeconds) {
changed = YES; changed = YES;
DDLogInfo( DDLogInfo(@"%@ Received remote message with different expiration set, updating our expiration to become "
@"%@ Received remote message with different expiration set, updating our expiration to become consistent.", @"consistent.",
self.tag); self.tag);
disappearingMessagesConfiguration.enabled = YES; disappearingMessagesConfiguration.enabled = YES;
disappearingMessagesConfiguration.durationSeconds = message.expiresInSeconds; disappearingMessagesConfiguration.durationSeconds = message.expiresInSeconds;
@ -277,6 +279,7 @@ NS_ASSUME_NONNULL_BEGIN
configuration:disappearingMessagesConfiguration] configuration:disappearingMessagesConfiguration]
save]; save];
} }
});
} }
- (void)startIfNecessary - (void)startIfNecessary

@ -600,9 +600,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
success:(void (^)())successHandler success:(void (^)())successHandler
failure:(RetryableFailureHandler)failureHandler failure:(RetryableFailureHandler)failureHandler
{ {
dispatch_async([OWSDispatch sendingQueue], ^{
TSThread *thread = message.thread; TSThread *thread = message.thread;
dispatch_async([OWSDispatch sendingQueue], ^{
if ([thread isKindOfClass:[TSGroupThread class]]) { if ([thread isKindOfClass:[TSGroupThread class]]) {
TSGroupThread *gThread = (TSGroupThread *)thread; TSGroupThread *gThread = (TSGroupThread *)thread;

@ -470,7 +470,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
// Use timestampForSorting which reflects local sort order, rather than timestamp // Use timestampForSorting which reflects local sort order, rather than timestamp
// which reflect sender time. // which reflect sender time.
[self markAsReadBeforeTimestamp:message.timestampForSorting [self markAsReadBeforeTimestamp:message.timestampForSorting
thread:message.thread thread:[message threadWithTransaction:transaction]
wasLocal:NO wasLocal:NO
transaction:transaction]; transaction:transaction];
} }

Loading…
Cancel
Save