2021-12-16 11:47:02 +00:00
|
|
|
// File created from FlowTemplate
|
|
|
|
// $ createRootCoordinator.sh Onboarding/SplashScreen Onboarding OnboardingSplashScreen
|
|
|
|
/*
|
|
|
|
Copyright 2021 New Vector Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
/// OnboardingCoordinator input parameters
|
|
|
|
struct OnboardingCoordinatorParameters {
|
|
|
|
|
|
|
|
/// The navigation router that manage physical navigation
|
|
|
|
let router: NavigationRouterType
|
2022-01-12 17:11:29 +00:00
|
|
|
/// The credentials to use if a soft logout has taken place.
|
|
|
|
let softLogoutCredentials: MXCredentials?
|
2021-12-16 11:47:02 +00:00
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
init(router: NavigationRouterType? = nil,
|
|
|
|
softLogoutCredentials: MXCredentials? = nil) {
|
2022-01-17 17:37:59 +00:00
|
|
|
self.router = router ?? NavigationRouter(navigationController: RiotNavigationController(isLockedToPortraitOnPhone: true))
|
2022-01-12 17:11:29 +00:00
|
|
|
self.softLogoutCredentials = softLogoutCredentials
|
2021-12-16 11:47:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@objcMembers
|
2022-01-18 16:48:52 +00:00
|
|
|
/// A coordinator to manage the full onboarding flow with pre-auth screens, authentication and setup screens once signed in.
|
2022-01-27 14:44:10 +00:00
|
|
|
final class OnboardingCoordinator: NSObject, OnboardingCoordinatorProtocol {
|
2022-01-18 16:48:52 +00:00
|
|
|
|
2021-12-16 11:47:02 +00:00
|
|
|
// MARK: - Properties
|
|
|
|
|
|
|
|
// MARK: Private
|
|
|
|
|
|
|
|
private let parameters: OnboardingCoordinatorParameters
|
2022-01-18 16:48:52 +00:00
|
|
|
// TODO: these can likely be consolidated using an additional authType.
|
|
|
|
/// The any registration parameters for AuthenticationViewController from a server provisioning link.
|
2022-01-12 17:11:29 +00:00
|
|
|
private var externalRegistrationParameters: [AnyHashable: Any]?
|
2022-01-18 16:48:52 +00:00
|
|
|
/// A custom homeserver to be shown when logging in.
|
2022-01-12 17:11:29 +00:00
|
|
|
private var customHomeserver: String?
|
2022-01-18 16:48:52 +00:00
|
|
|
/// A custom identity server to be used once logged in.
|
2022-01-12 17:11:29 +00:00
|
|
|
private var customIdentityServer: String?
|
2021-12-16 11:47:02 +00:00
|
|
|
|
2022-01-28 11:53:50 +00:00
|
|
|
// MARK: Navigation State
|
2021-12-16 11:47:02 +00:00
|
|
|
private var navigationRouter: NavigationRouterType {
|
|
|
|
parameters.router
|
|
|
|
}
|
2022-02-17 16:50:02 +00:00
|
|
|
// Keep a strong ref as we need to init authVC early to preload its view
|
|
|
|
private let authenticationCoordinator: AuthenticationCoordinatorProtocol
|
2022-02-28 14:27:32 +00:00
|
|
|
/// A boolean to prevent authentication being shown when already in progress.
|
2022-01-28 11:53:50 +00:00
|
|
|
private var isShowingAuthentication = false
|
|
|
|
|
|
|
|
// MARK: Screen results
|
2022-01-12 17:11:29 +00:00
|
|
|
private var splashScreenResult: OnboardingSplashScreenViewModelResult?
|
2022-02-02 12:24:22 +00:00
|
|
|
private var useCaseResult: OnboardingUseCaseViewModelResult?
|
2022-02-24 17:24:04 +00:00
|
|
|
private var authenticationType: MXKAuthenticationType?
|
|
|
|
private var session: MXSession?
|
|
|
|
|
2022-03-15 11:51:17 +00:00
|
|
|
private var shouldShowDisplayNameScreen = false
|
|
|
|
private var shouldShowAvatarScreen = false
|
|
|
|
|
2022-02-24 17:24:04 +00:00
|
|
|
/// Whether all of the onboarding steps have been completed or not. `false` if there are more screens to be shown.
|
2022-02-28 14:27:32 +00:00
|
|
|
private var onboardingFinished = false
|
|
|
|
/// Whether authentication is complete. `true` once authenticated, verified and the app is ready to be shown.
|
|
|
|
private var authenticationFinished = false
|
2021-12-16 11:47:02 +00:00
|
|
|
|
|
|
|
// MARK: Public
|
|
|
|
|
|
|
|
// Must be used only internally
|
|
|
|
var childCoordinators: [Coordinator] = []
|
2022-01-12 17:11:29 +00:00
|
|
|
var completion: (() -> Void)?
|
2021-12-16 11:47:02 +00:00
|
|
|
|
|
|
|
// MARK: - Setup
|
|
|
|
|
|
|
|
init(parameters: OnboardingCoordinatorParameters) {
|
|
|
|
self.parameters = parameters
|
2022-02-17 16:50:02 +00:00
|
|
|
|
|
|
|
// Preload the authVC (it is *really* slow to load in realtime)
|
2022-02-24 17:24:04 +00:00
|
|
|
let authenticationParameters = AuthenticationCoordinatorParameters(navigationRouter: parameters.router, canPresentAdditionalScreens: false)
|
2022-02-17 16:50:02 +00:00
|
|
|
authenticationCoordinator = AuthenticationCoordinator(parameters: authenticationParameters)
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
super.init()
|
|
|
|
}
|
2021-12-16 11:47:02 +00:00
|
|
|
|
|
|
|
// MARK: - Public
|
|
|
|
|
|
|
|
func start() {
|
2022-01-18 16:48:52 +00:00
|
|
|
// TODO: Manage a separate flow for soft logout that just uses AuthenticationCoordinator
|
|
|
|
if #available(iOS 14.0, *), parameters.softLogoutCredentials == nil, BuildSettings.authScreenShowRegister {
|
2022-01-12 17:11:29 +00:00
|
|
|
showSplashScreen()
|
2021-12-16 11:47:02 +00:00
|
|
|
} else {
|
2022-01-18 16:48:52 +00:00
|
|
|
showAuthenticationScreen()
|
2021-12-16 11:47:02 +00:00
|
|
|
}
|
2022-01-12 17:11:29 +00:00
|
|
|
}
|
2021-12-16 11:47:02 +00:00
|
|
|
|
|
|
|
func toPresentable() -> UIViewController {
|
|
|
|
navigationRouter.toPresentable()
|
|
|
|
}
|
|
|
|
|
2022-01-18 16:48:52 +00:00
|
|
|
/// Force a registration process based on a predefined set of parameters from a server provisioning link.
|
|
|
|
/// For more information see `AuthenticationViewController.externalRegistrationParameters`.
|
2022-01-12 17:11:29 +00:00
|
|
|
func update(externalRegistrationParameters: [AnyHashable: Any]) {
|
|
|
|
self.externalRegistrationParameters = externalRegistrationParameters
|
2022-01-28 11:53:50 +00:00
|
|
|
authenticationCoordinator.update(externalRegistrationParameters: externalRegistrationParameters)
|
2022-01-12 17:11:29 +00:00
|
|
|
}
|
|
|
|
|
2022-01-18 16:48:52 +00:00
|
|
|
/// Set up the authentication screen with the specified homeserver and/or identity server.
|
2022-01-27 14:44:10 +00:00
|
|
|
func updateHomeserver(_ homeserver: String?, andIdentityServer identityServer: String?) {
|
2022-01-12 17:11:29 +00:00
|
|
|
self.customHomeserver = homeserver
|
|
|
|
self.customIdentityServer = identityServer
|
2022-01-28 11:53:50 +00:00
|
|
|
authenticationCoordinator.updateHomeserver(homeserver, andIdentityServer: identityServer)
|
2022-01-12 17:11:29 +00:00
|
|
|
}
|
|
|
|
|
2022-01-18 16:48:52 +00:00
|
|
|
/// When SSO login succeeded, when SFSafariViewController is used, continue login with success parameters.
|
2022-01-12 17:11:29 +00:00
|
|
|
func continueSSOLogin(withToken loginToken: String, transactionID: String) -> Bool {
|
2022-01-28 11:53:50 +00:00
|
|
|
guard isShowingAuthentication else { return false }
|
2022-01-12 17:11:29 +00:00
|
|
|
return authenticationCoordinator.continueSSOLogin(withToken: loginToken, transactionID: transactionID)
|
|
|
|
}
|
|
|
|
|
2022-02-24 17:24:04 +00:00
|
|
|
// MARK: - Pre-Authentication
|
2022-01-12 17:11:29 +00:00
|
|
|
|
2021-12-16 11:47:02 +00:00
|
|
|
@available(iOS 14.0, *)
|
2022-01-18 16:48:52 +00:00
|
|
|
/// Show the onboarding splash screen as the root module in the flow.
|
2022-01-12 17:11:29 +00:00
|
|
|
private func showSplashScreen() {
|
2022-02-24 17:24:04 +00:00
|
|
|
MXLog.debug("[OnboardingCoordinator] showSplashScreen")
|
|
|
|
|
2022-01-27 14:44:10 +00:00
|
|
|
let coordinator = OnboardingSplashScreenCoordinator()
|
2022-01-12 17:11:29 +00:00
|
|
|
coordinator.completion = { [weak self, weak coordinator] result in
|
|
|
|
guard let self = self, let coordinator = coordinator else { return }
|
|
|
|
self.splashScreenCoordinator(coordinator, didCompleteWith: result)
|
2021-12-16 11:47:02 +00:00
|
|
|
}
|
2022-01-12 17:11:29 +00:00
|
|
|
|
|
|
|
coordinator.start()
|
|
|
|
add(childCoordinator: coordinator)
|
|
|
|
|
2022-02-24 17:24:04 +00:00
|
|
|
navigationRouter.setRootModule(coordinator, popCompletion: nil)
|
2022-01-12 17:11:29 +00:00
|
|
|
}
|
|
|
|
|
2022-02-02 12:24:22 +00:00
|
|
|
@available(iOS 14.0, *)
|
2022-01-18 16:48:52 +00:00
|
|
|
/// Displays the next view in the flow after the splash screen.
|
2022-01-12 17:11:29 +00:00
|
|
|
private func splashScreenCoordinator(_ coordinator: OnboardingSplashScreenCoordinator, didCompleteWith result: OnboardingSplashScreenViewModelResult) {
|
|
|
|
splashScreenResult = result
|
2022-02-02 12:24:22 +00:00
|
|
|
|
2022-02-04 16:10:03 +00:00
|
|
|
// Set the auth type early to allow network requests to finish during display of the use case screen.
|
2022-02-24 17:24:04 +00:00
|
|
|
authenticationCoordinator.update(authenticationType: result.mxkAuthenticationType)
|
2022-02-04 16:10:03 +00:00
|
|
|
|
2022-02-02 12:24:22 +00:00
|
|
|
switch result {
|
|
|
|
case .register:
|
2022-02-10 12:59:13 +00:00
|
|
|
showUseCaseSelectionScreen()
|
2022-02-02 12:24:22 +00:00
|
|
|
case .login:
|
|
|
|
showAuthenticationScreen()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@available(iOS 14.0, *)
|
|
|
|
/// Show the use case screen for new users.
|
2022-02-10 12:59:13 +00:00
|
|
|
private func showUseCaseSelectionScreen() {
|
2022-02-24 17:24:04 +00:00
|
|
|
MXLog.debug("[OnboardingCoordinator] showUseCaseSelectionScreen")
|
|
|
|
|
2022-02-17 11:19:32 +00:00
|
|
|
let coordinator = OnboardingUseCaseSelectionCoordinator()
|
2022-02-02 12:24:22 +00:00
|
|
|
coordinator.completion = { [weak self, weak coordinator] result in
|
|
|
|
guard let self = self, let coordinator = coordinator else { return }
|
2022-02-17 11:19:32 +00:00
|
|
|
self.useCaseSelectionCoordinator(coordinator, didCompleteWith: result)
|
2022-02-02 12:24:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
coordinator.start()
|
|
|
|
add(childCoordinator: coordinator)
|
|
|
|
|
2022-02-24 17:24:04 +00:00
|
|
|
if navigationRouter.modules.isEmpty {
|
|
|
|
navigationRouter.setRootModule(coordinator, popCompletion: nil)
|
2022-02-02 12:24:22 +00:00
|
|
|
} else {
|
2022-02-24 17:24:04 +00:00
|
|
|
navigationRouter.push(coordinator, animated: true) { [weak self] in
|
2022-02-02 12:24:22 +00:00
|
|
|
self?.remove(childCoordinator: coordinator)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Displays the next view in the flow after the use case screen.
|
2022-03-07 16:30:26 +00:00
|
|
|
@available(iOS 14.0, *)
|
2022-02-17 11:19:32 +00:00
|
|
|
private func useCaseSelectionCoordinator(_ coordinator: OnboardingUseCaseSelectionCoordinator, didCompleteWith result: OnboardingUseCaseViewModelResult) {
|
2022-02-02 12:24:22 +00:00
|
|
|
useCaseResult = result
|
2022-01-18 16:48:52 +00:00
|
|
|
showAuthenticationScreen()
|
2022-01-12 17:11:29 +00:00
|
|
|
}
|
|
|
|
|
2022-02-24 17:24:04 +00:00
|
|
|
// MARK: - Authentication
|
|
|
|
|
2022-01-18 16:48:52 +00:00
|
|
|
/// Show the authentication screen. Any parameters that have been set in previous screens are be applied.
|
|
|
|
private func showAuthenticationScreen() {
|
2022-01-28 11:53:50 +00:00
|
|
|
guard !isShowingAuthentication else { return }
|
2022-01-12 17:11:29 +00:00
|
|
|
|
|
|
|
MXLog.debug("[OnboardingCoordinator] showAuthenticationScreen")
|
|
|
|
|
2022-01-28 11:53:50 +00:00
|
|
|
let coordinator = authenticationCoordinator
|
2022-02-17 16:50:02 +00:00
|
|
|
coordinator.completion = { [weak self, weak coordinator] result in
|
2022-01-12 17:11:29 +00:00
|
|
|
guard let self = self, let coordinator = coordinator else { return }
|
2022-02-17 16:50:02 +00:00
|
|
|
|
|
|
|
switch result {
|
2022-02-24 17:24:04 +00:00
|
|
|
case .didLogin(let session, let authenticationType):
|
|
|
|
self.authenticationCoordinator(coordinator, didLoginWith: session, and: authenticationType)
|
|
|
|
case .didComplete:
|
|
|
|
self.authenticationCoordinatorDidComplete(coordinator)
|
2022-02-17 16:50:02 +00:00
|
|
|
}
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
}
|
|
|
|
|
2022-01-28 11:53:50 +00:00
|
|
|
// Due to needing to preload the authVC, this breaks the Coordinator init/start pattern.
|
|
|
|
// This can be re-assessed once we re-write a native flow for authentication.
|
|
|
|
|
|
|
|
if let externalRegistrationParameters = externalRegistrationParameters {
|
|
|
|
coordinator.update(externalRegistrationParameters: externalRegistrationParameters)
|
|
|
|
}
|
2022-02-04 16:10:03 +00:00
|
|
|
|
2022-03-10 11:28:03 +00:00
|
|
|
coordinator.customServerFieldsVisible = useCaseResult == .customServer
|
2022-02-04 16:10:03 +00:00
|
|
|
|
2022-01-28 11:53:50 +00:00
|
|
|
if let softLogoutCredentials = parameters.softLogoutCredentials {
|
|
|
|
coordinator.update(softLogoutCredentials: softLogoutCredentials)
|
|
|
|
}
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
coordinator.start()
|
|
|
|
add(childCoordinator: coordinator)
|
|
|
|
|
|
|
|
if customHomeserver != nil || customIdentityServer != nil {
|
2022-01-27 14:44:10 +00:00
|
|
|
coordinator.updateHomeserver(customHomeserver, andIdentityServer: customIdentityServer)
|
2022-01-12 17:11:29 +00:00
|
|
|
}
|
|
|
|
|
2022-02-24 17:24:04 +00:00
|
|
|
if navigationRouter.modules.isEmpty {
|
|
|
|
navigationRouter.setRootModule(coordinator, popCompletion: nil)
|
2022-01-12 17:11:29 +00:00
|
|
|
} else {
|
2022-02-24 17:24:04 +00:00
|
|
|
navigationRouter.push(coordinator, animated: true) { [weak self] in
|
2022-01-18 16:48:52 +00:00
|
|
|
self?.remove(childCoordinator: coordinator)
|
2022-01-28 11:53:50 +00:00
|
|
|
self?.isShowingAuthentication = false
|
2022-01-18 16:48:52 +00:00
|
|
|
}
|
2022-01-12 17:11:29 +00:00
|
|
|
}
|
2022-01-28 11:53:50 +00:00
|
|
|
isShowingAuthentication = true
|
2022-01-12 17:11:29 +00:00
|
|
|
}
|
|
|
|
|
2022-02-24 17:24:04 +00:00
|
|
|
/// Displays the next view in the flow after the authentication screen,
|
|
|
|
/// whilst crypto and the rest of the app is launching in the background.
|
|
|
|
private func authenticationCoordinator(_ coordinator: AuthenticationCoordinatorProtocol,
|
|
|
|
didLoginWith session: MXSession,
|
|
|
|
and authenticationType: MXKAuthenticationType) {
|
|
|
|
self.session = session
|
|
|
|
self.authenticationType = authenticationType
|
|
|
|
|
|
|
|
// Check whether another screen should be shown.
|
|
|
|
if #available(iOS 14.0, *) {
|
2022-03-07 16:30:26 +00:00
|
|
|
if authenticationType == .register,
|
|
|
|
let userId = session.credentials.userId,
|
|
|
|
let userSession = UserSessionsService.shared.userSession(withUserId: userId),
|
2022-03-15 11:51:17 +00:00
|
|
|
BuildSettings.onboardingShowAccountPersonalization {
|
|
|
|
checkHomeserverCapabilities(for: userSession)
|
2022-02-24 17:24:04 +00:00
|
|
|
return
|
|
|
|
} else if Analytics.shared.shouldShowAnalyticsPrompt {
|
|
|
|
showAnalyticsPrompt(for: session)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise onboarding is finished.
|
2022-02-28 14:27:32 +00:00
|
|
|
onboardingFinished = true
|
2022-02-24 17:24:04 +00:00
|
|
|
completeIfReady()
|
2022-02-17 16:50:02 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 19:08:25 +00:00
|
|
|
/// Checks the capabilities of the user's homeserver in order to determine
|
|
|
|
/// whether or not the display name and avatar can be updated.
|
|
|
|
///
|
|
|
|
/// Once complete this method will start the post authentication flow automatically.
|
2022-03-15 11:51:17 +00:00
|
|
|
@available(iOS 14.0, *)
|
|
|
|
private func checkHomeserverCapabilities(for userSession: UserSession) {
|
|
|
|
userSession.matrixSession.matrixRestClient.capabilities { [weak self] capabilities in
|
|
|
|
guard let self = self else { return }
|
|
|
|
self.shouldShowDisplayNameScreen = capabilities?.setDisplayName?.isEnabled == true
|
|
|
|
self.shouldShowAvatarScreen = capabilities?.setAvatarUrl?.isEnabled == true
|
|
|
|
|
|
|
|
self.beginPostAuthentication(for: userSession)
|
|
|
|
} failure: { [weak self] _ in
|
|
|
|
MXLog.warning("[OnboardingCoordinator] Homeserver capabilities not returned. Skipping personalisation")
|
|
|
|
self?.beginPostAuthentication(for: userSession)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-18 16:48:52 +00:00
|
|
|
/// Displays the next view in the flow after the authentication screen.
|
2022-02-24 17:24:04 +00:00
|
|
|
private func authenticationCoordinatorDidComplete(_ coordinator: AuthenticationCoordinatorProtocol) {
|
2022-01-28 11:53:50 +00:00
|
|
|
isShowingAuthentication = false
|
2022-02-02 12:24:22 +00:00
|
|
|
|
2022-02-15 17:54:17 +00:00
|
|
|
// Handle the chosen use case where applicable
|
2022-02-24 17:24:04 +00:00
|
|
|
if authenticationType == .register,
|
2022-02-15 17:54:17 +00:00
|
|
|
let useCase = useCaseResult?.userSessionPropertyValue,
|
2022-02-02 12:24:22 +00:00
|
|
|
let userSession = UserSessionsService.shared.mainUserSession {
|
2022-02-04 16:10:03 +00:00
|
|
|
// Store the value in the user's session
|
2022-02-15 17:54:17 +00:00
|
|
|
userSession.userProperties.useCase = useCase
|
|
|
|
|
2022-02-17 12:39:11 +00:00
|
|
|
// Update the analytics user properties with the use case
|
|
|
|
Analytics.shared.updateUserProperties(ftueUseCase: useCase)
|
2022-02-02 12:24:22 +00:00
|
|
|
}
|
2022-02-24 17:24:04 +00:00
|
|
|
|
|
|
|
// This method is only called when the app is ready so we can complete if finished
|
2022-02-28 14:27:32 +00:00
|
|
|
authenticationFinished = true
|
2022-02-24 17:24:04 +00:00
|
|
|
completeIfReady()
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Post-Authentication
|
|
|
|
|
2022-03-17 19:08:25 +00:00
|
|
|
/// Starts the part of the flow that comes after authentication for new users.
|
2022-02-24 17:24:04 +00:00
|
|
|
@available(iOS 14.0, *)
|
2022-03-15 11:51:17 +00:00
|
|
|
private func beginPostAuthentication(for userSession: UserSession) {
|
|
|
|
showCongratulationsScreen(for: userSession)
|
|
|
|
}
|
|
|
|
|
2022-03-17 19:08:25 +00:00
|
|
|
/// Show the congratulations screen for new users. The screen will be configured based on the homeserver's capabilities.
|
2022-03-15 11:51:17 +00:00
|
|
|
@available(iOS 14.0, *)
|
|
|
|
private func showCongratulationsScreen(for userSession: UserSession) {
|
2022-02-24 17:24:04 +00:00
|
|
|
MXLog.debug("[OnboardingCoordinator] showCongratulationsScreen")
|
|
|
|
|
2022-03-15 11:51:17 +00:00
|
|
|
let parameters = OnboardingCongratulationsCoordinatorParameters(userSession: userSession,
|
|
|
|
personalizationDisabled: !shouldShowDisplayNameScreen && !shouldShowAvatarScreen)
|
2022-02-24 17:24:04 +00:00
|
|
|
let coordinator = OnboardingCongratulationsCoordinator(parameters: parameters)
|
|
|
|
|
|
|
|
coordinator.completion = { [weak self, weak coordinator] result in
|
|
|
|
guard let self = self, let coordinator = coordinator else { return }
|
|
|
|
self.congratulationsCoordinator(coordinator, didCompleteWith: result)
|
|
|
|
}
|
|
|
|
|
|
|
|
add(childCoordinator: coordinator)
|
|
|
|
coordinator.start()
|
|
|
|
|
|
|
|
// Navigating back doesn't make any sense now, so replace the whole stack.
|
|
|
|
navigationRouter.setRootModule(coordinator, hideNavigationBar: true, animated: true) { [weak self] in
|
|
|
|
self?.remove(childCoordinator: coordinator)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-17 19:08:25 +00:00
|
|
|
/// Displays the next view in the flow after the congratulations screen.
|
2022-02-24 17:24:04 +00:00
|
|
|
@available(iOS 14.0, *)
|
2022-03-07 16:30:26 +00:00
|
|
|
private func congratulationsCoordinator(_ coordinator: OnboardingCongratulationsCoordinator, didCompleteWith result: OnboardingCongratulationsCoordinatorResult) {
|
|
|
|
switch result {
|
2022-03-21 11:42:58 +00:00
|
|
|
case .personalizeProfile(let userSession):
|
2022-03-15 11:51:17 +00:00
|
|
|
if shouldShowDisplayNameScreen {
|
|
|
|
showDisplayNameScreen(for: userSession)
|
|
|
|
return
|
|
|
|
} else if shouldShowAvatarScreen {
|
|
|
|
showAvatarScreen(for: userSession)
|
|
|
|
return
|
|
|
|
} else if Analytics.shared.shouldShowAnalyticsPrompt {
|
|
|
|
showAnalyticsPrompt(for: userSession.matrixSession)
|
|
|
|
return
|
|
|
|
}
|
2022-03-07 16:30:26 +00:00
|
|
|
case .takeMeHome(let userSession):
|
|
|
|
if Analytics.shared.shouldShowAnalyticsPrompt {
|
|
|
|
showAnalyticsPrompt(for: userSession.matrixSession)
|
|
|
|
return
|
2022-02-24 17:24:04 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-15 11:51:17 +00:00
|
|
|
|
|
|
|
onboardingFinished = true
|
|
|
|
completeIfReady()
|
2022-03-07 16:30:26 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 19:08:25 +00:00
|
|
|
/// Show the display name personalization screen for new users using the supplied user session.
|
2022-03-07 16:30:26 +00:00
|
|
|
@available(iOS 14.0, *)
|
|
|
|
private func showDisplayNameScreen(for userSession: UserSession) {
|
|
|
|
MXLog.debug("[OnboardingCoordinator]: showDisplayNameScreen")
|
|
|
|
|
|
|
|
let parameters = OnboardingDisplayNameCoordinatorParameters(userSession: userSession)
|
|
|
|
let coordinator = OnboardingDisplayNameCoordinator(parameters: parameters)
|
|
|
|
|
|
|
|
coordinator.completion = { [weak self, weak coordinator] session in
|
|
|
|
guard let self = self, let coordinator = coordinator else { return }
|
|
|
|
self.displayNameCoordinator(coordinator, didCompleteWith: session)
|
|
|
|
}
|
|
|
|
|
|
|
|
add(childCoordinator: coordinator)
|
|
|
|
coordinator.start()
|
|
|
|
|
|
|
|
navigationRouter.setRootModule(coordinator, hideNavigationBar: false, animated: true) { [weak self] in
|
|
|
|
self?.remove(childCoordinator: coordinator)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-17 19:08:25 +00:00
|
|
|
/// Displays the next view in the flow after the display name screen.
|
2022-03-07 16:30:26 +00:00
|
|
|
@available(iOS 14.0, *)
|
|
|
|
private func displayNameCoordinator(_ coordinator: OnboardingDisplayNameCoordinator, didCompleteWith userSession: UserSession) {
|
2022-03-15 11:51:17 +00:00
|
|
|
if shouldShowAvatarScreen {
|
|
|
|
showAvatarScreen(for: userSession)
|
|
|
|
return
|
|
|
|
} else if Analytics.shared.shouldShowAnalyticsPrompt {
|
|
|
|
showAnalyticsPrompt(for: userSession.matrixSession)
|
2022-03-17 19:08:25 +00:00
|
|
|
return
|
2022-03-15 11:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onboardingFinished = true
|
|
|
|
completeIfReady()
|
|
|
|
}
|
|
|
|
|
2022-03-17 19:08:25 +00:00
|
|
|
/// Show the avatar personalization screen for new users using the supplied user session.
|
2022-03-15 11:51:17 +00:00
|
|
|
@available(iOS 14.0, *)
|
|
|
|
private func showAvatarScreen(for userSession: UserSession) {
|
|
|
|
MXLog.debug("[OnboardingCoordinator]: showAvatarScreen")
|
|
|
|
|
|
|
|
let parameters = OnboardingAvatarCoordinatorParameters(userSession: userSession)
|
|
|
|
let coordinator = OnboardingAvatarCoordinator(parameters: parameters)
|
|
|
|
|
|
|
|
coordinator.completion = { [weak self, weak coordinator] session in
|
|
|
|
guard let self = self, let coordinator = coordinator else { return }
|
|
|
|
self.avatarCoordinator(coordinator, didCompleteWith: session)
|
|
|
|
}
|
|
|
|
|
|
|
|
add(childCoordinator: coordinator)
|
|
|
|
coordinator.start()
|
|
|
|
|
2022-03-17 19:08:25 +00:00
|
|
|
if navigationRouter.modules.isEmpty || !shouldShowDisplayNameScreen {
|
2022-03-15 11:51:17 +00:00
|
|
|
navigationRouter.setRootModule(coordinator, hideNavigationBar: false, animated: true) { [weak self] in
|
|
|
|
self?.remove(childCoordinator: coordinator)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
navigationRouter.push(coordinator, animated: true) { [weak self] in
|
|
|
|
self?.remove(childCoordinator: coordinator)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-17 19:08:25 +00:00
|
|
|
/// Displays the next view in the flow after the avatar screen.
|
2022-03-15 11:51:17 +00:00
|
|
|
@available(iOS 14.0, *)
|
|
|
|
private func avatarCoordinator(_ coordinator: OnboardingAvatarCoordinator, didCompleteWith userSession: UserSession) {
|
2022-03-07 16:30:26 +00:00
|
|
|
if Analytics.shared.shouldShowAnalyticsPrompt {
|
|
|
|
showAnalyticsPrompt(for: userSession.matrixSession)
|
|
|
|
return
|
|
|
|
}
|
2022-02-24 17:24:04 +00:00
|
|
|
|
2022-02-28 14:27:32 +00:00
|
|
|
onboardingFinished = true
|
2022-02-24 17:24:04 +00:00
|
|
|
completeIfReady()
|
|
|
|
}
|
|
|
|
|
2022-03-17 19:08:25 +00:00
|
|
|
/// Shows the analytics prompt for the supplied session.
|
|
|
|
///
|
|
|
|
/// Check `Analytics.shared.shouldShowAnalyticsPrompt` before calling this method.
|
2022-02-24 17:24:04 +00:00
|
|
|
@available(iOS 14.0, *)
|
|
|
|
private func showAnalyticsPrompt(for session: MXSession) {
|
|
|
|
MXLog.debug("[OnboardingCoordinator]: Invite the user to send analytics")
|
|
|
|
|
|
|
|
let parameters = AnalyticsPromptCoordinatorParameters(session: session)
|
|
|
|
let coordinator = AnalyticsPromptCoordinator(parameters: parameters)
|
|
|
|
|
|
|
|
coordinator.completion = { [weak self, weak coordinator] in
|
|
|
|
guard let self = self, let coordinator = coordinator else { return }
|
|
|
|
self.analyticsPromptCoordinatorDidComplete(coordinator)
|
|
|
|
}
|
|
|
|
|
|
|
|
add(childCoordinator: coordinator)
|
|
|
|
coordinator.start()
|
|
|
|
|
|
|
|
// TODO: Re-asses replacing the stack based on the previous screen once the whole flow is implemented
|
|
|
|
navigationRouter.setRootModule(coordinator, hideNavigationBar: true, animated: true) { [weak self] in
|
|
|
|
self?.remove(childCoordinator: coordinator)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-17 19:08:25 +00:00
|
|
|
/// Displays the next view in the flow after the analytics screen.
|
2022-02-24 17:24:04 +00:00
|
|
|
private func analyticsPromptCoordinatorDidComplete(_ coordinator: AnalyticsPromptCoordinator) {
|
2022-02-28 14:27:32 +00:00
|
|
|
onboardingFinished = true
|
2022-02-24 17:24:04 +00:00
|
|
|
completeIfReady()
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Finished
|
|
|
|
|
2022-03-17 19:08:25 +00:00
|
|
|
/// Calls the coordinator's completion handler if both `onboardingFinished` and `authenticationFinished`
|
|
|
|
/// are true. Otherwise displays any pending screens and waits to be called again.
|
2022-02-24 17:24:04 +00:00
|
|
|
private func completeIfReady() {
|
2022-02-28 14:27:32 +00:00
|
|
|
guard onboardingFinished else {
|
2022-02-24 17:24:04 +00:00
|
|
|
MXLog.debug("[OnboardingCoordinator] Delaying onboarding completion until all screens have been shown.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-02-28 14:27:32 +00:00
|
|
|
guard authenticationFinished else {
|
2022-02-24 17:24:04 +00:00
|
|
|
MXLog.debug("[OnboardingCoordinator] Allowing AuthenticationCoordinator to display any remaining screens.")
|
2022-02-28 14:27:32 +00:00
|
|
|
authenticationCoordinator.presentPendingScreensIfNecessary()
|
2022-02-24 17:24:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
completion?()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Helpers
|
|
|
|
|
|
|
|
extension OnboardingSplashScreenViewModelResult {
|
|
|
|
/// The result converted into the MatrixKit authentication type to use.
|
|
|
|
var mxkAuthenticationType: MXKAuthenticationType {
|
|
|
|
switch self {
|
|
|
|
case .login:
|
|
|
|
return .login
|
|
|
|
case .register:
|
|
|
|
return .register
|
|
|
|
}
|
2022-02-02 12:24:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension OnboardingUseCaseViewModelResult {
|
|
|
|
/// The result converted into the type stored in the user session.
|
|
|
|
var userSessionPropertyValue: UserSessionProperties.UseCase? {
|
|
|
|
switch self {
|
|
|
|
case .personalMessaging:
|
|
|
|
return .personalMessaging
|
|
|
|
case .workMessaging:
|
|
|
|
return .workMessaging
|
|
|
|
case .communityMessaging:
|
|
|
|
return .communityMessaging
|
|
|
|
case .skipped:
|
|
|
|
return .skipped
|
|
|
|
case .customServer:
|
|
|
|
return nil
|
|
|
|
}
|
2021-12-16 11:47:02 +00:00
|
|
|
}
|
|
|
|
}
|