Merge branch 'charlesmchen/contactsCrash'

pull/1/head
Matthew Chen 7 years ago
commit 371b247b4f

@ -44,7 +44,6 @@
#import "UIViewController+Permissions.h" #import "UIViewController+Permissions.h"
#import "ViewControllerUtils.h" #import "ViewControllerUtils.h"
#import <AVFoundation/AVFoundation.h> #import <AVFoundation/AVFoundation.h>
#import <AddressBookUI/AddressBookUI.h>
#import <AssetsLibrary/AssetsLibrary.h> #import <AssetsLibrary/AssetsLibrary.h>
#import <ContactsUI/CNContactViewController.h> #import <ContactsUI/CNContactViewController.h>
#import <JSQMessagesViewController/JSQMessagesBubbleImage.h> #import <JSQMessagesViewController/JSQMessagesBubbleImage.h>

@ -6,7 +6,6 @@
#import "Signal-Swift.h" #import "Signal-Swift.h"
#import "SignalApp.h" #import "SignalApp.h"
#import "ViewControllerUtils.h" #import "ViewControllerUtils.h"
#import <AddressBookUI/AddressBookUI.h>
#import <SignalMessaging/BlockListUIUtils.h> #import <SignalMessaging/BlockListUIUtils.h>
#import <SignalMessaging/ContactTableViewCell.h> #import <SignalMessaging/ContactTableViewCell.h>
#import <SignalMessaging/ContactsViewHelper.h> #import <SignalMessaging/ContactsViewHelper.h>

@ -19,6 +19,7 @@
#import <SignalServiceKit/PhoneNumber.h> #import <SignalServiceKit/PhoneNumber.h>
#import <SignalServiceKit/SignalAccount.h> #import <SignalServiceKit/SignalAccount.h>
@import AddressBook;
@import Contacts; @import Contacts;
NSString *const OWSContactsManagerSignalAccountsDidChangeNotification NSString *const OWSContactsManagerSignalAccountsDidChangeNotification

@ -1,8 +1,7 @@
// //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
#import <AddressBook/AddressBook.h>
#import <Mantle/MTLModel.h> #import <Mantle/MTLModel.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -16,8 +15,8 @@ NS_ASSUME_NONNULL_BEGIN
@class CNContact; @class CNContact;
@class PhoneNumber; @class PhoneNumber;
@class UIImage;
@class SignalRecipient; @class SignalRecipient;
@class UIImage;
@class YapDatabaseReadTransaction; @class YapDatabaseReadTransaction;
@interface Contact : MTLModel @interface Contact : MTLModel
@ -34,7 +33,6 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) BOOL isSignalContact; @property (nonatomic, readonly) BOOL isSignalContact;
#if TARGET_OS_IOS #if TARGET_OS_IOS
@property (nullable, readonly, nonatomic) UIImage *image; @property (nullable, readonly, nonatomic) UIImage *image;
@property (readonly, nonatomic) ABRecordID recordID;
@property (nullable, nonatomic, readonly) CNContact *cnContact; @property (nullable, nonatomic, readonly) CNContact *cnContact;
#endif // TARGET_OS_IOS #endif // TARGET_OS_IOS
@ -44,12 +42,6 @@ NS_ASSUME_NONNULL_BEGIN
#if TARGET_OS_IOS #if TARGET_OS_IOS
- (instancetype)initWithFirstName:(nullable NSString *)firstName
lastName:(nullable NSString *)lastName
userTextPhoneNumbers:(NSArray<NSString *> *)phoneNumbers
imageData:(nullable NSData *)imageData
contactID:(ABRecordID)record;
- (instancetype)initWithSystemContact:(CNContact *)contact NS_AVAILABLE_IOS(9_0); - (instancetype)initWithSystemContact:(CNContact *)contact NS_AVAILABLE_IOS(9_0);
- (NSString *)nameForPhoneNumber:(NSString *)recipientId; - (NSString *)nameForPhoneNumber:(NSString *)recipientId;

