diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 6531cc68f..ebc7cdaf7 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -44,7 +44,6 @@ #import "UIViewController+Permissions.h" #import "ViewControllerUtils.h" #import -#import #import #import #import diff --git a/Signal/src/ViewControllers/ThreadSettings/ShowGroupMembersViewController.m b/Signal/src/ViewControllers/ThreadSettings/ShowGroupMembersViewController.m index 975834a9c..b5fa90582 100644 --- a/Signal/src/ViewControllers/ThreadSettings/ShowGroupMembersViewController.m +++ b/Signal/src/ViewControllers/ThreadSettings/ShowGroupMembersViewController.m @@ -6,7 +6,6 @@ #import "Signal-Swift.h" #import "SignalApp.h" #import "ViewControllerUtils.h" -#import #import #import #import diff --git a/SignalMessaging/contacts/OWSContactsManager.m b/SignalMessaging/contacts/OWSContactsManager.m index 96a3dc6b2..7cda1c4fa 100644 --- a/SignalMessaging/contacts/OWSContactsManager.m +++ b/SignalMessaging/contacts/OWSContactsManager.m @@ -19,6 +19,7 @@ #import #import +@import AddressBook; @import Contacts; NSString *const OWSContactsManagerSignalAccountsDidChangeNotification diff --git a/SignalServiceKit/src/Contacts/Contact.h b/SignalServiceKit/src/Contacts/Contact.h index 449f7f0c0..f0205c48d 100644 --- a/SignalServiceKit/src/Contacts/Contact.h +++ b/SignalServiceKit/src/Contacts/Contact.h @@ -1,8 +1,7 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // -#import #import NS_ASSUME_NONNULL_BEGIN @@ -16,8 +15,8 @@ NS_ASSUME_NONNULL_BEGIN @class CNContact; @class PhoneNumber; -@class UIImage; @class SignalRecipient; +@class UIImage; @class YapDatabaseReadTransaction; @interface Contact : MTLModel @@ -34,7 +33,6 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) BOOL isSignalContact; #if TARGET_OS_IOS @property (nullable, readonly, nonatomic) UIImage *image; -@property (readonly, nonatomic) ABRecordID recordID; @property (nullable, nonatomic, readonly) CNContact *cnContact; #endif // TARGET_OS_IOS @@ -44,12 +42,6 @@ NS_ASSUME_NONNULL_BEGIN #if TARGET_OS_IOS -- (instancetype)initWithFirstName:(nullable NSString *)firstName - lastName:(nullable NSString *)lastName - userTextPhoneNumbers:(NSArray *)phoneNumbers - imageData:(nullable NSData *)imageData - contactID:(ABRecordID)record; - - (instancetype)initWithSystemContact:(CNContact *)contact NS_AVAILABLE_IOS(9_0); - (NSString *)nameForPhoneNumber:(NSString *)recipientId; diff --git a/SignalServiceKit/src/Contacts/Contact.m b/SignalServiceKit/src/Contacts/Contact.m index 35f2d0d5f..74fd195dc 100644 --- a/SignalServiceKit/src/Contacts/Contact.m +++ b/SignalServiceKit/src/Contacts/Contact.m @@ -24,36 +24,11 @@ NS_ASSUME_NONNULL_BEGIN @implementation Contact -@synthesize fullName = _fullName; @synthesize comparableNameFirstLast = _comparableNameFirstLast; @synthesize comparableNameLastFirst = _comparableNameLastFirst; @synthesize image = _image; #if TARGET_OS_IOS -- (instancetype)initWithFirstName:(nullable NSString *)firstName - lastName:(nullable NSString *)lastName - userTextPhoneNumbers:(NSArray *)phoneNumbers - imageData:(nullable NSData *)imageData - contactID:(ABRecordID)record -{ - self = [super init]; - if (!self) { - return self; - } - - _firstName = [self trimName:firstName]; - _lastName = [self trimName:lastName]; - _uniqueId = [self.class uniqueIdFromABRecordId:record]; - _recordID = record; - _userTextPhoneNumbers = phoneNumbers; - _phoneNumberNameMap = [NSMutableDictionary new]; - _parsedPhoneNumbers = [self parsedPhoneNumbersFromUserTextPhoneNumbers:phoneNumbers phoneNumberNameMap:@{}]; - _imageData = imageData; - // Not using emails for old AB style contacts. - _emails = [NSMutableArray new]; - - return self; -} - (instancetype)initWithSystemContact:(CNContact *)contact { @@ -65,6 +40,7 @@ NS_ASSUME_NONNULL_BEGIN _cnContact = contact; _firstName = [self trimName:contact.givenName]; _lastName = [self trimName:contact.familyName]; + _fullName = [CNContactFormatter stringFromContact:contact style:CNContactFormatterStyleFullName]; _uniqueId = contact.identifier; NSMutableArray *phoneNumbers = [NSMutableArray new]; @@ -129,7 +105,7 @@ NS_ASSUME_NONNULL_BEGIN _emails = [emailAddresses copy]; if (contact.thumbnailImageData) { - _imageData = contact.thumbnailImageData; + _imageData = [contact.thumbnailImageData copy]; } return self; @@ -154,11 +130,6 @@ NS_ASSUME_NONNULL_BEGIN return [name stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; } -+ (NSString *)uniqueIdFromABRecordId:(ABRecordID)recordId -{ - return [NSString stringWithFormat:@"ABRecordId:%d", recordId]; -} - + (MTLPropertyStorage)storageBehaviorForPropertyWithKey:(NSString *)propertyKey { if ([propertyKey isEqualToString:@"cnContact"] || [propertyKey isEqualToString:@"image"]) { @@ -193,18 +164,6 @@ NS_ASSUME_NONNULL_BEGIN return [parsedPhoneNumbers sortedArrayUsingSelector:@selector(compare:)]; } -- (NSString *)fullName { - if (_fullName == nil) { - if (ABPersonGetCompositeNameFormat() == kABPersonCompositeNameFormatFirstNameFirst) { - _fullName = [self combineLeftName:_firstName withRightName:_lastName usingSeparator:@" "]; - } else { - _fullName = [self combineLeftName:_lastName withRightName:_firstName usingSeparator:@" "]; - } - } - - return _fullName; -} - - (NSString *)comparableNameFirstLast { if (_comparableNameFirstLast == nil) { // Combine the two names with a tab separator, which has a lower ascii code than space, so that first names @@ -312,16 +271,14 @@ NS_ASSUME_NONNULL_BEGIN hash = hash ^ self.fullName.hash; - // base thumbnailHash is some arbitrary number - NSUInteger thumbnailHash = 389201946; - if (self.cnContact.thumbnailImageData) { + if (self.imageData) { + NSUInteger thumbnailHash = 0; NSData *thumbnailHashData = - [Cryptography computeSHA256Digest:self.cnContact.thumbnailImageData truncatedToBytes:sizeof(thumbnailHash)]; + [Cryptography computeSHA256Digest:self.imageData truncatedToBytes:sizeof(thumbnailHash)]; [thumbnailHashData getBytes:&thumbnailHash length:sizeof(thumbnailHash)]; + hash = hash ^ thumbnailHash; } - hash = hash ^ thumbnailHash; - for (PhoneNumber *phoneNumber in self.parsedPhoneNumbers) { hash = hash ^ phoneNumber.toE164.hash; }