Respond to CR.

pull/1/head
Matthew Chen 7 years ago
parent bd0f601792
commit 862172072c

@ -524,7 +524,7 @@ typedef void (^CustomLayoutBlock)(void);
identityKey:self.identityKey
recipientId:self.recipientId
isUserInitiatedChange:YES
protocolContext:transaction];
transaction:transaction];
}];
[self dismissViewControllerAnimated:YES completion:nil];

@ -56,7 +56,7 @@ class SafetyNumberConfirmationAlert: NSObject {
Logger.info("\(self.TAG) Confirmed identity: \(untrustedIdentity)")
self.storageManager.newDatabaseConnection().asyncReadWrite { (transaction) in
OWSIdentityManager.shared().setVerificationState(.default, identityKey: untrustedIdentity.identityKey, recipientId: untrustedIdentity.recipientId, isUserInitiatedChange: true, protocolContext: transaction)
OWSIdentityManager.shared().setVerificationState(.default, identityKey: untrustedIdentity.identityKey, recipientId: untrustedIdentity.recipientId, isUserInitiatedChange: true, transaction: transaction)
DispatchQueue.main.async {
completion(true)
}

@ -405,14 +405,14 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion);
}
case OWSVerificationStateNoLongerVerified: {
DDLogInfo(@"%@ marked recipient: %@ as default verification status.", self.logTag, recipientId);
NSData *identityKey = [[OWSIdentityManager sharedManager] identityKeyForRecipientId:recipientId
protocolContext:transaction];
NSData *identityKey =
[[OWSIdentityManager sharedManager] identityKeyForRecipientId:recipientId transaction:transaction];
OWSAssert(identityKey);
[[OWSIdentityManager sharedManager] setVerificationState:OWSVerificationStateDefault
identityKey:identityKey
recipientId:recipientId
isUserInitiatedChange:YES
protocolContext:transaction];
transaction:transaction];
break;
}
}

