Integrating call and messaging buttons.

pull/1/head
Frederic Jacobs 11 years ago
parent fbbeff70e4
commit 8514836032

@ -12,6 +12,7 @@
#import "PriorityQueue.h" #import "PriorityQueue.h"
#import "RecentCallManager.h" #import "RecentCallManager.h"
#import "Release.h" #import "Release.h"
#import "TSSocketManager.h"
#import "TSStorageManager.h" #import "TSStorageManager.h"
#import "TSAccountManager.h" #import "TSAccountManager.h"
#import "Util.h" #import "Util.h"
@ -140,6 +141,8 @@
[self.window.rootViewController presentViewController:callViewController animated:NO completion:nil]; [self.window.rootViewController presentViewController:callViewController animated:NO completion:nil];
} onThread:NSThread.mainThread untilCancelled:nil]; } onThread:NSThread.mainThread untilCancelled:nil];
[TSSocketManager becomeActive];
return YES; return YES;
} }

@ -119,7 +119,7 @@ static NSString *const DEFAULTS_KEY_DATE = @"DefaultsKeyDate";
ContactsManager *contactManager = [Environment getCurrent].contactsManager; ContactsManager *contactManager = [Environment getCurrent].contactsManager;
for (PhoneNumber *number in self.parsedPhoneNumbers) { for (PhoneNumber *number in self.parsedPhoneNumbers) {
if ([contactManager isPhoneNumberRegisteredWithRedPhone:number]) { if ([contactManager isPhoneNumberRegisteredWithRedPhone:number]) {
[identifiers addObject:number.toE164]; [identifiers addObject:number];
} }
} }

@ -23,6 +23,7 @@
@class ContactsManager; @class ContactsManager;
@class PhoneManager; @class PhoneManager;
@class PhoneNumberDirectoryFilterManager; @class PhoneNumberDirectoryFilterManager;
@class SignalsViewController;
@interface Environment : NSObject @interface Environment : NSObject
@property (nonatomic, readonly) in_port_t serverPort; @property (nonatomic, readonly) in_port_t serverPort;
@ -42,6 +43,8 @@
@property (nonatomic, readonly) ContactsManager *contactsManager; @property (nonatomic, readonly) ContactsManager *contactsManager;
@property (nonatomic, readonly) PhoneNumberDirectoryFilterManager* phoneDirectoryManager; @property (nonatomic, readonly) PhoneNumberDirectoryFilterManager* phoneDirectoryManager;
@property (nonatomic, readonly) SignalsViewController *signalsViewController;
+(SecureEndPoint*) getMasterServerSecureEndPoint; +(SecureEndPoint*) getMasterServerSecureEndPoint;
+(SecureEndPoint*) getSecureEndPointToDefaultRelayServer; +(SecureEndPoint*) getSecureEndPointToDefaultRelayServer;
+(SecureEndPoint*) getSecureEndPointToSignalingServerNamed:(NSString*)name; +(SecureEndPoint*) getSecureEndPointToSignalingServerNamed:(NSString*)name;
@ -77,4 +80,8 @@ andCurrentRegionCodeForPhoneNumbers:(NSString*)currentRegionCodeForPhoneNumbers
+(BOOL)isRedPhoneRegistered; +(BOOL)isRedPhoneRegistered;
+(void)resetAppData; +(void)resetAppData;
- (void)setSignalsViewController:(SignalsViewController *)signalsViewController;
+ (void)messageIdentifier:(NSString*)identifier;
@end @end

