From 121ef0439c34585ea4c45500ed244bc26f8e2680 Mon Sep 17 00:00:00 2001 From: Frederic Jacobs Date: Sun, 23 Nov 2014 01:08:36 +0100 Subject: [PATCH] Integrating the TextSecure Contact Discovery. --- Signal.xcodeproj/project.pbxproj | 8 +-- Signal/Signal-Info.plist | 2 +- Signal/src/Storyboard/Storyboard.storyboard | 2 +- Signal/src/contact/Contact.m | 2 +- Signal/src/contact/ContactsManager.h | 2 - Signal/src/contact/ContactsManager.m | 11 ---- .../PhoneNumberDirectoryFilterManager.m | 2 +- .../src/textsecure/Account/TSAccountManager.m | 3 +- Signal/src/textsecure/Contacts/TSThread.m | 3 -- .../src/textsecure/Storage/TSDatabaseView.m | 1 + .../src/textsecure/Storage/TSStorageManager.m | 54 ++++--------------- .../ContactDetailTableViewController.m | 4 +- .../view controllers/MessagesViewController.h | 3 +- .../UITests/SignalsViewController.m | 9 ++-- 14 files changed, 27 insertions(+), 79 deletions(-) diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 297d9df8d..0f080b378 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -3100,7 +3100,7 @@ ORGANIZATIONNAME = "Open Whisper Systems"; TargetAttributes = { D221A088169C9E5E00537ABF = { - DevelopmentTeam = DRXTS3ZU8M; + DevelopmentTeam = U68MSDN6DR; SystemCapabilities = { com.apple.DataProtection = { enabled = 1; @@ -4229,7 +4229,7 @@ LLVM_LTO = NO; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_NAME = Signal; - PROVISIONING_PROFILE = "87a69a1c-864f-4e05-8d48-b9268ace6179"; + PROVISIONING_PROFILE = ""; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = 1; TEST_AFTER_BUILD = YES; @@ -4464,7 +4464,7 @@ LLVM_LTO = NO; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_NAME = Signal; - PROVISIONING_PROFILE = "87a69a1c-864f-4e05-8d48-b9268ace6179"; + PROVISIONING_PROFILE = ""; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = 1; TEST_AFTER_BUILD = YES; @@ -4518,7 +4518,7 @@ LLVM_LTO = NO; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_NAME = Signal; - PROVISIONING_PROFILE = "87a69a1c-864f-4e05-8d48-b9268ace6179"; + PROVISIONING_PROFILE = ""; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = 1; TEST_AFTER_BUILD = YES; diff --git a/Signal/Signal-Info.plist b/Signal/Signal-Info.plist index 5e0126f80..be64d41c2 100644 --- a/Signal/Signal-Info.plist +++ b/Signal/Signal-Info.plist @@ -13,7 +13,7 @@ CFBundleIcons~ipad CFBundleIdentifier - org.whispersystems.signal.textSecure + org.whispersystems.signal CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Signal/src/Storyboard/Storyboard.storyboard b/Signal/src/Storyboard/Storyboard.storyboard index ac6fc2397..0af0d1c5c 100755 --- a/Signal/src/Storyboard/Storyboard.storyboard +++ b/Signal/src/Storyboard/Storyboard.storyboard @@ -1,5 +1,5 @@ - + diff --git a/Signal/src/contact/Contact.m b/Signal/src/contact/Contact.m index 126cdee6b..4603916a7 100644 --- a/Signal/src/contact/Contact.m +++ b/Signal/src/contact/Contact.m @@ -84,7 +84,7 @@ static NSString *const DEFAULTS_KEY_DATE = @"DefaultsKeyDate"; - (BOOL)isTextSecureContact{ __block BOOL isRecipient = NO; - [[TSStorageManager sharedManager].dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { + [[TSStorageManager sharedManager].databaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { for (PhoneNumber *number in self.parsedPhoneNumbers) { if ([TSRecipient recipientWithTextSecureIdentifier:number.toE164 withTransaction:transaction]) { isRecipient = YES; diff --git a/Signal/src/contact/ContactsManager.h b/Signal/src/contact/ContactsManager.h index 3862a84d7..8a6785695 100644 --- a/Signal/src/contact/ContactsManager.h +++ b/Signal/src/contact/ContactsManager.h @@ -45,6 +45,4 @@ typedef void(^ABReloadRequestCompletionBlock)(NSArray *contacts); - (NSArray*)allContacts; - (NSArray*)textSecureContacts; -- (NSString*)nameStringForPhoneIdentifier:(NSString*)identifier; - @end diff --git a/Signal/src/contact/ContactsManager.m b/Signal/src/contact/ContactsManager.m index 7d15fecb4..d7d7273ed 100644 --- a/Signal/src/contact/ContactsManager.m +++ b/Signal/src/contact/ContactsManager.m @@ -425,15 +425,4 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in return phoneNumber != nil && [directory containsPhoneNumber:phoneNumber]; } -- (NSString*)nameStringForPhoneIdentifier:(NSString*)identifier{ - for (Contact *contact in self.textSecureContacts) { - for (PhoneNumber *phoneNumber in contact.parsedPhoneNumbers) { - if ([phoneNumber.toE164 isEqualToString:identifier]) { - return contact.fullName; - } - } - } - return nil; -} - @end diff --git a/Signal/src/phone/signaling/number directory/PhoneNumberDirectoryFilterManager.m b/Signal/src/phone/signaling/number directory/PhoneNumberDirectoryFilterManager.m index a317b47ab..5918c8985 100644 --- a/Signal/src/phone/signaling/number directory/PhoneNumberDirectoryFilterManager.m +++ b/Signal/src/phone/signaling/number directory/PhoneNumberDirectoryFilterManager.m @@ -134,7 +134,7 @@ } } - [[TSStorageManager sharedManager].dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + [[TSStorageManager sharedManager].databaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { for (NSString *identifier in tsIdentifiers) { TSRecipient *recipient = [TSRecipient recipientWithTextSecureIdentifier:identifier withTransaction:transaction]; if (!recipient) { diff --git a/Signal/src/textsecure/Account/TSAccountManager.m b/Signal/src/textsecure/Account/TSAccountManager.m index 346270156..48e5d9fd2 100644 --- a/Signal/src/textsecure/Account/TSAccountManager.m +++ b/Signal/src/textsecure/Account/TSAccountManager.m @@ -97,7 +97,7 @@ NSString *authToken = [self generateNewAccountAuthenticationToken]; NSString *signalingKey = [self generateNewSignalingKeyToken]; NSString *phoneNumber = [[tsToken componentsSeparatedByString:@":"] objectAtIndex:0]; - + require(phoneNumber != nil); require(signalingKey != nil); require(authToken != nil); @@ -128,7 +128,6 @@ } failure:^(NSURLSessionDataTask *task, NSError *error) { DDLogError(@"Error registering with TextSecure: %@", error.debugDescription); - //TODO: Cover all error types: https://github.com/WhisperSystems/TextSecure-Server/wiki/API-Protocol // Above link doesn't appear to document the endpoint /v1/accounts/token/{token} - is it similar to /v1/accounts/code/{code} ? failureBlock([self errorForRegistrationFailure:kTSRegistrationFailureNetwork HTTPStatusCode:[task statusCode]]); diff --git a/Signal/src/textsecure/Contacts/TSThread.m b/Signal/src/textsecure/Contacts/TSThread.m index 7171b2dda..ff10b4845 100644 --- a/Signal/src/textsecure/Contacts/TSThread.m +++ b/Signal/src/textsecure/Contacts/TSThread.m @@ -7,9 +7,6 @@ // #import "TSThread.h" - -#import "Environment.h" -#import "ContactsManager.h" #import "TSGroup.h" @implementation TSThread diff --git a/Signal/src/textsecure/Storage/TSDatabaseView.m b/Signal/src/textsecure/Storage/TSDatabaseView.m index 58536d055..19ff33146 100644 --- a/Signal/src/textsecure/Storage/TSDatabaseView.m +++ b/Signal/src/textsecure/Storage/TSDatabaseView.m @@ -19,6 +19,7 @@ NSString *TSThreadGroup = @"TSThreadGroup"; NSString *TSThreadDatabaseViewExtensionName = @"TSThreadDatabaseViewExtensionName"; NSString *TSMessageDatabaseViewExtensionName = @"TSMessageDatabaseViewExtensionName"; +NSString *TSRecipientsDatabaseViewExtensionName = @"TSRecipientsDatabaseViewExtensionName"; @implementation TSDatabaseView diff --git a/Signal/src/textsecure/Storage/TSStorageManager.m b/Signal/src/textsecure/Storage/TSStorageManager.m index 1460a586c..b5283f254 100644 --- a/Signal/src/textsecure/Storage/TSStorageManager.m +++ b/Signal/src/textsecure/Storage/TSStorageManager.m @@ -40,60 +40,26 @@ static NSString * keychainDBPassAccount = @"TSDatabasePass"; return sharedMyManager; } -- (instancetype)init { - self = [super init]; - +- (void)setupDatabase { YapDatabaseOptions *options = [[YapDatabaseOptions alloc] init]; options.corruptAction = YapDatabaseCorruptAction_Fail; options.passphraseBlock = ^{ return [self databasePassword]; }; - _database = [[YapDatabase alloc] initWithPath:[self dbPath] - objectSerializer:NULL - objectDeserializer:NULL - metadataSerializer:NULL - metadataDeserializer:NULL - objectSanitizer:NULL - metadataSanitizer:NULL - options:options]; - _dbConnection = self.newDatabaseConnection; - return self; -} - -- (void)setupDatabase { + self. database = [[YapDatabase alloc] initWithPath:[self dbPath] + objectSerializer:NULL + objectDeserializer:NULL + metadataSerializer:NULL + metadataDeserializer:NULL + objectSanitizer:NULL + metadataSanitizer:NULL + options:options]; + self.dbConnection = self.databaseConnection; [TSDatabaseView registerThreadDatabaseView]; [TSDatabaseView registerBuddyConversationDatabaseView]; } -/** - * Protects the preference and logs file with disk encryption and prevents them to leak to iCloud. - */ - -- (void)protectDatabaseFile{ - - NSDictionary *attrs = @{NSFileProtectionKey: NSFileProtectionCompleteUntilFirstUserAuthentication}; - NSError *error; - - - [NSFileManager.defaultManager setAttributes:attrs ofItemAtPath:[self dbPath] error:&error]; - [[NSURL fileURLWithPath:[self dbPath]] setResourceValue:@YES - forKey:NSURLIsExcludedFromBackupKey - error:&error]; - - if (error) { - DDLogError(@"Error while removing log files from backup: %@", error.description); - UIAlertView *alert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"WARNING", @"") - message:NSLocalizedString(@"DISABLING_BACKUP_FAILED", @"") - delegate:nil - cancelButtonTitle:NSLocalizedString(@"OK", @"") - otherButtonTitles:nil]; - [alert show]; - return; - } - -} - - (YapDatabaseConnection *)newDatabaseConnection { return self.database.newConnection; } diff --git a/Signal/src/view controllers/ContactDetailTableViewController.m b/Signal/src/view controllers/ContactDetailTableViewController.m index b14698e3a..a4c88713f 100644 --- a/Signal/src/view controllers/ContactDetailTableViewController.m +++ b/Signal/src/view controllers/ContactDetailTableViewController.m @@ -43,7 +43,9 @@ static NSString* const kEmailCell = @"EmailCell"; static NSString* const kAnnexPhoneNumberCell = @"AnnexPhoneNumberCell"; static NSString *const kNotesCell = @"NotesCell"; -static NSString *const kContactDetailSegue = @"DetailSegue"; + +static NSString *const kContactDetailSegue = @"DetailSegue"; + @interface ContactDetailTableViewController () { BOOL doesImageExist; diff --git a/Signal/src/view controllers/MessagesViewController.h b/Signal/src/view controllers/MessagesViewController.h index 3c73dea42..a150c0199 100644 --- a/Signal/src/view controllers/MessagesViewController.h +++ b/Signal/src/view controllers/MessagesViewController.h @@ -15,10 +15,9 @@ @interface MessagesViewController : JSQMessagesViewController -@property (strong, nonatomic) NSString* senderTitleString; +@property (strong, nonatomic) NSString* _senderTitleString; @property DemoDataModel *demoData; - - (void)setupWithThread:(TSThread*)thread; @end diff --git a/Signal/src/view controllers/UITests/SignalsViewController.m b/Signal/src/view controllers/UITests/SignalsViewController.m index 43307279b..2d106fb23 100644 --- a/Signal/src/view controllers/UITests/SignalsViewController.m +++ b/Signal/src/view controllers/UITests/SignalsViewController.m @@ -22,13 +22,12 @@ #import "YapDatabaseFullTextSearch.h" #import "YapDatabase.h" -#define CELL_HEIGHT 71.0f +#define CELL_HEIGHT 71.0f #define HEADER_HEIGHT 44.0f -static NSString *const inboxTableViewCell = @"inBoxTableViewCell"; -static NSString *const kSegueIndentifier = @"showSegue"; - +static NSString *const inboxTableViewCell = @"inBoxTableViewCell"; +static NSString *const kSegueIndentifier = @"showSegue"; @interface SignalsViewController () { NSArray * _dataArray; @@ -46,8 +45,6 @@ static NSString *const kSegueIndentifier = @"showSegue"; - (void)viewDidLoad { [super viewDidLoad]; - [self tableViewSetUp]; - [self.uiDatabaseConnection beginLongLivedReadTransaction]; self.threadMappings = [[YapDatabaseViewMappings alloc] initWithGroups:@[TSThreadGroup]