Extract labels for phone numbers.

// FREEBIE
pull/1/head
Matthew Chen 7 years ago
parent cb9d96be00
commit 42768294ee

@ -1,12 +1,12 @@
platform :ios, '8.0'
platform :ios, '9.0'
source 'https://github.com/CocoaPods/Specs.git'
target 'Signal' do
pod 'SocketRocket', :git => 'https://github.com/facebook/SocketRocket.git'
pod 'AxolotlKit', git: 'https://github.com/WhisperSystems/SignalProtocolKit.git'
#pod 'AxolotlKit', path: '../SignalProtocolKit'
pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git'
#pod 'SignalServiceKit', path: '../SignalServiceKit'
#pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git'
pod 'SignalServiceKit', path: '../SignalServiceKit'
pod 'OpenSSL'
pod 'SCWaveformView', '~> 1.0'
pod 'JSQMessagesViewController', git: 'https://github.com/WhisperSystems/JSQMessagesViewController.git', branch: 'mkirk/position-edit-menu'

@ -116,7 +116,7 @@ DEPENDENCIES:
- OpenSSL
- PureLayout
- SCWaveformView (~> 1.0)
- SignalServiceKit (from `https://github.com/WhisperSystems/SignalServiceKit.git`)
- SignalServiceKit (from `../SignalServiceKit`)
- SocketRocket (from `https://github.com/facebook/SocketRocket.git`)
EXTERNAL SOURCES:
@ -126,7 +126,7 @@ EXTERNAL SOURCES:
:branch: mkirk/position-edit-menu
:git: https://github.com/WhisperSystems/JSQMessagesViewController.git
SignalServiceKit:
:git: https://github.com/WhisperSystems/SignalServiceKit.git
:path: ../SignalServiceKit
SocketRocket:
:git: https://github.com/facebook/SocketRocket.git
@ -137,9 +137,6 @@ CHECKOUT OPTIONS:
JSQMessagesViewController:
:commit: 7054e4b13ee5bcd6d524adb6dc9a726e8c466308
:git: https://github.com/WhisperSystems/JSQMessagesViewController.git
SignalServiceKit:
:commit: 608852898a58d3cc3d5e8ceee27b139a5d82fc1a
:git: https://github.com/WhisperSystems/SignalServiceKit.git
SocketRocket:
:commit: 877ac7438be3ad0b45ef5ca3969574e4b97112bf
:git: https://github.com/facebook/SocketRocket.git
@ -167,6 +164,6 @@ SPEC CHECKSUMS:
UnionFind: c33be5adb12983981d6e827ea94fc7f9e370f52d
YapDatabase: b1e43555a34a5298e23a045be96817a5ef0da58f
PODFILE CHECKSUM: d4f237ca4bd0b71e488d29b1e38dc31d06e45a52
PODFILE CHECKSUM: dcf50b2467bd856f7d5645efcd7688e7dba7c237
COCOAPODS: 1.2.1

