Normalize conversation presentation logic.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent f3fa107e47
commit b6d782046a

@ -442,7 +442,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
viewController.attachment = attachment; viewController.attachment = attachment;
UINavigationController *navigationController = UINavigationController *navigationController =
[[UINavigationController alloc] initWithRootViewController:viewController]; [[UINavigationController alloc] initWithRootViewController:viewController];
[[[Environment getCurrent] signalsViewController] presentTopLevelModalViewController:navigationController [[[Environment getCurrent] homeViewController] presentTopLevelModalViewController:navigationController
animateDismissal:NO animateDismissal:NO
animatePresentation:YES]; animatePresentation:YES];
} }
@ -529,7 +529,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
// If app has not re-entered active, show screen protection if necessary. // If app has not re-entered active, show screen protection if necessary.
[self showScreenProtection]; [self showScreenProtection];
} }
[[[Environment getCurrent] signalsViewController] updateInboxCountLabel]; [[[Environment getCurrent] homeViewController] updateInboxCountLabel];
[application endBackgroundTask:bgTask]; [application endBackgroundTask:bgTask];
}); });
} }
@ -542,7 +542,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem
completionHandler:(void (^)(BOOL succeeded))completionHandler { completionHandler:(void (^)(BOOL succeeded))completionHandler {
if ([TSAccountManager isRegistered]) { if ([TSAccountManager isRegistered]) {
[[Environment getCurrent].signalsViewController showNewConversationView]; [[Environment getCurrent].homeViewController showNewConversationView];
completionHandler(YES); completionHandler(YES);
} else { } else {
UIAlertController *controller = UIAlertController *controller =
@ -555,8 +555,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
handler:^(UIAlertAction *_Nonnull action){ handler:^(UIAlertAction *_Nonnull action){
}]]; }]];
[[Environment getCurrent] [[Environment getCurrent].homeViewController.presentedViewController presentViewController:controller
.signalsViewController.presentedViewController presentViewController:controller
animated:YES animated:YES
completion:^{ completion:^{
completionHandler(NO); completionHandler(NO);

@ -625,7 +625,7 @@ NS_ASSUME_NONNULL_BEGIN
[self dismissViewControllerAnimated:YES [self dismissViewControllerAnimated:YES
completion:^() { completion:^() {
[Environment messageIdentifier:recipientId withCompose:YES]; [Environment presentConversationForRecipientId:recipientId withCompose:YES];
}]; }];
} }

@ -459,7 +459,7 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
[self dismissViewControllerAnimated:YES [self dismissViewControllerAnimated:YES
completion:^{ completion:^{
// Pop to new group thread. // Pop to new group thread.
[Environment messageGroup:thread]; [Environment presentConversationForThread:thread];
}]; }];
}); });
@ -478,7 +478,7 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
failedMessageType:TSErrorMessageGroupCreationFailed] failedMessageType:TSErrorMessageGroupCreationFailed]
save]; save];
[Environment messageGroup:thread]; [Environment presentConversationForThread:thread];
}]; }];
}); });
}; };

@ -67,7 +67,7 @@ NS_ASSUME_NONNULL_BEGIN
[ThreadUtil addThreadToProfileWhitelistIfEmptyContactThread:thread]; [ThreadUtil addThreadToProfileWhitelistIfEmptyContactThread:thread];
[ThreadUtil sendMessageWithAttachment:self.attachment inThread:thread messageSender:self.messageSender]; [ThreadUtil sendMessageWithAttachment:self.attachment inThread:thread messageSender:self.messageSender];
[Environment messageThreadId:thread.uniqueId]; [Environment presentConversationForRecipientId:thread.uniqueId];
} }
- (BOOL)canSelectBlockedContact - (BOOL)canSelectBlockedContact

@ -408,12 +408,12 @@ NS_ASSUME_NONNULL_BEGIN
{ {
OWSAssert(recipientId.length > 0); OWSAssert(recipientId.length > 0);
[Environment messageIdentifier:recipientId withCompose:YES]; [Environment presentConversationForRecipientId:recipientId withCompose:YES];
} }
- (void)callMember:(NSString *)recipientId - (void)callMember:(NSString *)recipientId
{ {
[Environment callUserWithIdentifier:recipientId]; [Environment callRecipientId:recipientId];
} }
- (void)showSafetyNumberView:(NSString *)recipientId - (void)showSafetyNumberView:(NSString *)recipientId

