return unseen identity rather than bool

This turns out to be more versitile for the client app

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent e10cc0c180
commit ebd4800e21

@ -42,10 +42,11 @@ extern NSString *const TSStorageManagerTrustedKeysCollection;
/** /**
* @param recipientId unique stable identifier for the recipient, e.g. e164 phone number * @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) * @returns nil if the recipient's current id has been seen, or if it's the users first key
* NO if the recipient's current id has been seen, or if it's the users first key * else returns the unseen identity
*
*/ */
- (BOOL)hasUnseenIdentityChangeForRecipientId:(NSString *)recipientId; - (nullable OWSRecipientIdentity *)unseenIdentityChangeForRecipientId:(NSString *)recipientId;
- (void)generateNewIdentityKey; - (void)generateNewIdentityKey;
- (nullable NSData *)identityKeyForRecipientId:(NSString *)recipientId; - (nullable NSData *)identityKeyForRecipientId:(NSString *)recipientId;

@ -199,6 +199,31 @@ const NSTimeInterval kIdentityKeyStoreNonBlockingSecondsThreshold = 5.0;
} }
} }
- (nullable OWSRecipientIdentity *)unseenIdentityChangeForRecipientId:(NSString *)recipientId
{
OWSAssert(recipientId != nil);
@synchronized([[self class] sharedIdentityKeyLock])
{
OWSRecipientIdentity *currentIdentity = [OWSRecipientIdentity fetchObjectWithUniqueID:recipientId];
if (currentIdentity == nil) {
// No preexisting key, Trust On First Use
return nil;
}
if (currentIdentity.isFirstKnownKey) {
return nil;
}
if (currentIdentity.wasSeen) {
return nil;
}
// identity not yet seen
return currentIdentity;
}
}
- (BOOL)isTrustedKey:(NSData *)identityKey forSendingToIdentity:(nullable OWSRecipientIdentity *)recipientIdentity - (BOOL)isTrustedKey:(NSData *)identityKey forSendingToIdentity:(nullable OWSRecipientIdentity *)recipientIdentity
{ {
OWSAssert(identityKey != nil); OWSAssert(identityKey != nil);
@ -278,24 +303,6 @@ 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 @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

Loading…
Cancel
Save