@ -2356,7 +2356,7 @@
GCC_WARN_UNUSED_VALUE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "-fobjc-arc-exceptions";
SDKROOT = iphoneos;
@ -2410,7 +2410,7 @@
GCC_WARN_UNUSED_VALUE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
ONLY_ACTIVE_ARCH = NO;
OTHER_CFLAGS = (
"-DNS_BLOCK_ASSERTIONS=1",

@ -14,6 +14,7 @@
#import "UIUtil.h"
#import <MessageUI/MessageUI.h>
#import <SignalServiceKit/OWSBlockingManager.h>
#import <SignalServiceKit/TSAccountManager.h>
NS_ASSUME_NONNULL_BEGIN
@ -348,8 +349,9 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
self.searchResults = [contactsSearcher filterWithString:searchText];
NSMutableArray<NSString *> *searchPhoneNumbers = [NSMutableArray new];
for (PhoneNumber *phoneNumber in [PhoneNumber tryParsePhoneNumbersFromsUserSpecifiedText:searchText
clientPhoneNumber:[TSStorageManager localNumber]]) {
for (PhoneNumber *phoneNumber in
[PhoneNumber tryParsePhoneNumbersFromsUserSpecifiedText:searchText
clientPhoneNumber:[TSAccountManager localNumber]]) {
[searchPhoneNumbers addObject:phoneNumber.toE164];
}
// text to a non-signal number if we have no results and a valid phone #

@ -253,7 +253,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien
NSMutableArray<NSString *> *possiblePhoneNumbers = [NSMutableArray new];
for (PhoneNumber *phoneNumber in
[PhoneNumber tryParsePhoneNumbersFromsUserSpecifiedText:rawPhoneNumber
clientPhoneNumber:[TSStorageManager localNumber]]) {
clientPhoneNumber:[TSAccountManager localNumber]]) {
[possiblePhoneNumbers addObject:phoneNumber.toE164];
}
if ([possiblePhoneNumbers count] < 1) {

@ -27,7 +27,6 @@ extern NSString *const OWSContactsManagerSignalRecipientsDidChangeNotification;
- (nonnull ObservableValue *)getObservableContacts;
- (nonnull NSArray *)getContactsFromAddressBook:(nonnull ABAddressBookRef)addressBook;
- (nullable Contact *)latestContactForPhoneNumber:(nullable PhoneNumber *)phoneNumber;
- (nullable Contact *)contactForPhoneIdentifier:(nullable NSString *)identifier;
- (Contact *)getOrBuildContactForPhoneIdentifier:(NSString *)identifier;

@ -368,9 +368,10 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in
- (Contact *)contactForRecord:(ABRecordRef)record {
ABRecordID recordID = ABRecordGetRecordID(record);
NSString *firstName = (__bridge_transfer NSString *)ABRecordCopyValue(record, kABPersonFirstNameProperty);
NSString *lastName = (__bridge_transfer NSString *)ABRecordCopyValue(record, kABPersonLastNameProperty);
NSArray *phoneNumbers = [self phoneNumbersForRecord:record];
NSString *firstName = (__bridge_transfer NSString *)ABRecordCopyValue(record, kABPersonFirstNameProperty);
NSString *lastName = (__bridge_transfer NSString *)ABRecordCopyValue(record, kABPersonLastNameProperty);
NSDictionary<NSString *, NSNumber *> *phoneNumberTypeMap = [self phoneNumbersForRecord:record];
NSArray *phoneNumbers = [phoneNumberTypeMap.allKeys sortedArrayUsingSelector:@selector(compare:)];
if (!firstName && !lastName) {
NSString *companyName = (__bridge_transfer NSString *)ABRecordCopyValue(record, kABPersonOrganizationProperty);
@ -381,14 +382,14 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in
}
}
// NSString *notes = (__bridge_transfer NSString *)ABRecordCopyValue(record, kABPersonNoteProperty);
// NSArray *emails = [ContactsManager emailsForRecord:record];
NSData *image = (__bridge_transfer NSData *)ABPersonCopyImageDataWithFormat(record, kABPersonImageFormatThumbnail);
UIImage *img = [UIImage imageWithData:image];
NSData *imageData
= (__bridge_transfer NSData *)ABPersonCopyImageDataWithFormat(record, kABPersonImageFormatThumbnail);
UIImage *img = [UIImage imageWithData:imageData];
return [[Contact alloc] initWithContactWithFirstName:firstName
andLastName:lastName
andUserTextPhoneNumbers:phoneNumbers
phoneNumberTypeMap:phoneNumberTypeMap
andImage:img
andContactID:recordID];
}
@ -419,27 +420,41 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in
return [phoneNumber1.toE164 isEqualToString:phoneNumber2.toE164];
}
- (NSArray *)phoneNumbersForRecord:(ABRecordRef)record {
ABMultiValueRef numberRefs = ABRecordCopyValue(record, kABPersonPhoneProperty);
- (NSDictionary<NSString *, NSNumber *> *)phoneNumbersForRecord:(ABRecordRef)record
{
ABMultiValueRef phoneNumberRefs = NULL;
@try {
NSArray *phoneNumbers = (__bridge_transfer NSArray *)ABMultiValueCopyArrayOfAllValues(numberRefs);
if (phoneNumbers == nil)
phoneNumbers = @[];
NSMutableArray *numbers = [NSMutableArray array];
for (NSUInteger i = 0; i < phoneNumbers.count; i++) {
NSString *phoneNumber = phoneNumbers[i];
[numbers addObject:phoneNumber];
phoneNumberRefs = ABRecordCopyValue(record, kABPersonPhoneProperty);
CFIndex phoneNumberCount = ABMultiValueGetCount(phoneNumberRefs);
NSMutableDictionary<NSString *, NSNumber *> *result = [NSMutableDictionary new];
for (int i = 0; i < phoneNumberCount; i++) {
NSString *phoneNumberLabel = (__bridge_transfer NSString *)ABMultiValueCopyLabelAtIndex(phoneNumberRefs, i);
NSString *phoneNumber = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(phoneNumberRefs, i);
if ([phoneNumberLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel]) {
result[phoneNumber] = @(OWSPhoneNumberTypeMobile);
} else if ([phoneNumberLabel isEqualToString:(NSString *)kABPersonPhoneIPhoneLabel]) {
result[phoneNumber] = @(OWSPhoneNumberTypeIPhone);
} else if ([phoneNumberLabel isEqualToString:(NSString *)kABPersonPhoneMainLabel]) {
result[phoneNumber] = @(OWSPhoneNumberTypeMain);
} else if ([phoneNumberLabel isEqualToString:(NSString *)kABPersonPhoneHomeFAXLabel]) {
result[phoneNumber] = @(OWSPhoneNumberTypeHomeFAX);
} else if ([phoneNumberLabel isEqualToString:(NSString *)kABPersonPhoneWorkFAXLabel]) {
result[phoneNumber] = @(OWSPhoneNumberTypeWorkFAX);
} else if ([phoneNumberLabel isEqualToString:(NSString *)kABPersonPhoneOtherFAXLabel]) {
result[phoneNumber] = @(OWSPhoneNumberTypeOtherFAX);
} else if ([phoneNumberLabel isEqualToString:(NSString *)kABPersonPhonePagerLabel]) {
result[phoneNumber] = @(OWSPhoneNumberTypePager);
} else {
result[phoneNumber] = @(OWSPhoneNumberTypeUnknown);
}
}
return numbers;
return [result copy];
} @finally {
if (numberRefs) {
CFRelease(numberRefs);
if (phoneNumberRefs) {
CFRelease(phoneNumberRefs);
}
}
}
@ -597,6 +612,7 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in
return [[Contact alloc] initWithContactWithFirstName:self.unknownContactName
andLastName:nil
andUserTextPhoneNumbers:@[ identifier ]
phoneNumberTypeMap:nil
andImage:nil
andContactID:0];
}

Loading…
Cancel
Save