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 "RecentCallManager.h"
#import "Release.h"
#import "TSSocketManager.h"
#import "TSStorageManager.h"
#import "TSAccountManager.h"
#import "Util.h"
@ -122,10 +123,10 @@
if (latestCall == nil){
return;
}
InCallViewController *callViewController = [InCallViewController inCallViewControllerWithCallState:latestCall
andOptionallyKnownContact:latestCall.potentiallySpecifiedContact];
if (latestCall.initiatedLocally == false){
[self.callPickUpFuture.future thenDo:^(NSNumber *accept) {
if ([accept isEqualToNumber:@YES]) {
@ -135,11 +136,13 @@
}
}];
}
[self.window.rootViewController dismissViewControllerAnimated:NO completion:nil];
[self.window.rootViewController presentViewController:callViewController animated:NO completion:nil];
} onThread:NSThread.mainThread untilCancelled:nil];
[TSSocketManager becomeActive];
return YES;
}

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

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

@ -10,6 +10,7 @@
#import "PreferencesUtil.h"
#import "PhoneNumberDirectoryFilterManager.h"
#import "SignalKeyingStorage.h"
#import "SignalsViewController.h"
#define isRegisteredUserDefaultString @"isRegistered"
@ -161,7 +162,30 @@ phoneDirectoryManager;
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];
[Environment.preferences clear];
if (self.preferences.loggingIsEnabled) {

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

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

@ -11,6 +11,8 @@
#import "ActionContactDetailCell.h"
#import "UIUtil.h"
#import "DJWActionSheet.h"
#import "Environment.h"
#import "PhoneManager.h"
#define kImageRadius 50.0f
#define kMinRows 3
@ -170,7 +172,7 @@ static NSString *const kContactDetailSegue = @"DetailSegue";
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 addTarget:self action:@selector(initiateRedPhoneCall) forControlEvents:UIControlEventTouchUpInside];
} 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.enabled = NO;
@ -179,12 +181,66 @@ static NSString *const kContactDetailSegue = @"DetailSegue";
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 addTarget:self action:@selector(openTextSecureConversation) forControlEvents:UIControlEventTouchUpInside];
} 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.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
@ -322,7 +378,4 @@ static NSString *const kContactDetailSegue = @"DetailSegue";
return kMinRows + numEmails + numPhoneNumbers + numNotes;
}
@end

@ -132,15 +132,10 @@
-(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:^(){
[s performSegueWithIdentifier:@"showSegue" sender:nil];
[Environment messageIdentifier:identifier];
}];
}

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

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

Loading…
Cancel
Save