@ -10,6 +10,7 @@
#import "PreferencesUtil.h" #import "PreferencesUtil.h"
#import "PhoneNumberDirectoryFilterManager.h" #import "PhoneNumberDirectoryFilterManager.h"
#import "SignalKeyingStorage.h" #import "SignalKeyingStorage.h"
#import "SignalsViewController.h"
#define isRegisteredUserDefaultString @"isRegistered" #define isRegisteredUserDefaultString @"isRegistered"
@ -161,7 +162,30 @@ phoneDirectoryManager;
return [PropertyListPreferences new]; return [PropertyListPreferences new];
} }
+(void)resetAppData{
- (void)setSignalsViewController:(SignalsViewController *)signalsViewController{
_signalsViewController = signalsViewController;
}
+ (void)messageIdentifier:(NSString*)identifier{
Environment *env = [self getCurrent];
SignalsViewController *vc = env.signalsViewController;
if (vc.presentedViewController) {
[vc.presentedViewController dismissViewControllerAnimated:YES completion:nil];
}
[vc.navigationController popToRootViewControllerAnimated:YES];
vc.contactIdentifierFromCompose = identifier;
[vc performSegueWithIdentifier:@"showSegue" sender:nil];
UITabBarController *tabBarController = (UITabBarController*)vc.parentViewController.parentViewController;
if ([tabBarController respondsToSelector:@selector(selectedIndex)]) {
tabBarController.selectedIndex = 1;
}
}
+ (void)resetAppData{
[SignalKeyingStorage wipeKeychain]; [SignalKeyingStorage wipeKeychain];
[Environment.preferences clear]; [Environment.preferences clear];
if (self.preferences.loggingIsEnabled) { if (self.preferences.loggingIsEnabled) {

@ -25,5 +25,6 @@ extern NSString * const SocketConnectingNotification;
+ (void)becomeActive; + (void)becomeActive;
+ (void)resignActivity; + (void)resignActivity;
+ (void)sendNotification;
@end @end

@ -31,7 +31,7 @@ NSString * const SocketConnectingNotification = @"SocketConnectingNotification";
@property (nonatomic, retain) NSTimer *reconnectTimer; @property (nonatomic, retain) NSTimer *reconnectTimer;
@property (nonatomic, retain) SRWebSocket *websocket; @property (nonatomic, retain) SRWebSocket *websocket;
@property (nonatomic) NSUInteger status; @property (nonatomic) SocketStatus status;
@end @end
@implementation TSSocketManager @implementation TSSocketManager
@ -192,6 +192,13 @@ NSString * const SocketConnectingNotification = @"SocketConnectingNotification";
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (context == kSocketStatusObservationContext) if (context == kSocketStatusObservationContext)
{ {
[self notifyStatusChange];
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
- (void)notifyStatusChange{
switch (self.status) { switch (self.status) {
case kSocketStatusOpen: case kSocketStatusOpen:
[[NSNotificationCenter defaultCenter] postNotificationName:SocketOpenedNotification object:self]; [[NSNotificationCenter defaultCenter] postNotificationName:SocketOpenedNotification object:self];
@ -205,10 +212,10 @@ NSString * const SocketConnectingNotification = @"SocketConnectingNotification";
default: default:
break; break;
} }
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
} }
+ (void)sendNotification{
[[self sharedManager] notifyStatusChange];
}
@end @end

@ -11,6 +11,8 @@
#import "ActionContactDetailCell.h" #import "ActionContactDetailCell.h"
#import "UIUtil.h" #import "UIUtil.h"
#import "DJWActionSheet.h" #import "DJWActionSheet.h"
#import "Environment.h"
#import "PhoneManager.h"
#define kImageRadius 50.0f #define kImageRadius 50.0f
#define kMinRows 3 #define kMinRows 3
@ -170,7 +172,7 @@ static NSString *const kContactDetailSegue = @"DetailSegue";
if (c.isRedPhoneContact) if (c.isRedPhoneContact)
{ {
cell.contactCallButton.tintColor = [UIColor colorWithRed:0.f/255.f green:122.f/255.f blue:255.f/255.f alpha:1.0f]; cell.contactCallButton.tintColor = [UIColor colorWithRed:0.f/255.f green:122.f/255.f blue:255.f/255.f alpha:1.0f];
[cell.contactCallButton addTarget:self action:@selector(initiateRedPhoneCall) forControlEvents:UIControlEventTouchUpInside];
} else { } else {
cell.contactCallButton.tintColor = [UIColor colorWithRed:81.f/255.f green:81.f/255.f blue:81.f/255.f alpha:1.0f]; cell.contactCallButton.tintColor = [UIColor colorWithRed:81.f/255.f green:81.f/255.f blue:81.f/255.f alpha:1.0f];
cell.contactCallButton.enabled = NO; cell.contactCallButton.enabled = NO;
@ -179,12 +181,66 @@ static NSString *const kContactDetailSegue = @"DetailSegue";
if (c.isTextSecureContact) if (c.isTextSecureContact)
{ {
cell.contactTextButton.tintColor = [UIColor colorWithRed:0.f/255.f green:122.f/255.f blue:255.f/255.f alpha:1.0f]; cell.contactTextButton.tintColor = [UIColor colorWithRed:0.f/255.f green:122.f/255.f blue:255.f/255.f alpha:1.0f];
[cell.contactTextButton addTarget:self action:@selector(openTextSecureConversation) forControlEvents:UIControlEventTouchUpInside];
} else { } else {
cell.contactTextButton.tintColor = [UIColor colorWithRed:81.f/255.f green:81.f/255.f blue:81.f/255.f alpha:1.0f]; cell.contactTextButton.tintColor = [UIColor colorWithRed:81.f/255.f green:81.f/255.f blue:81.f/255.f alpha:1.0f];
cell.contactTextButton.enabled = NO; cell.contactTextButton.enabled = NO;
} }
}
- (void)openTextSecureConversation{
NSArray *textSecureIdentifiers = [self.contact textSecureIdentifiers];
if (textSecureIdentifiers.count > 1) {
[DJWActionSheet showInView:self.tabBarController.view
withTitle:@"What number would you like to message?"
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:textSecureIdentifiers
tapBlock:^(DJWActionSheet *actionSheet, NSInteger tappedButtonIndex) {
if (tappedButtonIndex == actionSheet.cancelButtonIndex) {
DDLogVerbose(@"User Cancelled Call");
} else {
[Environment messageIdentifier:[textSecureIdentifiers objectAtIndex:(NSUInteger)tappedButtonIndex]];
}
}];
} else if (textSecureIdentifiers.count == 1){
[Environment messageIdentifier:[textSecureIdentifiers firstObject]];
} else{
DDLogWarn(@"Tried to intiate a call but contact has no RedPhone identifier");
}
}
- (void)initiateRedPhoneCall{
NSArray *redPhoneIdentifiers = [self.contact redPhoneIdentifiers];
if (redPhoneIdentifiers.count > 1) {
NSMutableArray *e164 = [NSMutableArray array];
for (PhoneNumber *phoneNumber in redPhoneIdentifiers) {
[e164 addObject:phoneNumber.toE164];
}
[DJWActionSheet showInView:self.tabBarController.view
withTitle:@"What number would you like to dial?"
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:e164
tapBlock:^(DJWActionSheet *actionSheet, NSInteger tappedButtonIndex) {
if (tappedButtonIndex == actionSheet.cancelButtonIndex) {
DDLogVerbose(@"User Cancelled Call");
} else {
[Environment.phoneManager initiateOutgoingCallToContact:self.contact atRemoteNumber:[redPhoneIdentifiers objectAtIndex:(NSUInteger)tappedButtonIndex]];
}
}];
} else if (redPhoneIdentifiers.count == 1){
[Environment.phoneManager initiateOutgoingCallToContact:self.contact atRemoteNumber:[redPhoneIdentifiers firstObject]];
} else{
DDLogWarn(@"Tried to intiate a call but contact has no RedPhone identifier");
}
} }
-(void)setUpNameMainUserCell:(ContactDetailCell*)cell -(void)setUpNameMainUserCell:(ContactDetailCell*)cell
@ -322,7 +378,4 @@ static NSString *const kContactDetailSegue = @"DetailSegue";
return kMinRows + numEmails + numPhoneNumbers + numNotes; return kMinRows + numEmails + numPhoneNumbers + numNotes;
} }
@end @end

@ -132,15 +132,10 @@
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ {
//HACK: This is horrible due to the view hierarchy, but gets the job done. Gets a reference to the SignalsVC so we can present the conversation from it. NSString *identifier = [[[self contactForIndexPath:indexPath] textSecureIdentifiers] firstObject];
UITabBarController * tb = (UITabBarController*)self.parentViewController.presentingViewController;
UINavigationController* nav = (UINavigationController*)[tb.childViewControllers objectAtIndex:1];
SignalsViewController* s = (SignalsViewController*)nav.topViewController;
s.contactIdentifierFromCompose = [[[self contactForIndexPath:indexPath] textSecureIdentifiers] firstObject];
[self dismissViewControllerAnimated:YES completion:^(){ [self dismissViewControllerAnimated:YES completion:^(){
[s performSegueWithIdentifier:@"showSegue" sender:nil]; [Environment messageIdentifier:identifier];
}]; }];
} }

@ -19,6 +19,7 @@
// Do any additional setup after loading the view. // Do any additional setup after loading the view.
[self initializeSocketStatusBar]; [self initializeSocketStatusBar];
[self initializeObserver]; [self initializeObserver];
[TSSocketManager sendNotification];
} }
- (void)didReceiveMemoryWarning { - (void)didReceiveMemoryWarning {
@ -42,8 +43,6 @@
[[NSNotificationCenter defaultCenter] removeObserver:self name:SocketOpenedNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:SocketOpenedNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:SocketClosedNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:SocketClosedNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:SocketConnectingNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:SocketConnectingNotification object:nil];
} }
#pragma mark - Socket Status Notifications #pragma mark - Socket Status Notifications

