@@ -45,49 +45,48 @@ final class CrossSigningSetupCoordinator: CrossSigningSetupCoordinatorType {
4545 // MARK: - Public methods
4646
4747 func start( ) {
48- self . showReauthentication ( )
48+ setupCrossSigning ( )
4949 }
5050
5151 func toPresentable( ) -> UIViewController {
5252 return self . parameters. presenter. toPresentable ( )
5353 }
5454
5555 // MARK: - Private methods
56-
57- private func showReauthentication( ) {
56+
57+ private func setupCrossSigning( with authenticationParameters: [ String : Any ] = [ : ] ) {
58+ guard let crossSigning = parameters. session. crypto? . crossSigning else { return }
5859
60+ crossSigning. setup ( withAuthParams: authenticationParameters) { [ weak self] in
61+ guard let self else { return }
62+ delegate? . crossSigningSetupCoordinatorDidComplete ( self )
63+ } failure: { [ weak self] error in
64+ guard let self else { return }
65+
66+ if let responseData = ( error as NSError ) . userInfo [ MXHTTPClientErrorResponseDataKey] as? [ AnyHashable : Any ] ,
67+ let authenticationSession = MXAuthenticationSession ( fromJSON: responseData) {
68+ showReauthentication ( authenticationSession: authenticationSession)
69+ } else {
70+ delegate? . crossSigningSetupCoordinator ( self , didFailWithError: error)
71+ }
72+ }
73+ }
74+
75+ private func showReauthentication( authenticationSession: MXAuthenticationSession ) {
5976 let setupCrossSigningRequest = self . crossSigningService. setupCrossSigningRequest ( )
6077
6178 let reauthenticationParameters = ReauthenticationCoordinatorParameters ( session: parameters. session,
6279 presenter: parameters. presenter,
6380 title: parameters. title,
6481 message: parameters. message,
65- authenticatedEndpointRequest : setupCrossSigningRequest )
82+ authenticationSession : authenticationSession )
6683
6784 let coordinator = ReauthenticationCoordinator ( parameters: reauthenticationParameters)
6885 coordinator. delegate = self
6986 self . add ( childCoordinator: coordinator)
7087
7188 coordinator. start ( )
7289 }
73-
74- private func setupCrossSigning( with authenticationParameters: [ String : Any ] ) {
75- guard let crossSigning = self . parameters. session. crypto? . crossSigning else {
76- return
77- }
78-
79- crossSigning. setup ( withAuthParams: authenticationParameters) { [ weak self] in
80- guard let self = self else {
81- return
82- }
83- self . delegate? . crossSigningSetupCoordinatorDidComplete ( self )
84- } failure: { [ weak self] error in
85- guard let self = self else {
86- return
87- }
88- self . delegate? . crossSigningSetupCoordinator ( self , didFailWithError: error)
89- }
90- }
9190}
9291
9392// MARK: - ReauthenticationCoordinatorDelegate
0 commit comments