diff --git a/Session/DMs/NewDMVC.swift b/Session/DMs/NewDMVC.swift index e8cbf7afb..c6ff34141 100644 --- a/Session/DMs/NewDMVC.swift +++ b/Session/DMs/NewDMVC.swift @@ -40,15 +40,15 @@ final class NewDMVC : BaseVC, UIPageViewControllerDataSource, UIPageViewControll init(sessionID: String) { super.init(nibName: nil, bundle: nil) - enterPublicKeyVC.setSessionID(sessionID: sessionID) + enterPublicKeyVC.setSessionID(to: sessionID) } - required init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) + required init?(coder: NSCoder) { + super.init(coder: coder) } - override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { - super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) + override init(nibName: String?, bundle: Bundle?) { + super.init(nibName: nibName, bundle: bundle) } // MARK: Lifecycle @@ -217,10 +217,6 @@ private final class EnterPublicKeyVC : UIViewController { return result }() - func setSessionID(sessionID: String){ - self.publicKeyTextView.insertText(sessionID); - } - // MARK: Lifecycle override func viewDidLoad() { // Remove background color @@ -277,6 +273,10 @@ private final class EnterPublicKeyVC : UIViewController { } // MARK: General + func setSessionID(to sessionID: String){ + publicKeyTextView.text = sessionID + } + func constrainHeight(to height: CGFloat) { view.set(.height, to: height) } diff --git a/Session/Home/HomeVC.swift b/Session/Home/HomeVC.swift index 23e42d7cc..de966618f 100644 --- a/Session/Home/HomeVC.swift +++ b/Session/Home/HomeVC.swift @@ -66,7 +66,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv explanationLabel.text = NSLocalizedString("vc_home_empty_state_message", comment: "") let createNewPrivateChatButton = Button(style: .prominentOutline, size: .large) createNewPrivateChatButton.setTitle(NSLocalizedString("vc_home_empty_state_button_title", comment: ""), for: UIControl.State.normal) - createNewPrivateChatButton.addTarget(self, action: #selector(createNewDM as () -> Void), for: UIControl.Event.touchUpInside) + createNewPrivateChatButton.addTarget(self, action: #selector(createNewDM), for: UIControl.Event.touchUpInside) createNewPrivateChatButton.set(.width, to: 196) let result = UIStackView(arrangedSubviews: [ explanationLabel, createNewPrivateChatButton ]) result.axis = .vertical @@ -385,11 +385,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv } else if let thread = thread as? TSGroupThread, thread.isClosedGroup == true { let groupID = thread.groupModel.groupId let groupPublicKey = LKGroupUtilities.getDecodedGroupID(groupID) - do { - try MessageSender.leave(groupPublicKey, using: transaction) - } catch { - // TODO: Handle - } + MessageSender.leave(groupPublicKey, using: transaction).retainUntilComplete() thread.removeAllThreadInteractions(with: transaction) thread.remove(with: transaction) } else { @@ -423,7 +419,8 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv present(navigationController, animated: true, completion: nil) } - @objc func createNewDM(sessionID: String) { + @objc(createNewDMFromDeepLink:) + func createNewDMFromDeepLink(sessionID: String) { let newDMVC = NewDMVC(sessionID: sessionID) let navigationController = OWSNavigationController(rootViewController: newDMVC) present(navigationController, animated: true, completion: nil) diff --git a/Session/Home/NewConversationButtonSet.swift b/Session/Home/NewConversationButtonSet.swift index 3aeab12d2..61ba617e8 100644 --- a/Session/Home/NewConversationButtonSet.swift +++ b/Session/Home/NewConversationButtonSet.swift @@ -218,7 +218,6 @@ protocol NewConversationButtonSetDelegate { func joinOpenGroup() func createNewDM() - func createNewDM(sessionID: String) func createClosedGroup() } diff --git a/Session/Meta/AppDelegate.m b/Session/Meta/AppDelegate.m index f3c9b66db..8b056a529 100644 --- a/Session/Meta/AppDelegate.m +++ b/Session/Meta/AppDelegate.m @@ -790,41 +790,35 @@ static NSTimeInterval launchStartedAt; } # pragma mark - App Link -- (BOOL)application:(UIApplication *)app - openURL:(NSURL *)incomingURL - options:(NSDictionary *)options + +- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { - NSURLComponents *components = [[NSURLComponents alloc] initWithURL:incomingURL resolvingAgainstBaseURL: true]; + NSURLComponents *components = [[NSURLComponents alloc] initWithURL:url resolvingAgainstBaseURL:true]; // URL Scheme is sessionmessenger://DM?sessionID=1234 // We can later add more parameters like message etc. NSString *intent = components.host; - if(intent != nil){ - //Handle DM - if([intent isEqualToString: @"DM"]){ - NSArray *params = [components queryItems]; - NSPredicate *sessionIDPredicate = [NSPredicate predicateWithFormat:@"name == %@", @"sessionID"]; - NSArray *matches = [params filteredArrayUsingPredicate: sessionIDPredicate]; - if(matches.count > 0){ - NSString *sessionID = matches.firstObject.value; - if(sessionID != nil){ - [self handleDM: sessionID]; - return true; - } - } + if (intent != nil && [intent isEqualToString:@"DM"]) { + NSArray *params = [components queryItems]; + NSPredicate *sessionIDPredicate = [NSPredicate predicateWithFormat:@"name == %@", @"sessionID"]; + NSArray *matches = [params filteredArrayUsingPredicate:sessionIDPredicate]; + if (matches.count > 0) { + NSString *sessionID = matches.firstObject.value; + [self createNewDMFromDeepLink:sessionID]; + return YES; } } - return false; + return NO; } -- (void)handleDM:(NSString *)sessionID +- (void)createNewDMFromDeepLink:(NSString *)sessionID { UIViewController *viewController = self.window.rootViewController; - if([viewController class] == [OWSNavigationController class]){ - UIViewController *rVC = ((OWSNavigationController *)viewController).visibleViewController; - if([rVC class] == [HomeVC class]){ - HomeVC *homeVC = (HomeVC *)rVC; - [homeVC createNewDMWithSessionID: sessionID]; + if ([viewController class] == [OWSNavigationController class]) { + UIViewController *visibleVC = ((OWSNavigationController *)viewController).visibleViewController; + if ([visibleVC isKindOfClass:HomeVC.class]) { + HomeVC *homeVC = (HomeVC *)visibleVC; + [homeVC createNewDMFromDeepLink:sessionID]; } } }