mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
192 lines
6.0 KiB
Matlab
192 lines
6.0 KiB
Matlab
8 years ago
|
//
|
||
6 years ago
|
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||
8 years ago
|
//
|
||
|
|
||
8 years ago
|
#import "SignalApp.h"
|
||
7 years ago
|
#import "AppDelegate.h"
|
||
8 years ago
|
#import "ConversationViewController.h"
|
||
6 years ago
|
#import "Session-Swift.h"
|
||
5 years ago
|
#import <SignalCoreKit/Threading.h>
|
||
5 years ago
|
#import <SignalUtilitiesKit/DebugLogger.h>
|
||
4 years ago
|
#import <SessionMessagingKit/Environment.h>
|
||
4 years ago
|
#import <SessionMessagingKit/OWSPrimaryStorage.h>
|
||
|
#import <SessionMessagingKit/TSContactThread.h>
|
||
|
#import <SessionMessagingKit/TSGroupThread.h>
|
||
11 years ago
|
|
||
7 years ago
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
||
8 years ago
|
@implementation SignalApp
|
||
|
|
||
|
+ (instancetype)sharedApp
|
||
|
{
|
||
|
static SignalApp *sharedApp = nil;
|
||
|
static dispatch_once_t onceToken;
|
||
|
dispatch_once(&onceToken, ^{
|
||
|
sharedApp = [[self alloc] initDefault];
|
||
|
});
|
||
|
return sharedApp;
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
- (instancetype)initDefault
|
||
9 years ago
|
{
|
||
|
self = [super init];
|
||
8 years ago
|
|
||
9 years ago
|
if (!self) {
|
||
|
return self;
|
||
|
}
|
||
|
|
||
8 years ago
|
OWSSingletonAssert();
|
||
|
|
||
9 years ago
|
return self;
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
8 years ago
|
#pragma mark - Singletons
|
||
9 years ago
|
|
||
7 years ago
|
- (void)setup {
|
||
7 years ago
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||
|
selector:@selector(didChangeCallLoggingPreference:)
|
||
|
name:OWSPreferencesCallLoggingDidChangeNotification
|
||
|
object:nil];
|
||
|
}
|
||
|
|
||
8 years ago
|
#pragma mark - View Convenience Methods
|
||
11 years ago
|
|
||
7 years ago
|
- (void)presentConversationForRecipientId:(NSString *)recipientId animated:(BOOL)isAnimated
|
||
8 years ago
|
{
|
||
7 years ago
|
[self presentConversationForRecipientId:recipientId action:ConversationViewActionNone animated:(BOOL)isAnimated];
|
||
8 years ago
|
}
|
||
9 years ago
|
|
||
7 years ago
|
- (void)presentConversationForRecipientId:(NSString *)recipientId
|
||
|
action:(ConversationViewAction)action
|
||
|
animated:(BOOL)isAnimated
|
||
8 years ago
|
{
|
||
7 years ago
|
__block TSThread *thread = nil;
|
||
5 years ago
|
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||
|
thread = [TSContactThread getOrCreateThreadWithContactId:recipientId transaction:transaction];
|
||
5 years ago
|
}];
|
||
7 years ago
|
[self presentConversationForThread:thread action:action animated:(BOOL)isAnimated];
|
||
11 years ago
|
}
|
||
|
|
||
7 years ago
|
- (void)presentConversationForThreadId:(NSString *)threadId animated:(BOOL)isAnimated
|
||
8 years ago
|
{
|
||
7 years ago
|
OWSAssertDebug(threadId.length > 0);
|
||
8 years ago
|
|
||
|
TSThread *thread = [TSThread fetchObjectWithUniqueID:threadId];
|
||
|
if (thread == nil) {
|
||
7 years ago
|
OWSFailDebug(@"unable to find thread with id: %@", threadId);
|
||
8 years ago
|
return;
|
||
|
}
|
||
|
|
||
7 years ago
|
[self presentConversationForThread:thread animated:isAnimated];
|
||
8 years ago
|
}
|
||
|
|
||
7 years ago
|
- (void)presentConversationForThread:(TSThread *)thread animated:(BOOL)isAnimated
|
||
8 years ago
|
{
|
||
7 years ago
|
[self presentConversationForThread:thread action:ConversationViewActionNone animated:isAnimated];
|
||
8 years ago
|
}
|
||
|
|
||
7 years ago
|
- (void)presentConversationForThread:(TSThread *)thread action:(ConversationViewAction)action animated:(BOOL)isAnimated
|
||
7 years ago
|
{
|
||
7 years ago
|
[self presentConversationForThread:thread action:action focusMessageId:nil animated:isAnimated];
|
||
7 years ago
|
}
|
||
|
|
||
|
- (void)presentConversationForThread:(TSThread *)thread
|
||
|
action:(ConversationViewAction)action
|
||
|
focusMessageId:(nullable NSString *)focusMessageId
|
||
7 years ago
|
animated:(BOOL)isAnimated
|
||
8 years ago
|
{
|
||
7 years ago
|
OWSAssertIsOnMainThread();
|
||
8 years ago
|
|
||
7 years ago
|
OWSLogInfo(@"");
|
||
7 years ago
|
|
||
8 years ago
|
if (!thread) {
|
||
7 years ago
|
OWSFailDebug(@"Can't present nil thread.");
|
||
8 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
DispatchMainThreadSafe(^{
|
||
|
UIViewController *frontmostVC = [[UIApplication sharedApplication] frontmostViewController];
|
||
6 years ago
|
|
||
8 years ago
|
if ([frontmostVC isKindOfClass:[ConversationViewController class]]) {
|
||
|
ConversationViewController *conversationVC = (ConversationViewController *)frontmostVC;
|
||
|
if ([conversationVC.thread.uniqueId isEqualToString:thread.uniqueId]) {
|
||
|
[conversationVC popKeyBoard];
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
6 years ago
|
|
||
5 years ago
|
[self.homeViewController show:thread with:action highlightedMessageID:focusMessageId animated:isAnimated];
|
||
8 years ago
|
});
|
||
11 years ago
|
}
|
||
|
|
||
6 years ago
|
- (void)presentConversationAndScrollToFirstUnreadMessageForThreadId:(NSString *)threadId animated:(BOOL)isAnimated
|
||
6 years ago
|
{
|
||
|
OWSAssertIsOnMainThread();
|
||
6 years ago
|
OWSAssertDebug(threadId.length > 0);
|
||
6 years ago
|
|
||
|
OWSLogInfo(@"");
|
||
|
|
||
6 years ago
|
TSThread *thread = [TSThread fetchObjectWithUniqueID:threadId];
|
||
|
if (thread == nil) {
|
||
|
OWSFailDebug(@"unable to find thread with id: %@", threadId);
|
||
6 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
DispatchMainThreadSafe(^{
|
||
|
UIViewController *frontmostVC = [[UIApplication sharedApplication] frontmostViewController];
|
||
|
|
||
|
if ([frontmostVC isKindOfClass:[ConversationViewController class]]) {
|
||
|
ConversationViewController *conversationVC = (ConversationViewController *)frontmostVC;
|
||
|
if ([conversationVC.thread.uniqueId isEqualToString:thread.uniqueId]) {
|
||
|
[conversationVC scrollToFirstUnreadMessage:isAnimated];
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
[self.homeViewController show:thread with:ConversationViewActionNone highlightedMessageID:nil animated:isAnimated];
|
||
6 years ago
|
});
|
||
|
}
|
||
|
|
||
7 years ago
|
- (void)didChangeCallLoggingPreference:(NSNotification *)notitication
|
||
|
{
|
||
5 years ago
|
// [AppEnvironment.shared.callService createCallUIAdapter];
|
||
7 years ago
|
}
|
||
|
|
||
8 years ago
|
#pragma mark - Methods
|
||
|
|
||
|
+ (void)resetAppData
|
||
|
{
|
||
5 years ago
|
[self resetAppData:nil];
|
||
|
}
|
||
|
|
||
|
+ (void)resetAppData:(void (^__nullable)(void))onReset {
|
||
8 years ago
|
// This _should_ be wiped out below.
|
||
7 years ago
|
OWSLogError(@"");
|
||
8 years ago
|
[DDLog flushLog];
|
||
|
|
||
7 years ago
|
[OWSStorage resetAllStorage];
|
||
7 years ago
|
[OWSUserProfile resetProfileStorage];
|
||
7 years ago
|
[Environment.shared.preferences clear];
|
||
6 years ago
|
[AppEnvironment.shared.notificationPresenter clearAllNotifications];
|
||
8 years ago
|
|
||
9 years ago
|
[DebugLogger.sharedLogger wipeLogs];
|
||
5 years ago
|
if (onReset != nil) { onReset(); }
|
||
7 years ago
|
exit(0);
|
||
11 years ago
|
}
|
||
|
|
||
7 years ago
|
- (void)showHomeView
|
||
|
{
|
||
5 years ago
|
HomeVC *homeView = [HomeVC new];
|
||
5 years ago
|
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:homeView];
|
||
7 years ago
|
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
||
|
appDelegate.window.rootViewController = navigationController;
|
||
5 years ago
|
OWSAssertDebug([navigationController.topViewController isKindOfClass:[HomeVC class]]);
|
||
6 years ago
|
|
||
|
// Clear the signUpFlowNavigationController.
|
||
|
[self setSignUpFlowNavigationController:nil];
|
||
7 years ago
|
}
|
||
|
|
||
11 years ago
|
@end
|
||
7 years ago
|
|
||
|
NS_ASSUME_NONNULL_END
|