|
|
@ -23,6 +23,7 @@
|
|
|
|
#import "TSStorageManager.h"
|
|
|
|
#import "TSStorageManager.h"
|
|
|
|
#import "TextSecureKitEnv.h"
|
|
|
|
#import "TextSecureKitEnv.h"
|
|
|
|
#import "YapDatabaseConnection+OWS.h"
|
|
|
|
#import "YapDatabaseConnection+OWS.h"
|
|
|
|
|
|
|
|
#import "YapDatabaseReadTransaction+OWS.h"
|
|
|
|
#import <AxolotlKit/NSData+keyVersionByte.h>
|
|
|
|
#import <AxolotlKit/NSData+keyVersionByte.h>
|
|
|
|
#import <Curve25519Kit/Curve25519.h>
|
|
|
|
#import <Curve25519Kit/Curve25519.h>
|
|
|
|
#import <YapDatabase/YapDatabase.h>
|
|
|
|
#import <YapDatabase/YapDatabase.h>
|
|
|
@ -55,9 +56,11 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
@interface OWSIdentityManager ()
|
|
|
|
@interface OWSIdentityManager ()
|
|
|
|
|
|
|
|
|
|
|
|
@property (nonatomic, readonly) TSStorageManager *storageManager;
|
|
|
|
@property (nonatomic, readonly) TSStorageManager *storageManager;
|
|
|
|
@property (nonatomic, readonly) YapDatabaseConnection *dbConnection;
|
|
|
|
|
|
|
|
@property (nonatomic, readonly) OWSMessageSender *messageSender;
|
|
|
|
@property (nonatomic, readonly) OWSMessageSender *messageSender;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Should we get rid of this property?
|
|
|
|
|
|
|
|
@property (nonatomic, readonly) YapDatabaseConnection *dbConnection;
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark -
|
|
|
@ -136,12 +139,12 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
|
|
|
|
|
|
|
|
YapDatabaseReadWriteTransaction *transaction = protocolContext;
|
|
|
|
YapDatabaseReadWriteTransaction *transaction = protocolContext;
|
|
|
|
|
|
|
|
|
|
|
|
return [OWSRecipientIdentity fetchObjectWithUniqueID:recipientId].identityKey;
|
|
|
|
return [OWSRecipientIdentity fetchObjectWithUniqueID:recipientId transaction:transaction].identityKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (nullable ECKeyPair *)identityKeyPairWithoutProtocolContext
|
|
|
|
- (nullable ECKeyPair *)identityKeyPairWithoutProtocolContext
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ECKeyPair *_Nullable identityKeyPair = nil;
|
|
|
|
__block ECKeyPair *_Nullable identityKeyPair = nil;
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
|
|
|
identityKeyPair = [self identityKeyPair:transaction];
|
|
|
|
identityKeyPair = [self identityKeyPair:transaction];
|
|
|
|
}];
|
|
|
|
}];
|
|
|
@ -154,15 +157,19 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
|
|
|
|
|
|
|
|
YapDatabaseReadWriteTransaction *transaction = protocolContext;
|
|
|
|
YapDatabaseReadWriteTransaction *transaction = protocolContext;
|
|
|
|
|
|
|
|
|
|
|
|
ECKeyPair *_Nullable identityKeyPair = [self.dbConnection keyPairForKey:TSStorageManagerIdentityKeyStoreIdentityKey
|
|
|
|
ECKeyPair *_Nullable identityKeyPair = [transaction keyPairForKey:TSStorageManagerIdentityKeyStoreIdentityKey
|
|
|
|
inCollection:TSStorageManagerIdentityKeyStoreCollection];
|
|
|
|
inCollection:TSStorageManagerIdentityKeyStoreCollection];
|
|
|
|
return identityKeyPair;
|
|
|
|
return identityKeyPair;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//- (int)localRegistrationId
|
|
|
|
- (int)localRegistrationId:(nullable id)protocolContext
|
|
|
|
//{
|
|
|
|
{
|
|
|
|
// return (int)[TSAccountManager getOrGenerateRegistrationId];
|
|
|
|
OWSAssert([protocolContext isKindOfClass:[YapDatabaseReadWriteTransaction class]]);
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
YapDatabaseReadWriteTransaction *transaction = protocolContext;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (int)[TSAccountManager getOrGenerateRegistrationId:transaction];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (BOOL)saveRemoteIdentity:(NSData *)identityKey
|
|
|
|
- (BOOL)saveRemoteIdentity:(NSData *)identityKey
|
|
|
|
recipientId:(NSString *)recipientId
|
|
|
|
recipientId:(NSString *)recipientId
|
|
|
@ -228,7 +235,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
[self.storageManager archiveAllSessionsForContact:recipientId protocolContext:protocolContext];
|
|
|
|
[self.storageManager archiveAllSessionsForContact:recipientId protocolContext:protocolContext];
|
|
|
|
|
|
|
|
|
|
|
|
// Cancel any pending verification state sync messages for this recipient.
|
|
|
|
// Cancel any pending verification state sync messages for this recipient.
|
|
|
|
[self clearSyncMessageForRecipientId:recipientId];
|
|
|
|
[self clearSyncMessageForRecipientId:recipientId transaction:transaction];
|
|
|
|
|
|
|
|
|
|
|
|
[self fireIdentityStateChangeNotification];
|
|
|
|
[self fireIdentityStateChangeNotification];
|
|
|
|
|
|
|
|
|
|
|
@ -242,17 +249,21 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
identityKey:(NSData *)identityKey
|
|
|
|
identityKey:(NSData *)identityKey
|
|
|
|
recipientId:(NSString *)recipientId
|
|
|
|
recipientId:(NSString *)recipientId
|
|
|
|
isUserInitiatedChange:(BOOL)isUserInitiatedChange
|
|
|
|
isUserInitiatedChange:(BOOL)isUserInitiatedChange
|
|
|
|
|
|
|
|
protocolContext:(nullable id)protocolContext
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OWSAssert(identityKey.length == kStoredIdentityKeyLength);
|
|
|
|
OWSAssert(identityKey.length == kStoredIdentityKeyLength);
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
|
|
|
|
OWSAssert([protocolContext isKindOfClass:[YapDatabaseReadWriteTransaction class]]);
|
|
|
|
|
|
|
|
|
|
|
|
@synchronized(self)
|
|
|
|
YapDatabaseReadWriteTransaction *transaction = protocolContext;
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Remove all @synchronized
|
|
|
|
// Ensure a remote identity exists for this key. We may be learning about
|
|
|
|
// Ensure a remote identity exists for this key. We may be learning about
|
|
|
|
// it for the first time.
|
|
|
|
// it for the first time.
|
|
|
|
[self saveRemoteIdentity:identityKey recipientId:recipientId protocolContext:protocolContext];
|
|
|
|
[self saveRemoteIdentity:identityKey recipientId:recipientId protocolContext:protocolContext];
|
|
|
|
|
|
|
|
|
|
|
|
OWSRecipientIdentity *recipientIdentity = [OWSRecipientIdentity fetchObjectWithUniqueID:recipientId];
|
|
|
|
OWSRecipientIdentity *recipientIdentity =
|
|
|
|
|
|
|
|
[OWSRecipientIdentity fetchObjectWithUniqueID:recipientId transaction:transaction];
|
|
|
|
|
|
|
|
|
|
|
|
if (recipientIdentity == nil) {
|
|
|
|
if (recipientIdentity == nil) {
|
|
|
|
OWSFail(@"Missing expected identity: %@", recipientId);
|
|
|
|
OWSFail(@"Missing expected identity: %@", recipientId);
|
|
|
@ -269,27 +280,40 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
OWSVerificationStateToString(recipientIdentity.verificationState),
|
|
|
|
OWSVerificationStateToString(recipientIdentity.verificationState),
|
|
|
|
OWSVerificationStateToString(verificationState));
|
|
|
|
OWSVerificationStateToString(verificationState));
|
|
|
|
|
|
|
|
|
|
|
|
[recipientIdentity updateWithVerificationState:verificationState];
|
|
|
|
[recipientIdentity updateWithVerificationState:verificationState transaction:transaction];
|
|
|
|
|
|
|
|
|
|
|
|
if (isUserInitiatedChange) {
|
|
|
|
if (isUserInitiatedChange) {
|
|
|
|
[self saveChangeMessagesForRecipientId:recipientId verificationState:verificationState isLocalChange:YES];
|
|
|
|
[self saveChangeMessagesForRecipientId:recipientId
|
|
|
|
[self enqueueSyncMessageForVerificationStateForRecipientId:recipientId];
|
|
|
|
verificationState:verificationState
|
|
|
|
|
|
|
|
isLocalChange:YES
|
|
|
|
|
|
|
|
transaction:transaction];
|
|
|
|
|
|
|
|
[self enqueueSyncMessageForVerificationStateForRecipientId:recipientId transaction:transaction];
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Cancel any pending verification state sync messages for this recipient.
|
|
|
|
// Cancel any pending verification state sync messages for this recipient.
|
|
|
|
[self clearSyncMessageForRecipientId:recipientId];
|
|
|
|
[self clearSyncMessageForRecipientId:recipientId transaction:transaction];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[self fireIdentityStateChangeNotification];
|
|
|
|
[self fireIdentityStateChangeNotification];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (OWSVerificationState)verificationStateForRecipientId:(NSString *)recipientId
|
|
|
|
- (OWSVerificationState)verificationStateForRecipientId:(NSString *)recipientId
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
__block OWSVerificationState result;
|
|
|
|
|
|
|
|
// Use a read/write transaction to block on latest.
|
|
|
|
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
|
|
|
|
|
|
|
result = [self verificationStateForRecipientId:recipientId transaction:transaction];
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (OWSVerificationState)verificationStateForRecipientId:(NSString *)recipientId
|
|
|
|
|
|
|
|
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
|
|
|
|
OWSAssert(transaction);
|
|
|
|
|
|
|
|
|
|
|
|
@synchronized(self)
|
|
|
|
OWSRecipientIdentity *_Nullable currentIdentity =
|
|
|
|
{
|
|
|
|
[OWSRecipientIdentity fetchObjectWithUniqueID:recipientId transaction:transaction];
|
|
|
|
OWSRecipientIdentity *_Nullable currentIdentity = [OWSRecipientIdentity fetchObjectWithUniqueID:recipientId];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!currentIdentity) {
|
|
|
|
if (!currentIdentity) {
|
|
|
|
// We might not know the identity for this recipient yet.
|
|
|
|
// We might not know the identity for this recipient yet.
|
|
|
@ -297,17 +321,18 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return currentIdentity.verificationState;
|
|
|
|
return currentIdentity.verificationState;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (nullable OWSRecipientIdentity *)recipientIdentityForRecipientId:(NSString *)recipientId
|
|
|
|
- (nullable OWSRecipientIdentity *)recipientIdentityForRecipientId:(NSString *)recipientId
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
|
|
|
|
|
|
|
|
@synchronized(self)
|
|
|
|
__block OWSRecipientIdentity *_Nullable result;
|
|
|
|
{
|
|
|
|
// Use a read/write transaction to block on latest.
|
|
|
|
return [OWSRecipientIdentity fetchObjectWithUniqueID:recipientId];
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
|
|
|
}
|
|
|
|
result = [OWSRecipientIdentity fetchObjectWithUniqueID:recipientId transaction:transaction];
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (nullable OWSRecipientIdentity *)untrustedIdentityForSendingToRecipientId:(NSString *)recipientId
|
|
|
|
- (nullable OWSRecipientIdentity *)untrustedIdentityForSendingToRecipientId:(NSString *)recipientId
|
|
|
@ -318,9 +343,8 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
|
|
|
|
|
|
|
|
YapDatabaseReadWriteTransaction *transaction = protocolContext;
|
|
|
|
YapDatabaseReadWriteTransaction *transaction = protocolContext;
|
|
|
|
|
|
|
|
|
|
|
|
@synchronized(self)
|
|
|
|
OWSRecipientIdentity *_Nullable recipientIdentity =
|
|
|
|
{
|
|
|
|
[OWSRecipientIdentity fetchObjectWithUniqueID:recipientId transaction:transaction];
|
|
|
|
OWSRecipientIdentity *_Nullable recipientIdentity = [OWSRecipientIdentity fetchObjectWithUniqueID:recipientId];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (recipientIdentity == nil) {
|
|
|
|
if (recipientIdentity == nil) {
|
|
|
|
// trust on first use
|
|
|
|
// trust on first use
|
|
|
@ -336,7 +360,6 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return recipientIdentity;
|
|
|
|
return recipientIdentity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)fireIdentityStateChangeNotification
|
|
|
|
- (void)fireIdentityStateChangeNotification
|
|
|
@ -361,13 +384,15 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
@synchronized(self)
|
|
|
|
@synchronized(self)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ([[TSAccountManager localNumber] isEqualToString:recipientId]) {
|
|
|
|
if ([[TSAccountManager localNumber] isEqualToString:recipientId]) {
|
|
|
|
if ([[self identityKeyPair].publicKey isEqualToData:identityKey]) {
|
|
|
|
ECKeyPair *_Nullable localIdentityKeyPair = [self identityKeyPair:protocolContext];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ([localIdentityKeyPair.publicKey isEqualToData:identityKey]) {
|
|
|
|
return YES;
|
|
|
|
return YES;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
OWSFail(@"%@ Wrong identity: %@ for local key: %@, recipientId: %@",
|
|
|
|
OWSFail(@"%@ Wrong identity: %@ for local key: %@, recipientId: %@",
|
|
|
|
self.logTag,
|
|
|
|
self.logTag,
|
|
|
|
identityKey,
|
|
|
|
identityKey,
|
|
|
|
[self identityKeyPair].publicKey,
|
|
|
|
localIdentityKeyPair.publicKey,
|
|
|
|
recipientId);
|
|
|
|
recipientId);
|
|
|
|
return NO;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -378,7 +403,8 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
return YES;
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case TSMessageDirectionOutgoing: {
|
|
|
|
case TSMessageDirectionOutgoing: {
|
|
|
|
OWSRecipientIdentity *existingIdentity = [OWSRecipientIdentity fetchObjectWithUniqueID:recipientId];
|
|
|
|
OWSRecipientIdentity *existingIdentity =
|
|
|
|
|
|
|
|
[OWSRecipientIdentity fetchObjectWithUniqueID:recipientId transaction:transaction];
|
|
|
|
return [self isTrustedKey:identityKey forSendingToIdentity:existingIdentity];
|
|
|
|
return [self isTrustedKey:identityKey forSendingToIdentity:existingIdentity];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
default: {
|
|
|
@ -393,8 +419,6 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OWSAssert(identityKey.length == kStoredIdentityKeyLength);
|
|
|
|
OWSAssert(identityKey.length == kStoredIdentityKeyLength);
|
|
|
|
|
|
|
|
|
|
|
|
@synchronized(self)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (recipientIdentity == nil) {
|
|
|
|
if (recipientIdentity == nil) {
|
|
|
|
return YES;
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -429,7 +453,6 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
recipientIdentity.recipientId);
|
|
|
|
recipientIdentity.recipientId);
|
|
|
|
return NO;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)createIdentityChangeInfoMessageForRecipientId:(NSString *)recipientId
|
|
|
|
- (void)createIdentityChangeInfoMessageForRecipientId:(NSString *)recipientId
|
|
|
@ -460,21 +483,18 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)enqueueSyncMessageForVerificationStateForRecipientId:(NSString *)recipientId
|
|
|
|
- (void)enqueueSyncMessageForVerificationStateForRecipientId:(NSString *)recipientId
|
|
|
|
|
|
|
|
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
|
|
|
|
OWSAssert(transaction);
|
|
|
|
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
|
[transaction setObject:recipientId
|
|
|
|
@synchronized(self)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
[self.dbConnection setObject:recipientId
|
|
|
|
|
|
|
|
forKey:recipientId
|
|
|
|
forKey:recipientId
|
|
|
|
inCollection:OWSIdentityManager_QueuedVerificationStateSyncMessages];
|
|
|
|
inCollection:OWSIdentityManager_QueuedVerificationStateSyncMessages];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[self tryToSyncQueuedVerificationStates];
|
|
|
|
[self tryToSyncQueuedVerificationStates];
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)tryToSyncQueuedVerificationStates
|
|
|
|
- (void)tryToSyncQueuedVerificationStates
|
|
|
@ -544,10 +564,12 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Keep converting.
|
|
|
|
- (void)sendSyncVerificationStateMessage:(OWSVerificationStateSyncMessage *)message
|
|
|
|
- (void)sendSyncVerificationStateMessage:(OWSVerificationStateSyncMessage *)message
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OWSAssert(message);
|
|
|
|
OWSAssert(message);
|
|
|
|
OWSAssert(message.verificationForRecipientId.length > 0);
|
|
|
|
OWSAssert(message.verificationForRecipientId.length > 0);
|
|
|
|
|
|
|
|
OWSAssertIsOnMainThread();
|
|
|
|
|
|
|
|
|
|
|
|
TSContactThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:message.verificationForRecipientId];
|
|
|
|
TSContactThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:message.verificationForRecipientId];
|
|
|
|
|
|
|
|
|
|
|
@ -738,7 +760,10 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
|
|
|
|
|
|
|
|
[recipientIdentity updateWithVerificationState:verificationState];
|
|
|
|
[recipientIdentity updateWithVerificationState:verificationState];
|
|
|
|
|
|
|
|
|
|
|
|
[self saveChangeMessagesForRecipientId:recipientId verificationState:verificationState isLocalChange:NO];
|
|
|
|
[self saveChangeMessagesForRecipientId:recipientId
|
|
|
|
|
|
|
|
verificationState:verificationState
|
|
|
|
|
|
|
|
isLocalChange:NO
|
|
|
|
|
|
|
|
transaction:transaction];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -748,12 +773,15 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
- (void)saveChangeMessagesForRecipientId:(NSString *)recipientId
|
|
|
|
- (void)saveChangeMessagesForRecipientId:(NSString *)recipientId
|
|
|
|
verificationState:(OWSVerificationState)verificationState
|
|
|
|
verificationState:(OWSVerificationState)verificationState
|
|
|
|
isLocalChange:(BOOL)isLocalChange
|
|
|
|
isLocalChange:(BOOL)isLocalChange
|
|
|
|
|
|
|
|
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
|
|
|
|
OWSAssert(transaction);
|
|
|
|
|
|
|
|
|
|
|
|
NSMutableArray<TSMessage *> *messages = [NSMutableArray new];
|
|
|
|
NSMutableArray<TSMessage *> *messages = [NSMutableArray new];
|
|
|
|
|
|
|
|
|
|
|
|
TSContactThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:recipientId];
|
|
|
|
TSContactThread *contactThread =
|
|
|
|
|
|
|
|
[TSContactThread getOrCreateThreadWithContactId:recipientId transaction:transaction];
|
|
|
|
OWSAssert(contactThread);
|
|
|
|
OWSAssert(contactThread);
|
|
|
|
[messages addObject:[[OWSVerificationStateChangeMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
|
|
|
[messages addObject:[[OWSVerificationStateChangeMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
|
|
|
thread:contactThread
|
|
|
|
thread:contactThread
|
|
|
@ -761,7 +789,8 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
verificationState:verificationState
|
|
|
|
verificationState:verificationState
|
|
|
|
isLocalChange:isLocalChange]];
|
|
|
|
isLocalChange:isLocalChange]];
|
|
|
|
|
|
|
|
|
|
|
|
for (TSGroupThread *groupThread in [TSGroupThread groupThreadsWithRecipientId:recipientId]) {
|
|
|
|
for (TSGroupThread *groupThread in
|
|
|
|
|
|
|
|
[TSGroupThread groupThreadsWithRecipientId:recipientId transaction:transaction]) {
|
|
|
|
[messages
|
|
|
|
[messages
|
|
|
|
addObject:[[OWSVerificationStateChangeMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
|
|
|
addObject:[[OWSVerificationStateChangeMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
|
|
|
thread:groupThread
|
|
|
|
thread:groupThread
|
|
|
@ -770,11 +799,9 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|
|
|
isLocalChange:isLocalChange]];
|
|
|
|
isLocalChange:isLocalChange]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
|
|
|
|
for (TSMessage *message in messages) {
|
|
|
|
for (TSMessage *message in messages) {
|
|
|
|
[message saveWithTransaction:transaction];
|
|
|
|
[message saveWithTransaction:transaction];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - Debug
|
|
|
|
#pragma mark - Debug
|
|
|
|