From 899e96f70ff600f1ebe5e13ea8c7f0ae5e36b9ec Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 18 Jul 2018 14:25:30 -0400 Subject: [PATCH] Respond to CR. --- .../src/Contacts/SignalRecipient.m | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/SignalServiceKit/src/Contacts/SignalRecipient.m b/SignalServiceKit/src/Contacts/SignalRecipient.m index 93d40bbf1..2790e59ab 100644 --- a/SignalServiceKit/src/Contacts/SignalRecipient.m +++ b/SignalServiceKit/src/Contacts/SignalRecipient.m @@ -83,15 +83,6 @@ NS_ASSUME_NONNULL_BEGIN OWSAssert(transaction); OWSAssert(recipientId.length > 0); - return [self recipientForRecipientId:recipientId transaction:transaction]; -} - -+ (nullable instancetype)recipientForRecipientId:(NSString *)recipientId - transaction:(YapDatabaseReadTransaction *)transaction -{ - OWSAssert(transaction); - OWSAssert(recipientId.length > 0); - return [self fetchObjectWithUniqueID:recipientId transaction:transaction]; } @@ -101,7 +92,7 @@ NS_ASSUME_NONNULL_BEGIN __block SignalRecipient *recipient; [self.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { - recipient = [self recipientForRecipientId:recipientId transaction:transaction]; + recipient = [self registeredRecipientForRecipientId:recipientId transaction:transaction]; }]; return recipient; } @@ -189,6 +180,12 @@ NS_ASSUME_NONNULL_BEGIN - (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction { + // We only want to mutate the persisted SignalRecipients in the database + // using other methods of this class, e.g. markRecipientAsRegistered... + // to create, addDevices and removeDevices to mutate. We're trying to + // be strict about using persisted SignalRecipients as a cache to + // reflect "last known registration status". Forcing our codebase to + // use those methods helps ensure that we update the cache deliberately. OWSProdLogAndFail(@"%@ Don't call saveWithTransaction from outside this class.", self.logTag); [self saveWithTransaction_internal:transaction]; @@ -203,7 +200,7 @@ NS_ASSUME_NONNULL_BEGIN + (BOOL)isRegisteredRecipient:(NSString *)recipientId transaction:(YapDatabaseReadTransaction *)transaction { - SignalRecipient *_Nullable instance = [self recipientForRecipientId:recipientId transaction:transaction]; + SignalRecipient *_Nullable instance = [self registeredRecipientForRecipientId:recipientId transaction:transaction]; return instance != nil; } @@ -213,7 +210,7 @@ NS_ASSUME_NONNULL_BEGIN OWSAssert(transaction); OWSAssert(recipientId.length > 0); - SignalRecipient *_Nullable instance = [self recipientForRecipientId:recipientId transaction:transaction]; + SignalRecipient *_Nullable instance = [self registeredRecipientForRecipientId:recipientId transaction:transaction]; if (!instance) { DDLogDebug(@"%@ creating recipient: %@", self.logTag, recipientId); @@ -248,7 +245,7 @@ NS_ASSUME_NONNULL_BEGIN OWSAssert(transaction); OWSAssert(recipientId.length > 0); - SignalRecipient *_Nullable instance = [self recipientForRecipientId:recipientId transaction:transaction]; + SignalRecipient *_Nullable instance = [self registeredRecipientForRecipientId:recipientId transaction:transaction]; if (!instance) { return; }