From 2e67bc93743d76bc7c609df0766e0c34a281e359 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Tue, 13 Sep 2022 14:36:11 +1000 Subject: [PATCH] feat: automatically open the community conversation if tapping on suggestion grids to join --- Session/Open Groups/JoinOpenGroupVC.swift | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Session/Open Groups/JoinOpenGroupVC.swift b/Session/Open Groups/JoinOpenGroupVC.swift index 1faad204f..9c228e1f3 100644 --- a/Session/Open Groups/JoinOpenGroupVC.swift +++ b/Session/Open Groups/JoinOpenGroupVC.swift @@ -146,7 +146,7 @@ final class JoinOpenGroupVC: BaseVC, UIPageViewControllerDataSource, UIPageViewC joinOpenGroup(roomToken: room, server: server, publicKey: publicKey) } - fileprivate func joinOpenGroup(roomToken: String, server: String, publicKey: String) { + fileprivate func joinOpenGroup(roomToken: String, server: String, publicKey: String, shouldOpenCommunity: Bool = false) { guard !isJoining, let navigationController: UINavigationController = navigationController else { return } isJoining = true @@ -166,8 +166,24 @@ final class JoinOpenGroupVC: BaseVC, UIPageViewControllerDataSource, UIPageViewC Storage.shared.writeAsync { db in try MessageSender.syncConfiguration(db, forceSyncNow: true).retainUntilComplete() // FIXME: It's probably cleaner to do this inside addOpenGroup(...) } + + let maybeThread: SessionThread? = Storage.shared.write { db in + let threadId: String = OpenGroup.idFor(roomToken: roomToken, server: server) + return try SessionThread.fetchOrCreate(db, id: threadId, variant: .openGroup) + } self?.presentingViewController?.dismiss(animated: true, completion: nil) + + if let thread = maybeThread, shouldOpenCommunity { + SessionApp.presentConversation( + for: thread.id, + threadVariant: thread.variant, + isMessageRequest: false, + action: .compose, + focusInteractionId: nil, + animated: false + ) + } } .catch(on: DispatchQueue.main) { [weak self] error in self?.dismiss(animated: true, completion: nil) // Dismiss the loader @@ -309,7 +325,8 @@ private final class EnterURLVC: UIViewController, UIGestureRecognizerDelegate, O joinOpenGroupVC?.joinOpenGroup( roomToken: room.token, server: OpenGroupAPI.defaultServer, - publicKey: OpenGroupAPI.defaultServerPublicKey + publicKey: OpenGroupAPI.defaultServerPublicKey, + shouldOpenCommunity: true ) }