@ -149,7 +149,10 @@ NS_ASSUME_NONNULL_BEGIN
// @note If this becomes a hotspot we can extract into a YapDB View.
// As is, the number of groups should be small (dozens, *maybe* hundreds), and we only enumerate them upon SN changes.
+ (NSArray<TSGroupThread *> *)groupThreadsWithRecipientId:(NSString *)recipientId
transaction:(YapDatabaseReadWriteTransaction *)transaction {
transaction:(YapDatabaseReadWriteTransaction *)transaction
{
OWSAssert(recipientId.length > 0);
OWSAssert(transaction);
NSMutableArray<TSGroupThread *> *groupThreads = [NSMutableArray new];

@ -32,13 +32,14 @@ extern const NSUInteger kIdentityKeyLength;
- (nullable NSData *)identityKeyForRecipientId:(NSString *)recipientId;
- (nullable NSData *)identityKeyForRecipientId:(NSString *)recipientId protocolContext:(nullable id)protocolContext;
- (nullable NSData *)identityKeyForRecipientId:(NSString *)recipientId
transaction:(YapDatabaseReadTransaction *)transaction;
- (void)setVerificationState:(OWSVerificationState)verificationState
identityKey:(NSData *)identityKey
recipientId:(NSString *)recipientId
isUserInitiatedChange:(BOOL)isUserInitiatedChange
protocolContext:(nullable id)protocolContext;
transaction:(YapDatabaseReadWriteTransaction *)transaction;
- (OWSVerificationState)verificationStateForRecipientId:(NSString *)recipientId;
- (OWSVerificationState)verificationStateForRecipientId:(NSString *)recipientId

@ -131,21 +131,11 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
{
__block NSData *_Nullable result = nil;
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
result = [self identityKeyForRecipientId:recipientId protocolContext:transaction];
result = [self identityKeyForRecipientId:recipientId transaction:transaction];
}];
return result;
}
- (nullable NSData *)identityKeyForRecipientId:(NSString *)recipientId protocolContext:(nullable id)protocolContext
{
OWSAssert(recipientId.length > 0);
OWSAssert([protocolContext isKindOfClass:[YapDatabaseReadWriteTransaction class]]);
YapDatabaseReadWriteTransaction *transaction = protocolContext;
return [self identityKeyForRecipientId:recipientId protocolContext:transaction];
}
- (nullable NSData *)identityKeyForRecipientId:(NSString *)recipientId
transaction:(YapDatabaseReadTransaction *)transaction
{
@ -158,8 +148,8 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
- (nullable ECKeyPair *)identityKeyPair
{
__block ECKeyPair *_Nullable identityKeyPair = nil;
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
identityKeyPair = [self identityKeyPair:transaction];
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
identityKeyPair = [self identityKeyPairWithTransaction:transaction];
}];
return identityKeyPair;
}
@ -170,6 +160,13 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
YapDatabaseReadWriteTransaction *transaction = protocolContext;
return [self identityKeyPairWithTransaction:transaction];
}
- (nullable ECKeyPair *)identityKeyPairWithTransaction:(YapDatabaseReadTransaction *)transaction
{
OWSAssert(transaction);
ECKeyPair *_Nullable identityKeyPair = [transaction keyPairForKey:TSStorageManagerIdentityKeyStoreIdentityKey
inCollection:TSStorageManagerIdentityKeyStoreCollection];
return identityKeyPair;
@ -359,7 +356,6 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
- (OWSVerificationState)verificationStateForRecipientId:(NSString *)recipientId
{
__block OWSVerificationState result;
// Use a read/write transaction to block on latest.
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
result = [self verificationStateForRecipientId:recipientId transaction:transaction];
}];
@ -388,8 +384,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
OWSAssert(recipientId.length > 0);
__block OWSRecipientIdentity *_Nullable result;
// Use a read/write transaction to block on latest.
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
result = [OWSRecipientIdentity fetchObjectWithUniqueID:recipientId transaction:transaction];
}];
return result;
@ -400,8 +395,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
OWSAssert(recipientId.length > 0);
__block OWSRecipientIdentity *_Nullable result;
// Use a read/write transaction to block on latest.
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
OWSRecipientIdentity *_Nullable recipientIdentity =
[OWSRecipientIdentity fetchObjectWithUniqueID:recipientId transaction:transaction];
@ -413,7 +407,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
BOOL isTrusted = [self isTrustedIdentityKey:recipientIdentity.identityKey
recipientId:recipientId
direction:TSMessageDirectionOutgoing
protocolContext:transaction];
transaction:transaction];
if (isTrusted) {
return;
} else {
@ -442,10 +436,23 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
YapDatabaseReadWriteTransaction *transaction = protocolContext;
return [self isTrustedIdentityKey:identityKey recipientId:recipientId direction:direction transaction:transaction];
}
- (BOOL)isTrustedIdentityKey:(NSData *)identityKey
recipientId:(NSString *)recipientId
direction:(TSMessageDirection)direction
transaction:(YapDatabaseReadTransaction *)transaction
{
OWSAssert(identityKey.length == kStoredIdentityKeyLength);
OWSAssert(recipientId.length > 0);
OWSAssert(direction != TSMessageDirectionUnknown);
OWSAssert(transaction);
@synchronized(self)
{
if ([[TSAccountManager localNumber] isEqualToString:recipientId]) {
ECKeyPair *_Nullable localIdentityKeyPair = [self identityKeyPair:protocolContext];
ECKeyPair *_Nullable localIdentityKeyPair = [self identityKeyPair:transaction];
if ([localIdentityKeyPair.publicKey isEqualToData:identityKey]) {
return YES;
@ -573,7 +580,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
@synchronized(self)
{
NSMutableArray<NSString *> *recipientIds = [NSMutableArray new];
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[transaction enumerateKeysAndObjectsInCollection:OWSIdentityManager_QueuedVerificationStateSyncMessages
usingBlock:^(NSString *_Nonnull recipientId,
id _Nonnull object,

Loading…
Cancel
Save