Avoid deadlock in profile manager.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago committed by Michael Kirk
parent b2ee64e701
commit 44051bd7e7

@ -243,42 +243,44 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
OWSAssert([userProfile isEqual:userProfileCopy]); OWSAssert([userProfile isEqual:userProfileCopy]);
} }
// Make sure to save on the local db connection for consistency. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { // Make sure to save on the local db connection for consistency.
[userProfileCopy saveWithTransaction:transaction]; [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
}]; [userProfileCopy saveWithTransaction:transaction];
}];
BOOL isLocalUserProfile = userProfile == self.localUserProfile; BOOL isLocalUserProfile = userProfile == self.localUserProfile;
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if (isLocalUserProfile) { if (isLocalUserProfile) {
// We populate an initial (empty) profile on launch of a new install, but until // We populate an initial (empty) profile on launch of a new install, but until
// we have a registered account, syncing will fail (and there could not be any // we have a registered account, syncing will fail (and there could not be any
// linked device to sync to at this point anyway). // linked device to sync to at this point anyway).
if ([TSAccountManager isRegistered]) { if ([TSAccountManager isRegistered]) {
[MultiDeviceProfileKeyUpdateJob runWithProfileKey:userProfile.profileKey [MultiDeviceProfileKeyUpdateJob runWithProfileKey:userProfile.profileKey
identityManager:self.identityManager identityManager:self.identityManager
messageSender:self.messageSender messageSender:self.messageSender
profileManager:self]; profileManager:self];
} }
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:kNSNotificationName_LocalProfileDidChange [[NSNotificationCenter defaultCenter] postNotificationNameAsync:kNSNotificationName_LocalProfileDidChange
object:nil object:nil
userInfo:nil]; userInfo:nil];
} else { } else {
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
postNotificationNameAsync:kNSNotificationName_OtherUsersProfileWillChange postNotificationNameAsync:kNSNotificationName_OtherUsersProfileWillChange
object:nil object:nil
userInfo:@{ userInfo:@{
kNSNotificationKey_ProfileRecipientId : userProfile.recipientId, kNSNotificationKey_ProfileRecipientId : userProfile.recipientId,
}]; }];
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
postNotificationNameAsync:kNSNotificationName_OtherUsersProfileDidChange postNotificationNameAsync:kNSNotificationName_OtherUsersProfileDidChange
object:nil object:nil
userInfo:@{ userInfo:@{
kNSNotificationKey_ProfileRecipientId : userProfile.recipientId, kNSNotificationKey_ProfileRecipientId : userProfile.recipientId,
}]; }];
} }
});
}); });
} }

Loading…
Cancel
Save