Add a SignOutFlowPresenter. (#6854)

Used in AllChats, UserSessions and Settings.
(TabBarCoordinator is unnecessary as signout will be removed from there).
This commit is contained in:
Doug
2022-10-13 14:36:30 +01:00
committed by GitHub
parent 8fa639f96e
commit 7023196ec3
5 changed files with 225 additions and 235 deletions
@@ -28,6 +28,7 @@ final class UserSessionsFlowCoordinator: Coordinator, Presentable {
private let navigationRouter: NavigationRouterType
private var reauthenticationPresenter: ReauthenticationCoordinatorBridgePresenter?
private var signOutFlowPresenter: SignOutFlowPresenter?
private var errorPresenter: MXKErrorPresentation
private var indicatorPresenter: UserIndicatorTypePresenterProtocol
private var loadingIndicator: UserIndicator?
@@ -167,6 +168,11 @@ final class UserSessionsFlowCoordinator: Coordinator, Presentable {
/// Shows a confirmation dialog to the user to sign out of a session.
private func showLogoutConfirmation(for sessionInfo: UserSessionInfo) {
guard !sessionInfo.isCurrent else {
showLogoutConfirmationForCurrentSession()
return
}
// Use a UIAlertController as we don't have confirmationDialog in SwiftUI on iOS 14.
let alert = UIAlertController(title: VectorL10n.signOutConfirmationMessage, message: nil, preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: VectorL10n.signOut, style: .destructive) { [weak self] _ in
@@ -178,6 +184,14 @@ final class UserSessionsFlowCoordinator: Coordinator, Presentable {
navigationRouter.present(alert, animated: true)
}
private func showLogoutConfirmationForCurrentSession() {
let flowPresenter = SignOutFlowPresenter(session: parameters.session, presentingViewController: toPresentable())
flowPresenter.delegate = self
flowPresenter.start()
signOutFlowPresenter = flowPresenter
}
/// Prompts the user to authenticate (if necessary) in order to log out of a specific session.
private func showLogoutAuthentication(for sessionInfo: UserSessionInfo) {
startLoading()
@@ -340,6 +354,22 @@ final class UserSessionsFlowCoordinator: Coordinator, Presentable {
}
}
// MARK: SignOutFlowPresenter
extension UserSessionsFlowCoordinator: SignOutFlowPresenterDelegate {
func signOutFlowPresenterDidStartLoading(_ presenter: SignOutFlowPresenter) {
startLoading()
}
func signOutFlowPresenterDidStopLoading(_ presenter: SignOutFlowPresenter) {
stopLoading()
}
func signOutFlowPresenter(_ presenter: SignOutFlowPresenter, didFailWith error: Error) {
errorPresenter.presentError(from: toPresentable(), forError: error, animated: true, handler: { })
}
}
// MARK: CrossSigningSetupCoordinatorDelegate
extension UserSessionsFlowCoordinator: CrossSigningSetupCoordinatorDelegate {