Fix the "is contact" test.

// FREEBIE
pull/1/head
Matthew Chen 7 years ago committed by Michael Kirk
parent 2ddde6617e
commit 50ec55c313

@ -423,8 +423,8 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
name:kNSNotificationName_ProfileWhitelistDidChange
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(signalAccountsDidChange:)
name:OWSContactsManagerSignalAccountsDidChangeNotification
selector:@selector(contactsDidChange:)
name:OWSContactsManagerContactListDidChangeNotification
object:nil];
}
@ -446,7 +446,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil];
}
- (void)signalAccountsDidChange:(NSNotification *)notification
- (void)contactsDidChange:(NSNotification *)notification
{
OWSAssert([NSThread isMainThread]);

@ -8,6 +8,9 @@
NS_ASSUME_NONNULL_BEGIN
extern NSString *const OWSContactsManagerSignalAccountsDidChangeNotification;
// Fired when the list of contact phone numbers changes, not when
// other contact properties change.
extern NSString *const OWSContactsManagerContactListDidChangeNotification;
@class ImageCache;
@class SignalAccount;

@ -17,7 +17,9 @@
@import Contacts;
NSString *const OWSContactsManagerSignalAccountsDidChangeNotification =
@"OWSContactsManagerSignalAccountsDidChangeNotification";
@"OWSContactsManagerSignalAccountsDidChangeNotification";
NSString *const OWSContactsManagerContactListDidChangeNotification =
@"OWSContactsManagerContactListDidChangeNotification";
NSString *const kTSStorageManager_AccountDisplayNames = @"kTSStorageManager_AccountDisplayNames";
NSString *const kTSStorageManager_AccountFirstNames = @"kTSStorageManager_AccountFirstNames";
@ -53,6 +55,7 @@ NSString *const kTSStorageManager_AccountLastNames = @"kTSStorageManager_Account
// TODO: We need to configure the limits of this cache.
_avatarCache = [ImageCache new];
_allContacts = @[];
_allContactsMap = @{};
_signalAccountMap = @{};
_signalAccounts = @[];
_systemContactsFetcher = [SystemContactsFetcher new];
@ -175,6 +178,8 @@ NSString *const kTSStorageManager_AccountLastNames = @"kTSStorageManager_Account
}
dispatch_async(dispatch_get_main_queue(), ^{
BOOL didContactListChange = ![self.allContactsMap isEqual:allContactsMap];
self.allContacts = contacts;
self.allContactsMap = [allContactsMap copy];
@ -185,6 +190,12 @@ NSString *const kTSStorageManager_AccountLastNames = @"kTSStorageManager_Account
[self updateSignalAccounts];
[self updateCachedDisplayNames];
if (didContactListChange) {
[[NSNotificationCenter defaultCenter]
postNotificationNameAsync:OWSContactsManagerContactListDidChangeNotification
object:nil];
}
});
});
}

@ -385,8 +385,8 @@ NS_ASSUME_NONNULL_BEGIN
shouldHaveAddToProfileWhitelistOffer = NO;
}
SignalAccount *signalAccount = contactsManager.signalAccountMap[recipientId];
if (signalAccount) {
BOOL isContact = contactsManager.allContactsMap[recipientId] != nil;
if (isContact) {
// Only create "add to contacts" offers for non-contacts.
shouldHaveAddToContactsOffer = NO;
// Only create block offers for non-contacts.

Loading…
Cancel
Save