Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 616041c0fb
commit c871e2de3e

@ -214,9 +214,14 @@ NSString *const kTSStorageManager_AccountLastNames = @"kTSStorageManager_Account
{ {
OWSAssert([NSThread isMainThread]); OWSAssert([NSThread isMainThread]);
NSMutableDictionary<NSString *, NSString *> *cachedAccountNameMap = [NSMutableDictionary new]; // Preserve any existing values, so that contacts that have been removed
NSMutableDictionary<NSString *, NSString *> *cachedFirstNameMap = [NSMutableDictionary new]; // from system contacts still show up properly in the app.
NSMutableDictionary<NSString *, NSString *> *cachedLastNameMap = [NSMutableDictionary new]; NSMutableDictionary<NSString *, NSString *> *cachedAccountNameMap
= (self.cachedAccountNameMap ? [self.cachedAccountNameMap mutableCopy] : [NSMutableDictionary new]);
NSMutableDictionary<NSString *, NSString *> *cachedFirstNameMap
= (self.cachedFirstNameMap ? [self.cachedFirstNameMap mutableCopy] : [NSMutableDictionary new]);
NSMutableDictionary<NSString *, NSString *> *cachedLastNameMap
= (self.cachedLastNameMap ? [self.cachedLastNameMap mutableCopy] : [NSMutableDictionary new]);
for (SignalAccount *signalAccount in self.signalAccounts) { for (SignalAccount *signalAccount in self.signalAccounts) {
NSString *baseName NSString *baseName
= (signalAccount.contact.fullName.length > 0 ? signalAccount.contact.fullName : signalAccount.recipientId); = (signalAccount.contact.fullName.length > 0 ? signalAccount.contact.fullName : signalAccount.recipientId);
@ -292,6 +297,13 @@ NSString *const kTSStorageManager_AccountLastNames = @"kTSStorageManager_Account
}]; }];
}]; }];
if (self.cachedAccountNameMap || self.cachedFirstNameMap || self.cachedLastNameMap) {
// If these properties have already been populated from system contacts,
// don't overwrite. In practice this should never happen.
OWSAssert(0);
return;
}
self.cachedAccountNameMap = [cachedAccountNameMap copy]; self.cachedAccountNameMap = [cachedAccountNameMap copy];
self.cachedFirstNameMap = [cachedFirstNameMap copy]; self.cachedFirstNameMap = [cachedFirstNameMap copy];
self.cachedLastNameMap = [cachedLastNameMap copy]; self.cachedLastNameMap = [cachedLastNameMap copy];
@ -300,21 +312,21 @@ NSString *const kTSStorageManager_AccountLastNames = @"kTSStorageManager_Account
- (NSString *_Nullable)cachedDisplayNameForRecipientId:(NSString *)recipientId - (NSString *_Nullable)cachedDisplayNameForRecipientId:(NSString *)recipientId
{ {
OWSAssert(recipientId.lastPathComponent > 0); OWSAssert(recipientId.length > 0);
return self.cachedAccountNameMap[recipientId]; return self.cachedAccountNameMap[recipientId];
} }
- (NSString *_Nullable)cachedFirstNameForRecipientId:(NSString *)recipientId - (NSString *_Nullable)cachedFirstNameForRecipientId:(NSString *)recipientId
{ {
OWSAssert(recipientId.lastPathComponent > 0); OWSAssert(recipientId.length > 0);
return self.cachedFirstNameMap[recipientId]; return self.cachedFirstNameMap[recipientId];
} }
- (NSString *_Nullable)cachedLastNameForRecipientId:(NSString *)recipientId - (NSString *_Nullable)cachedLastNameForRecipientId:(NSString *)recipientId
{ {
OWSAssert(recipientId.lastPathComponent > 0); OWSAssert(recipientId.length > 0);
return self.cachedLastNameMap[recipientId]; return self.cachedLastNameMap[recipientId];
} }

Loading…
Cancel
Save