From e10cc0c1803c598a7518b6c8b28195e20f0eb12e Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Wed, 31 May 2017 11:30:05 -0700 Subject: [PATCH] determine if recipient identity change is unseen // FREEBIE --- .../TSStorageManager+IdentityKeyStore.h | 7 +++++++ .../TSStorageManager+IdentityKeyStore.m | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Storage/AxolotlStore/TSStorageManager+IdentityKeyStore.h b/src/Storage/AxolotlStore/TSStorageManager+IdentityKeyStore.h index 841d7997a..0244f7b03 100644 --- a/src/Storage/AxolotlStore/TSStorageManager+IdentityKeyStore.h +++ b/src/Storage/AxolotlStore/TSStorageManager+IdentityKeyStore.h @@ -40,6 +40,13 @@ extern NSString *const TSStorageManagerTrustedKeysCollection; */ - (nullable OWSRecipientIdentity *)unconfirmedIdentityThatShouldBlockSendingForRecipientId:(NSString *)recipientId; +/** + * @param recipientId unique stable identifier for the recipient, e.g. e164 phone number + * @returns YES if the recipient's id has not been marked as seen (and it's not a TOFU situation) + * NO if the recipient's current id has been seen, or if it's the users first key + */ +- (BOOL)hasUnseenIdentityChangeForRecipientId:(NSString *)recipientId; + - (void)generateNewIdentityKey; - (nullable NSData *)identityKeyForRecipientId:(NSString *)recipientId; - (void)removeIdentityKeyForRecipient:(NSString *)receipientId; diff --git a/src/Storage/AxolotlStore/TSStorageManager+IdentityKeyStore.m b/src/Storage/AxolotlStore/TSStorageManager+IdentityKeyStore.m index c6ee65256..925e09567 100644 --- a/src/Storage/AxolotlStore/TSStorageManager+IdentityKeyStore.m +++ b/src/Storage/AxolotlStore/TSStorageManager+IdentityKeyStore.m @@ -278,6 +278,24 @@ const NSTimeInterval kIdentityKeyStoreNonBlockingSecondsThreshold = 5.0; } } + +- (BOOL)hasUnseenIdentityChangeForRecipientId:(NSString *)recipientId +{ + OWSAssert(recipientId != nil); + + OWSRecipientIdentity *recipientIdentity = [OWSRecipientIdentity fetchObjectWithUniqueID:recipientId]; + + if (!recipientIdentity) { + return NO; + } + + if (recipientIdentity.isFirstKnownKey) { + return NO; + } + + return !recipientIdentity.wasSeen; +} + @end NS_ASSUME_NONNULL_END