@ -9,6 +9,7 @@
#import "UIUtil.h" #import "UIUtil.h"
#import "InboxTableViewCell.h" #import "InboxTableViewCell.h"
#import "Environment.h"
#import "MessagesViewController.h" #import "MessagesViewController.h"
#import "SignalsViewController.h" #import "SignalsViewController.h"
#import "TSStorageManager.h" #import "TSStorageManager.h"
@ -44,6 +45,10 @@ static NSString *const kSegueIndentifier = @"showSegue";
@implementation SignalsViewController @implementation SignalsViewController
- (void)awakeFromNib{
[[Environment getCurrent] setSignalsViewController:self];
}
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
@ -60,9 +65,6 @@ static NSString *const kSegueIndentifier = @"showSegue";
selector:@selector(yapDatabaseModified:) selector:@selector(yapDatabaseModified:)
name:TSUIDatabaseConnectionDidUpdateNotification name:TSUIDatabaseConnectionDidUpdateNotification
object:nil]; object:nil];
[TSSocketManager becomeActive];
} }
-(void)viewWillAppear:(BOOL)animated -(void)viewWillAppear:(BOOL)animated
@ -141,8 +143,6 @@ static NSString *const kSegueIndentifier = @"showSegue";
[tableView deselectRowAtIndexPath:indexPath animated:NO]; [tableView deselectRowAtIndexPath:indexPath animated:NO];
} }
#pragma mark - Navigation #pragma mark - Navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

Loading…
Cancel
Save