@ -24,36 +24,11 @@ NS_ASSUME_NONNULL_BEGIN
@implementation Contact @implementation Contact
@synthesize fullName = _fullName;
@synthesize comparableNameFirstLast = _comparableNameFirstLast; @synthesize comparableNameFirstLast = _comparableNameFirstLast;
@synthesize comparableNameLastFirst = _comparableNameLastFirst; @synthesize comparableNameLastFirst = _comparableNameLastFirst;
@synthesize image = _image; @synthesize image = _image;
#if TARGET_OS_IOS #if TARGET_OS_IOS
- (instancetype)initWithFirstName:(nullable NSString *)firstName
lastName:(nullable NSString *)lastName
userTextPhoneNumbers:(NSArray<NSString *> *)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 - (instancetype)initWithSystemContact:(CNContact *)contact
{ {
@ -65,6 +40,7 @@ NS_ASSUME_NONNULL_BEGIN
_cnContact = contact; _cnContact = contact;
_firstName = [self trimName:contact.givenName]; _firstName = [self trimName:contact.givenName];
_lastName = [self trimName:contact.familyName]; _lastName = [self trimName:contact.familyName];
_fullName = [CNContactFormatter stringFromContact:contact style:CNContactFormatterStyleFullName];
_uniqueId = contact.identifier; _uniqueId = contact.identifier;
NSMutableArray<NSString *> *phoneNumbers = [NSMutableArray new]; NSMutableArray<NSString *> *phoneNumbers = [NSMutableArray new];
@ -129,7 +105,7 @@ NS_ASSUME_NONNULL_BEGIN
_emails = [emailAddresses copy]; _emails = [emailAddresses copy];
if (contact.thumbnailImageData) { if (contact.thumbnailImageData) {
_imageData = contact.thumbnailImageData; _imageData = [contact.thumbnailImageData copy];
} }
return self; return self;
@ -154,11 +130,6 @@ NS_ASSUME_NONNULL_BEGIN
return [name stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; return [name stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
} }
+ (NSString *)uniqueIdFromABRecordId:(ABRecordID)recordId
{
return [NSString stringWithFormat:@"ABRecordId:%d", recordId];
}
+ (MTLPropertyStorage)storageBehaviorForPropertyWithKey:(NSString *)propertyKey + (MTLPropertyStorage)storageBehaviorForPropertyWithKey:(NSString *)propertyKey
{ {
if ([propertyKey isEqualToString:@"cnContact"] || [propertyKey isEqualToString:@"image"]) { if ([propertyKey isEqualToString:@"cnContact"] || [propertyKey isEqualToString:@"image"]) {
@ -193,18 +164,6 @@ NS_ASSUME_NONNULL_BEGIN
return [parsedPhoneNumbers sortedArrayUsingSelector:@selector(compare:)]; 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 { - (NSString *)comparableNameFirstLast {
if (_comparableNameFirstLast == nil) { if (_comparableNameFirstLast == nil) {
// Combine the two names with a tab separator, which has a lower ascii code than space, so that first names // 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; hash = hash ^ self.fullName.hash;
// base thumbnailHash is some arbitrary number if (self.imageData) {
NSUInteger thumbnailHash = 389201946; NSUInteger thumbnailHash = 0;
if (self.cnContact.thumbnailImageData) {
NSData *thumbnailHashData = NSData *thumbnailHashData =
[Cryptography computeSHA256Digest:self.cnContact.thumbnailImageData truncatedToBytes:sizeof(thumbnailHash)]; [Cryptography computeSHA256Digest:self.imageData truncatedToBytes:sizeof(thumbnailHash)];
[thumbnailHashData getBytes:&thumbnailHash length:sizeof(thumbnailHash)]; [thumbnailHashData getBytes:&thumbnailHash length:sizeof(thumbnailHash)];
hash = hash ^ thumbnailHash;
} }
hash = hash ^ thumbnailHash;
for (PhoneNumber *phoneNumber in self.parsedPhoneNumbers) { for (PhoneNumber *phoneNumber in self.parsedPhoneNumbers) {
hash = hash ^ phoneNumber.toE164.hash; hash = hash ^ phoneNumber.toE164.hash;
} }

Loading…
Cancel
Save