|
|
|
@ -12,6 +12,7 @@
|
|
|
|
|
#import "TSContactThread.h"
|
|
|
|
|
#import "TSGroupThread.h"
|
|
|
|
|
#import <SignalServiceKit/ContactsUpdater.h>
|
|
|
|
|
#import <SignalServiceKit/Threading.h>
|
|
|
|
|
|
|
|
|
|
static Environment *environment = nil;
|
|
|
|
|
|
|
|
|
@ -171,69 +172,82 @@ static Environment *environment = nil;
|
|
|
|
|
return _preferences;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setHomeViewController:(HomeViewController *)signalsViewController
|
|
|
|
|
- (void)setHomeViewController:(HomeViewController *)homeViewController
|
|
|
|
|
{
|
|
|
|
|
_signalsViewController = signalsViewController;
|
|
|
|
|
_homeViewController = homeViewController;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setSignUpFlowNavigationController:(UINavigationController *)navigationController {
|
|
|
|
|
_signUpFlowNavigationController = navigationController;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (void)messageThreadId:(NSString *)threadId {
|
|
|
|
|
TSThread *thread = [TSThread fetchObjectWithUniqueID:threadId];
|
|
|
|
|
|
|
|
|
|
if (!thread) {
|
|
|
|
|
DDLogWarn(@"We get UILocalNotifications with unknown threadId: %@", threadId);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
+ (void)presentConversationForRecipientId:(NSString *)recipientId
|
|
|
|
|
{
|
|
|
|
|
[self presentConversationForRecipientId:recipientId keyboardOnViewAppearing:YES callOnViewAppearing:NO];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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]]) {
|
|
|
|
|
ConversationViewController *mvc = (ConversationViewController *)topvc;
|
|
|
|
|
if ([mvc.thread.uniqueId isEqualToString:threadId]) {
|
|
|
|
|
[mvc popKeyBoard];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[self messageIdentifier:((TSContactThread *)thread).contactIdentifier withCompose:YES];
|
|
|
|
|
}
|
|
|
|
|
+ (void)presentConversationForRecipientId:(NSString *)recipientId withCompose:(BOOL)compose
|
|
|
|
|
{
|
|
|
|
|
[self presentConversationForRecipientId:recipientId keyboardOnViewAppearing:compose callOnViewAppearing:NO];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (void)messageIdentifier:(NSString *)identifier withCompose:(BOOL)compose {
|
|
|
|
|
Environment *env = [self getCurrent];
|
|
|
|
|
HomeViewController *vc = env.signalsViewController;
|
|
|
|
|
+ (void)callRecipientId:(NSString *)recipientId
|
|
|
|
|
{
|
|
|
|
|
[self presentConversationForRecipientId:recipientId keyboardOnViewAppearing:NO callOnViewAppearing:YES];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[TSStorageManager sharedManager].dbReadWriteConnection
|
|
|
|
|
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
|
|
|
|
TSThread *thread = [TSContactThread getOrCreateThreadWithContactId:identifier transaction:transaction];
|
|
|
|
|
[vc presentThread:thread keyboardOnViewAppearing:YES callOnViewAppearing:NO];
|
|
|
|
|
}];
|
|
|
|
|
+ (void)presentConversationForRecipientId:(NSString *)recipientId
|
|
|
|
|
keyboardOnViewAppearing:(BOOL)keyboardOnViewAppearing
|
|
|
|
|
callOnViewAppearing:(BOOL)callOnViewAppearing
|
|
|
|
|
{
|
|
|
|
|
// At most one.
|
|
|
|
|
OWSAssert(!keyboardOnViewAppearing || !callOnViewAppearing);
|
|
|
|
|
|
|
|
|
|
DispatchMainThreadSafe(^{
|
|
|
|
|
__block TSThread *thread = nil;
|
|
|
|
|
[[TSStorageManager sharedManager].dbReadWriteConnection
|
|
|
|
|
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
|
|
|
|
thread = [TSContactThread getOrCreateThreadWithContactId:recipientId transaction:transaction];
|
|
|
|
|
}];
|
|
|
|
|
[self presentConversationForThread:thread
|
|
|
|
|
keyboardOnViewAppearing:keyboardOnViewAppearing
|
|
|
|
|
callOnViewAppearing:callOnViewAppearing];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (void)callUserWithIdentifier:(NSString *)identifier
|
|
|
|
|
+ (void)presentConversationForThread:(TSThread *)thread
|
|
|
|
|
{
|
|
|
|
|
Environment *env = [self getCurrent];
|
|
|
|
|
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];
|
|
|
|
|
}];
|
|
|
|
|
[self presentConversationForThread:thread keyboardOnViewAppearing:YES callOnViewAppearing:NO];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (void)messageGroup:(TSGroupThread *)groupThread {
|
|
|
|
|
Environment *env = [self getCurrent];
|
|
|
|
|
HomeViewController *vc = env.signalsViewController;
|
|
|
|
|
+ (void)presentConversationForThread:(TSThread *)thread
|
|
|
|
|
keyboardOnViewAppearing:(BOOL)keyboardOnViewAppearing
|
|
|
|
|
callOnViewAppearing:(BOOL)callOnViewAppearing
|
|
|
|
|
{
|
|
|
|
|
// At most one.
|
|
|
|
|
OWSAssert(!keyboardOnViewAppearing || !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 {
|
|
|
|
|