diff --git a/Monal/Classes/ActiveChatsViewController.m b/Monal/Classes/ActiveChatsViewController.m index a62eab26d..56c1fcf1e 100755 --- a/Monal/Classes/ActiveChatsViewController.m +++ b/Monal/Classes/ActiveChatsViewController.m @@ -26,6 +26,7 @@ #import "MLIQProcessor.h" #import "Quicksy_Country.h" #import +#import "chatViewController.h" #define prependToViewQueue(firstArg, ...) metamacro_if_eq(0, metamacro_argcount(__VA_ARGS__))([self prependToViewQueue:firstArg withId:MLViewIDUnspecified andFile:(char*)__FILE__ andLine:__LINE__ andFunc:(char*)__func__])(_prependToViewQueue(firstArg, __VA_ARGS__)) #define _prependToViewQueue(ownId, block) [self prependToViewQueue:block withId:ownId andFile:(char*)__FILE__ andLine:__LINE__ andFunc:(char*)__func__] @@ -1057,19 +1058,37 @@ -(void) presentChatWithContact:(MLContact*) contact andCompletion:(monal_id_bloc }; [self scrollToContact:contact]; [self showDetailViewController:chatView sender:self]; - if(completion != nil) - completion(@YES); }; //open chat (make sure we have an active buddy for it and add it to our ui, if needed) //but don't animate this if the contact is already present in our list [[DataLayer sharedInstance] addActiveBuddies:contact.contactJid forAccount:contact.accountID]; if([[self getChatArrayForSection:pinnedChats] containsObject:contact] || [[self getChatArrayForSection:unpinnedChats] containsObject:contact]) - presentator(); + { + if([[HelperTools defaultsDB] boolForKey:@"showNewChatView"]) + presentator(); + else + { + [self scrollToContact:contact]; + [self performSegueWithIdentifier:@"showConversation" sender:contact]; + } + if(completion != nil) + completion(@YES); + } else + { [self insertOrMoveContact:contact completion:^(BOOL finished __unused) { - presentator(); + if([[HelperTools defaultsDB] boolForKey:@"showNewChatView"]) + presentator(); + else + { + [self scrollToContact:contact]; + [self performSegueWithIdentifier:@"showConversation" sender:contact]; + } + if(completion != nil) + completion(@YES); }]; + } }]; }]; } @@ -1106,6 +1125,16 @@ -(void) performSegueWithIdentifier:(NSString*) identifier sender:(id) sender -(void) prepareForSegue:(UIStoryboardSegue*) segue sender:(id) sender { DDLogInfo(@"Got segue identifier '%@'", segue.identifier); + + if([segue.identifier isEqualToString:@"showConversation"]) + { + UINavigationController* nav = segue.destinationViewController; + chatViewController* chatVC = (chatViewController*)nav.topViewController; + UIBarButtonItem* barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; + self.navigationItem.backBarButtonItem = barButtonItem; + [chatVC setupWithContact:sender]; + } + if([segue.identifier isEqualToString:@"showDetails"]) { UIViewController* detailsViewController = [[SwiftuiInterface new] makeContactDetails:sender]; @@ -1523,8 +1552,9 @@ -(void) dismissRecursorWithViewControllers:(NSMutableArray*) viewControllers ani -(chatViewController* _Nullable) currentChatView { //TODO: this has to be adapted to the new chatui - return nil; - /* + if([[HelperTools defaultsDB] boolForKey:@"showNewChatView"]) + return nil; + NSArray* controllers = ((UINavigationController*)self.splitViewController.viewControllers[0]).viewControllers; chatViewController* chatView = nil; if(controllers.count > 1) @@ -1532,7 +1562,6 @@ -(chatViewController* _Nullable) currentChatView if(![chatView isKindOfClass:NSClassFromString(@"chatViewController")]) chatView = nil; return chatView; - */ } -(void) scrollToContact:(MLContact*) contact diff --git a/Monal/Classes/DebugView.swift b/Monal/Classes/DebugView.swift index d002f4839..71d88d0a8 100644 --- a/Monal/Classes/DebugView.swift +++ b/Monal/Classes/DebugView.swift @@ -21,6 +21,9 @@ class DebugDefaultDB: ObservableObject { @defaultsDB("hasCompletedOnboarding") var hasCompletedOnboarding: Bool + + @defaultsDB("showNewChatView") + var showNewChatView: Bool } struct LogFilesView: View { @@ -123,6 +126,10 @@ struct CrashTestingView: View { Toggle(isOn: $defaultDB.hasCompletedOnboarding) { Text("Don't show onboarding") } + + Toggle(isOn: $defaultDB.showNewChatView) { + Text("Show new SwiftUI ChatView") + } } Text("The following buttons allow you to forcefully crash the app using several different methods to test the crash handling.") diff --git a/Monal/Classes/MLXMPPManager.m b/Monal/Classes/MLXMPPManager.m index 2083a2f07..25cc1df88 100644 --- a/Monal/Classes/MLXMPPManager.m +++ b/Monal/Classes/MLXMPPManager.m @@ -157,6 +157,8 @@ -(void) defaultSettings [self upgradeBoolUserSettingsIfUnset:@"showAdvancedUI" toDefault:NO]; + [self upgradeBoolUserSettingsIfUnset:@"showNewChatView" toDefault:YES]; + // //always show onboarding on simulator for now // #if TARGET_OS_SIMULATOR // [[HelperTools defaultsDB] setBool:NO forKey:@"hasCompletedOnboarding"];