@ -37,7 +37,7 @@ extension CallUIAdaptee {
let callViewController = CallViewController(call: call) let callViewController = CallViewController(call: call)
callViewController.modalTransitionStyle = .crossDissolve callViewController.modalTransitionStyle = .crossDissolve
guard let presentingViewController = Environment.getCurrent().signalsViewController else { guard let presentingViewController = Environment.getCurrent().homeViewController else {
owsFail("in \(#function) view controller unexpectedly nil") owsFail("in \(#function) view controller unexpectedly nil")
return return
} }

@ -49,7 +49,7 @@
@property (nonatomic, readonly) PropertyListPreferences *preferences; @property (nonatomic, readonly) PropertyListPreferences *preferences;
@property (nonatomic, readonly) HomeViewController *signalsViewController; @property (nonatomic, readonly) HomeViewController *homeViewController;
@property (nonatomic, readonly, weak) UINavigationController *signUpFlowNavigationController; @property (nonatomic, readonly, weak) UINavigationController *signUpFlowNavigationController;
+ (Environment *)getCurrent; + (Environment *)getCurrent;
@ -59,12 +59,12 @@
+ (void)resetAppData; + (void)resetAppData;
- (void)setHomeViewController:(HomeViewController *)signalsViewController; - (void)setHomeViewController:(HomeViewController *)homeViewController;
- (void)setSignUpFlowNavigationController:(UINavigationController *)signUpFlowNavigationController; - (void)setSignUpFlowNavigationController:(UINavigationController *)signUpFlowNavigationController;
+ (void)messageThreadId:(NSString *)threadId; + (void)presentConversationForRecipientId:(NSString *)recipientId;
+ (void)messageIdentifier:(NSString *)identifier withCompose:(BOOL)compose; + (void)presentConversationForRecipientId:(NSString *)recipientId withCompose:(BOOL)compose;
+ (void)callUserWithIdentifier:(NSString *)identifier; + (void)callRecipientId:(NSString *)recipientId;
+ (void)messageGroup:(TSGroupThread *)groupThread; + (void)presentConversationForThread:(TSGroupThread *)groupThread;
@end @end

@ -12,6 +12,7 @@
#import "TSContactThread.h" #import "TSContactThread.h"
#import "TSGroupThread.h" #import "TSGroupThread.h"
#import <SignalServiceKit/ContactsUpdater.h> #import <SignalServiceKit/ContactsUpdater.h>
#import <SignalServiceKit/Threading.h>
static Environment *environment = nil; static Environment *environment = nil;
@ -171,69 +172,75 @@ static Environment *environment = nil;
return _preferences; return _preferences;
} }
- (void)setHomeViewController:(HomeViewController *)signalsViewController - (void)setHomeViewController:(HomeViewController *)homeViewController
{ {
_signalsViewController = signalsViewController; _homeViewController = homeViewController;
} }
- (void)setSignUpFlowNavigationController:(UINavigationController *)navigationController { - (void)setSignUpFlowNavigationController:(UINavigationController *)navigationController {
_signUpFlowNavigationController = navigationController; _signUpFlowNavigationController = navigationController;
} }
+ (void)messageThreadId:(NSString *)threadId { + (void)presentConversationForRecipientId:(NSString *)recipientId
TSThread *thread = [TSThread fetchObjectWithUniqueID:threadId]; {
[self presentConversationForRecipientId:recipientId keyboardOnViewAppearing:YES callOnViewAppearing:NO];
if (!thread) { }
DDLogWarn(@"We get UILocalNotifications with unknown threadId: %@", threadId);
return;
}
if ([thread isGroupThread]) {
[self messageGroup:(TSGroupThread *)thread];
} else {
Environment *env = [self getCurrent];
HomeViewController *vc = env.signalsViewController;
UIViewController *topvc = vc.navigationController.topViewController;
if ([topvc isKindOfClass:[ConversationViewController class]]) { + (void)presentConversationForRecipientId:(NSString *)recipientId withCompose:(BOOL)compose
ConversationViewController *mvc = (ConversationViewController *)topvc; {
if ([mvc.thread.uniqueId isEqualToString:threadId]) { [self presentConversationForRecipientId:recipientId keyboardOnViewAppearing:compose callOnViewAppearing:NO];
[mvc popKeyBoard];
return;
}
}
[self messageIdentifier:((TSContactThread *)thread).contactIdentifier withCompose:YES];
}
} }
+ (void)messageIdentifier:(NSString *)identifier withCompose:(BOOL)compose { + (void)callRecipientId:(NSString *)recipientId
Environment *env = [self getCurrent]; {
HomeViewController *vc = env.signalsViewController; [self presentConversationForRecipientId:recipientId keyboardOnViewAppearing:NO callOnViewAppearing:YES];
}
+ (void)presentConversationForRecipientId:(NSString *)recipientId
keyboardOnViewAppearing:(BOOL)keyboardOnViewAppearing
callOnViewAppearing:(BOOL)callOnViewAppearing
{
[[TSStorageManager sharedManager].dbReadWriteConnection [[TSStorageManager sharedManager].dbReadWriteConnection
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
TSThread *thread = [TSContactThread getOrCreateThreadWithContactId:identifier transaction:transaction]; TSThread *thread = [TSContactThread getOrCreateThreadWithContactId:recipientId transaction:transaction];
[vc presentThread:thread keyboardOnViewAppearing:YES callOnViewAppearing:NO]; dispatch_async(dispatch_get_main_queue(), ^{
[self presentConversationForThread:thread
keyboardOnViewAppearing:keyboardOnViewAppearing
callOnViewAppearing:callOnViewAppearing];
});
}]; }];
} }
+ (void)callUserWithIdentifier:(NSString *)identifier + (void)presentConversationForThread:(TSThread *)thread
{ {
Environment *env = [self getCurrent]; [self presentConversationForThread:thread keyboardOnViewAppearing:YES callOnViewAppearing:NO];
HomeViewController *vc = env.signalsViewController;
[[TSStorageManager sharedManager].dbReadWriteConnection
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
TSThread *thread = [TSContactThread getOrCreateThreadWithContactId:identifier transaction:transaction];
[vc presentThread:thread keyboardOnViewAppearing:NO callOnViewAppearing:YES];
}];
} }
+ (void)messageGroup:(TSGroupThread *)groupThread { + (void)presentConversationForThread:(TSThread *)thread
Environment *env = [self getCurrent]; keyboardOnViewAppearing:(BOOL)keyboardOnViewAppearing
HomeViewController *vc = env.signalsViewController; callOnViewAppearing:(BOOL)callOnViewAppearing
{
if (!thread) {
OWSFail(@"%@ Can't present nil thread.", self.tag);
return;
}
DispatchMainThreadSafe(^{
UIViewController *frontmostVC = [[UIApplication sharedApplication] frontmostViewController];
if ([frontmostVC isKindOfClass:[ConversationViewController class]]) {
ConversationViewController *conversationVC = (ConversationViewController *)frontmostVC;
if ([conversationVC.thread.uniqueId isEqualToString:thread.uniqueId]) {
[conversationVC popKeyBoard];
return;
}
}
[vc presentThread:groupThread keyboardOnViewAppearing:YES callOnViewAppearing:NO]; Environment *env = [self getCurrent];
[env.homeViewController presentThread:thread
keyboardOnViewAppearing:keyboardOnViewAppearing
callOnViewAppearing:callOnViewAppearing];
});
} }
+ (void)resetAppData { + (void)resetAppData {

@ -118,7 +118,7 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
NSString *threadId = notification.userInfo[Signal_Thread_UserInfo_Key]; NSString *threadId = notification.userInfo[Signal_Thread_UserInfo_Key];
if (threadId && [TSThread fetchObjectWithUniqueID:threadId]) { if (threadId && [TSThread fetchObjectWithUniqueID:threadId]) {
[Environment messageThreadId:threadId]; [Environment presentConversationForRecipientId:threadId];
} }
} }
@ -213,12 +213,12 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
completionHandler(); completionHandler();
} else if ([identifier isEqualToString:PushManagerActionsShowThread]) { } else if ([identifier isEqualToString:PushManagerActionsShowThread]) {
NSString *threadId = notification.userInfo[Signal_Thread_UserInfo_Key]; NSString *threadId = notification.userInfo[Signal_Thread_UserInfo_Key];
[Environment messageThreadId:threadId]; [Environment presentConversationForRecipientId:threadId];
completionHandler(); completionHandler();
} else { } else {
OWSFail(@"%@ Unhandled action with identifier: %@", self.tag, identifier); OWSFail(@"%@ Unhandled action with identifier: %@", self.tag, identifier);
NSString *threadId = notification.userInfo[Signal_Thread_UserInfo_Key]; NSString *threadId = notification.userInfo[Signal_Thread_UserInfo_Key];
[Environment messageThreadId:threadId]; [Environment presentConversationForRecipientId:threadId];
completionHandler(); completionHandler();
} }
} }
@ -234,7 +234,7 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
[thread markAllAsReadWithTransaction:transaction]; [thread markAllAsReadWithTransaction:transaction];
} }
completionBlock:^{ completionBlock:^{
[[[Environment getCurrent] signalsViewController] updateInboxCountLabel]; [[[Environment getCurrent] homeViewController] updateInboxCountLabel];
[self cancelNotificationsWithThreadId:threadId]; [self cancelNotificationsWithThreadId:threadId];
completionHandler(); completionHandler();

Loading…
Cancel
Save