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' source 'https://github.com/CocoaPods/Specs.git'
target 'Signal' do target 'Signal' do
pod 'SocketRocket', :git => 'https://github.com/facebook/SocketRocket.git' pod 'SocketRocket', :git => 'https://github.com/facebook/SocketRocket.git'
pod 'AxolotlKit', git: 'https://github.com/WhisperSystems/SignalProtocolKit.git' pod 'AxolotlKit', git: 'https://github.com/WhisperSystems/SignalProtocolKit.git'
#pod 'AxolotlKit', path: '../SignalProtocolKit' #pod 'AxolotlKit', path: '../SignalProtocolKit'
pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git' #pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git'
#pod 'SignalServiceKit', path: '../SignalServiceKit' pod 'SignalServiceKit', path: '../SignalServiceKit'
pod 'OpenSSL' pod 'OpenSSL'
pod 'SCWaveformView', '~> 1.0' pod 'SCWaveformView', '~> 1.0'
pod 'JSQMessagesViewController', git: 'https://github.com/WhisperSystems/JSQMessagesViewController.git', branch: 'mkirk/position-edit-menu' pod 'JSQMessagesViewController', git: 'https://github.com/WhisperSystems/JSQMessagesViewController.git', branch: 'mkirk/position-edit-menu'

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

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

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

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

@ -370,7 +370,8 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in
NSString *firstName = (__bridge_transfer NSString *)ABRecordCopyValue(record, kABPersonFirstNameProperty); NSString *firstName = (__bridge_transfer NSString *)ABRecordCopyValue(record, kABPersonFirstNameProperty);
NSString *lastName = (__bridge_transfer NSString *)ABRecordCopyValue(record, kABPersonLastNameProperty); NSString *lastName = (__bridge_transfer NSString *)ABRecordCopyValue(record, kABPersonLastNameProperty);
NSArray *phoneNumbers = [self phoneNumbersForRecord:record]; NSDictionary<NSString *, NSNumber *> *phoneNumberTypeMap = [self phoneNumbersForRecord:record];
NSArray *phoneNumbers = [phoneNumberTypeMap.allKeys sortedArrayUsingSelector:@selector(compare:)];
if (!firstName && !lastName) { if (!firstName && !lastName) {
NSString *companyName = (__bridge_transfer NSString *)ABRecordCopyValue(record, kABPersonOrganizationProperty); 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); NSData *imageData
// NSArray *emails = [ContactsManager emailsForRecord:record]; = (__bridge_transfer NSData *)ABPersonCopyImageDataWithFormat(record, kABPersonImageFormatThumbnail);
NSData *image = (__bridge_transfer NSData *)ABPersonCopyImageDataWithFormat(record, kABPersonImageFormatThumbnail); UIImage *img = [UIImage imageWithData:imageData];
UIImage *img = [UIImage imageWithData:image];
return [[Contact alloc] initWithContactWithFirstName:firstName return [[Contact alloc] initWithContactWithFirstName:firstName
andLastName:lastName andLastName:lastName
andUserTextPhoneNumbers:phoneNumbers andUserTextPhoneNumbers:phoneNumbers
phoneNumberTypeMap:phoneNumberTypeMap
andImage:img andImage:img
andContactID:recordID]; andContactID:recordID];
} }
@ -419,27 +420,41 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in
return [phoneNumber1.toE164 isEqualToString:phoneNumber2.toE164]; return [phoneNumber1.toE164 isEqualToString:phoneNumber2.toE164];
} }
- (NSArray *)phoneNumbersForRecord:(ABRecordRef)record { - (NSDictionary<NSString *, NSNumber *> *)phoneNumbersForRecord:(ABRecordRef)record
ABMultiValueRef numberRefs = ABRecordCopyValue(record, kABPersonPhoneProperty); {
ABMultiValueRef phoneNumberRefs = NULL;
@try { @try {
NSArray *phoneNumbers = (__bridge_transfer NSArray *)ABMultiValueCopyArrayOfAllValues(numberRefs); phoneNumberRefs = ABRecordCopyValue(record, kABPersonPhoneProperty);
if (phoneNumbers == nil) CFIndex phoneNumberCount = ABMultiValueGetCount(phoneNumberRefs);
phoneNumbers = @[]; NSMutableDictionary<NSString *, NSNumber *> *result = [NSMutableDictionary new];
for (int i = 0; i < phoneNumberCount; i++) {
NSMutableArray *numbers = [NSMutableArray array]; NSString *phoneNumberLabel = (__bridge_transfer NSString *)ABMultiValueCopyLabelAtIndex(phoneNumberRefs, i);
NSString *phoneNumber = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(phoneNumberRefs, i);
for (NSUInteger i = 0; i < phoneNumbers.count; i++) {
NSString *phoneNumber = phoneNumbers[i]; if ([phoneNumberLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel]) {
[numbers addObject:phoneNumber]; 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 { } @finally {
if (numberRefs) { if (phoneNumberRefs) {
CFRelease(numberRefs); CFRelease(phoneNumberRefs);
} }
} }
} }
@ -597,6 +612,7 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in
return [[Contact alloc] initWithContactWithFirstName:self.unknownContactName return [[Contact alloc] initWithContactWithFirstName:self.unknownContactName
andLastName:nil andLastName:nil
andUserTextPhoneNumbers:@[ identifier ] andUserTextPhoneNumbers:@[ identifier ]
phoneNumberTypeMap:nil
andImage:nil andImage:nil
andContactID:0]; andContactID:0];
} }

Loading…
Cancel
Save