diff --git a/SignalServiceKit/src/Messages/OWSIdentityManager.h b/SignalServiceKit/src/Messages/OWSIdentityManager.h index aa3fe6ee5..d56e4f0e9 100644 --- a/SignalServiceKit/src/Messages/OWSIdentityManager.h +++ b/SignalServiceKit/src/Messages/OWSIdentityManager.h @@ -60,7 +60,8 @@ extern const NSUInteger kIdentityKeyLength; - (nullable OWSRecipientIdentity *)untrustedIdentityForSendingToRecipientId:(NSString *)recipientId; // This method can be called from any thread. -- (void)processIncomingSyncMessage:(OWSSignalServiceProtosVerified *)verified; +- (void)processIncomingSyncMessage:(OWSSignalServiceProtosVerified *)verified + transaction:(YapDatabaseReadWriteTransaction *)transaction; - (BOOL)saveRemoteIdentity:(NSData *)identityKey recipientId:(NSString *)recipientId; diff --git a/SignalServiceKit/src/Messages/OWSIdentityManager.m b/SignalServiceKit/src/Messages/OWSIdentityManager.m index 9887f057d..1a9715744 100644 --- a/SignalServiceKit/src/Messages/OWSIdentityManager.m +++ b/SignalServiceKit/src/Messages/OWSIdentityManager.m @@ -683,7 +683,11 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa } - (void)processIncomingSyncMessage:(OWSSignalServiceProtosVerified *)verified + transaction:(YapDatabaseReadWriteTransaction *)transaction { + OWSAssert(verified); + OWSAssert(transaction); + NSString *recipientId = verified.destination; if (recipientId.length < 1) { OWSFail(@"Verification state sync message missing recipientId."); @@ -698,32 +702,29 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa } NSData *identityKey = [rawIdentityKey removeKeyType]; - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction * transaction) { - switch (verified.state) { - case OWSSignalServiceProtosVerifiedStateDefault: - [self tryToApplyVerificationStateFromSyncMessage:OWSVerificationStateDefault - recipientId:recipientId - identityKey:identityKey - overwriteOnConflict:NO - transaction:transaction]; - break; - case OWSSignalServiceProtosVerifiedStateVerified: - [self tryToApplyVerificationStateFromSyncMessage:OWSVerificationStateVerified - recipientId:recipientId - identityKey:identityKey - overwriteOnConflict:YES - transaction:transaction]; - break; - case OWSSignalServiceProtosVerifiedStateUnverified: - OWSFail(@"Verification state sync message for recipientId: %@ has unexpected value: %@.", - recipientId, - OWSVerificationStateToString(OWSVerificationStateNoLongerVerified)); - return; - } - }]; - [self fireIdentityStateChangeNotification]; - }); + switch (verified.state) { + case OWSSignalServiceProtosVerifiedStateDefault: + [self tryToApplyVerificationStateFromSyncMessage:OWSVerificationStateDefault + recipientId:recipientId + identityKey:identityKey + overwriteOnConflict:NO + transaction:transaction]; + break; + case OWSSignalServiceProtosVerifiedStateVerified: + [self tryToApplyVerificationStateFromSyncMessage:OWSVerificationStateVerified + recipientId:recipientId + identityKey:identityKey + overwriteOnConflict:YES + transaction:transaction]; + break; + case OWSSignalServiceProtosVerifiedStateUnverified: + OWSFail(@"Verification state sync message for recipientId: %@ has unexpected value: %@.", + recipientId, + OWSVerificationStateToString(OWSVerificationStateNoLongerVerified)); + return; + } + + [self fireIdentityStateChangeNotification]; } - (void)tryToApplyVerificationStateFromSyncMessage:(OWSVerificationState)verificationState diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index 467022ebb..616754e59 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -699,7 +699,7 @@ NS_ASSUME_NONNULL_BEGIN transaction:transaction]; } else if (syncMessage.hasVerified) { DDLogInfo(@"%@ Received verification state for %@", self.logTag, syncMessage.verified.destination); - [self.identityManager processIncomingSyncMessage:syncMessage.verified]; + [self.identityManager processIncomingSyncMessage:syncMessage.verified transaction:transaction]; } else { DDLogWarn(@"%@ Ignoring unsupported sync message.", self.logTag); }