diff --git a/submodules/TelegramUI/Components/PeerSelectionController/Sources/PeerSelectionController.swift b/submodules/TelegramUI/Components/PeerSelectionController/Sources/PeerSelectionController.swift index d5361bc583..a3972f832f 100644 --- a/submodules/TelegramUI/Components/PeerSelectionController/Sources/PeerSelectionController.swift +++ b/submodules/TelegramUI/Components/PeerSelectionController/Sources/PeerSelectionController.swift @@ -228,6 +228,7 @@ public final class PeerSelectionControllerImpl: ViewController, PeerSelectionCon replaceImpl = { [weak controller] c in controller?.replace(with: c) } + strongSelf.peerSelectionNode.pushedController = controller strongSelf.push(controller) } else { strongSelf.selectTab(id: id) @@ -330,6 +331,7 @@ public final class PeerSelectionControllerImpl: ViewController, PeerSelectionCon ) ) controller.peerSelected = self.peerSelected + self.peerSelectionNode.pushedController = controller self.push(controller) } else { peerSelected(.channel(peer), threadId) @@ -373,6 +375,7 @@ public final class PeerSelectionControllerImpl: ViewController, PeerSelectionCon ) ) controller.peerSelected = strongSelf.peerSelected + strongSelf.peerSelectionNode.pushedController = controller strongSelf.push(controller) } else { peerSelected(peer, threadId) @@ -626,4 +629,16 @@ public final class PeerSelectionControllerImpl: ViewController, PeerSelectionCon } }) } + + override public func dismiss(completion: (() -> Void)? = nil) { + guard let navigationController = self.navigationController as? NavigationController else { + return + } + var viewControllers = navigationController.viewControllers + viewControllers.removeAll(where: { $0 === self }) + if let pushedController = self.peerSelectionNode.pushedController { + viewControllers.removeAll(where: { $0 === pushedController }) + } + navigationController.setViewControllers(viewControllers, animated: true) + } } diff --git a/submodules/TelegramUI/Components/PeerSelectionController/Sources/PeerSelectionControllerNode.swift b/submodules/TelegramUI/Components/PeerSelectionController/Sources/PeerSelectionControllerNode.swift index 9dee157d98..10e7c98abb 100644 --- a/submodules/TelegramUI/Components/PeerSelectionController/Sources/PeerSelectionControllerNode.swift +++ b/submodules/TelegramUI/Components/PeerSelectionController/Sources/PeerSelectionControllerNode.swift @@ -102,6 +102,8 @@ final class PeerSelectionControllerNode: ASDisplayNode { private var countPanelNode: PeersCountPanelNode? + weak var pushedController: ViewController? + private var readyValue = Promise() var ready: Signal { return self.readyValue.get() @@ -348,6 +350,7 @@ final class PeerSelectionControllerNode: ASDisplayNode { replaceImpl = { [weak controller] c in controller?.replace(with: c) } + strongSelf.pushedController = controller strongSelf.controller?.push(controller) } self.addSubnode(mainContainerNode)