Merge branch 'charlesmchen/contactsCrash'
This commit is contained in:
commit
371b247b4f
@ -44,7 +44,6 @@
|
||||
#import "UIViewController+Permissions.h"
|
||||
#import "ViewControllerUtils.h"
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import <AddressBookUI/AddressBookUI.h>
|
||||
#import <AssetsLibrary/AssetsLibrary.h>
|
||||
#import <ContactsUI/CNContactViewController.h>
|
||||
#import <JSQMessagesViewController/JSQMessagesBubbleImage.h>
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
#import "Signal-Swift.h"
|
||||
#import "SignalApp.h"
|
||||
#import "ViewControllerUtils.h"
|
||||
#import <AddressBookUI/AddressBookUI.h>
|
||||
#import <SignalMessaging/BlockListUIUtils.h>
|
||||
#import <SignalMessaging/ContactTableViewCell.h>
|
||||
#import <SignalMessaging/ContactsViewHelper.h>
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
#import <SignalServiceKit/PhoneNumber.h>
|
||||
#import <SignalServiceKit/SignalAccount.h>
|
||||
|
||||
@import AddressBook;
|
||||
@import Contacts;
|
||||
|
||||
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>
|
||||
|
||||
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<NSString *> *)phoneNumbers
|
||||
imageData:(nullable NSData *)imageData
|
||||
contactID:(ABRecordID)record;
|
||||
|
||||
- (instancetype)initWithSystemContact:(CNContact *)contact NS_AVAILABLE_IOS(9_0);
|
||||
|
||||
- (NSString *)nameForPhoneNumber:(NSString *)recipientId;
|
||||
|
||||
@ -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<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
|
||||
{
|
||||
@ -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<NSString *> *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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user