diff --git a/Riot/Modules/UserInteractiveAuthentication/AuthenticatedEndpointRequest.swift b/Riot/Modules/UserInteractiveAuthentication/AuthenticatedEndpointRequest.swift index dfa8c8ee5..f8827427a 100644 --- a/Riot/Modules/UserInteractiveAuthentication/AuthenticatedEndpointRequest.swift +++ b/Riot/Modules/UserInteractiveAuthentication/AuthenticatedEndpointRequest.swift @@ -29,3 +29,14 @@ class AuthenticatedEndpointRequest: NSObject { super.init() } } + +// MARK: - Helper methods + +extension AuthenticatedEndpointRequest { + /// Create an authenticated request on `_matrix/client/r0/devices/{deviceID}`. + /// - Parameter deviceID: The device ID that is to be deleted. + static func deleteDevice(_ deviceID: String) -> AuthenticatedEndpointRequest { + let path = String(format: "%@/devices/%@", kMXAPIPrefixPathR0, MXTools.encodeURIComponent(deviceID)) + return AuthenticatedEndpointRequest(path: path, httpMethod: "DELETE") + } +} diff --git a/RiotSwiftUI/Modules/UserSessions/Coordinator/UserSessionsFlowCoordinator.swift b/RiotSwiftUI/Modules/UserSessions/Coordinator/UserSessionsFlowCoordinator.swift index 3ede6da2f..583217637 100644 --- a/RiotSwiftUI/Modules/UserSessions/Coordinator/UserSessionsFlowCoordinator.swift +++ b/RiotSwiftUI/Modules/UserSessions/Coordinator/UserSessionsFlowCoordinator.swift @@ -19,7 +19,7 @@ import Foundation struct UserSessionsFlowCoordinatorParameters { let session: MXSession - let router: NavigationRouterType? + let router: NavigationRouterType } final class UserSessionsFlowCoordinator: Coordinator, Presentable { @@ -41,11 +41,9 @@ final class UserSessionsFlowCoordinator: Coordinator, Presentable { init(parameters: UserSessionsFlowCoordinatorParameters) { self.parameters = parameters - let navigationRouter = parameters.router ?? NavigationRouter(navigationController: RiotNavigationController()) - self.navigationRouter = navigationRouter - + self.navigationRouter = parameters.router errorPresenter = MXKErrorAlertPresentation() - indicatorPresenter = UserIndicatorTypePresenter(presentingViewController: navigationRouter.toPresentable()) + indicatorPresenter = UserIndicatorTypePresenter(presentingViewController: parameters.router.toPresentable()) } // MARK: - Private @@ -146,6 +144,7 @@ final class UserSessionsFlowCoordinator: Coordinator, Presentable { self?.showLogoutAuthentication(for: sessionInfo) }) alert.addAction(UIAlertAction(title: VectorL10n.cancel, style: .cancel)) + alert.popoverPresentationController?.sourceView = toPresentable().view navigationRouter.present(alert, animated: true) } @@ -154,9 +153,7 @@ final class UserSessionsFlowCoordinator: Coordinator, Presentable { private func showLogoutAuthentication(for sessionInfo: UserSessionInfo) { startLoading() - let path = String(format: "%@/devices/%@", kMXAPIPrefixPathR0, MXTools.encodeURIComponent(sessionInfo.id)) - let deleteDeviceRequest = AuthenticatedEndpointRequest(path: path, httpMethod: "DELETE") - + let deleteDeviceRequest = AuthenticatedEndpointRequest.deleteDevice(sessionInfo.id) let coordinatorParameters = ReauthenticationCoordinatorParameters(session: parameters.session, presenter: navigationRouter.toPresentable(), title: VectorL10n.deviceDetailsDeletePromptTitle, diff --git a/RiotSwiftUI/Modules/UserSessions/Coordinator/UserSessionsFlowCoordinatorBridgePresenter.swift b/RiotSwiftUI/Modules/UserSessions/Coordinator/UserSessionsFlowCoordinatorBridgePresenter.swift index a2b256177..498b9d391 100644 --- a/RiotSwiftUI/Modules/UserSessions/Coordinator/UserSessionsFlowCoordinatorBridgePresenter.swift +++ b/RiotSwiftUI/Modules/UserSessions/Coordinator/UserSessionsFlowCoordinatorBridgePresenter.swift @@ -42,12 +42,8 @@ final class UserSessionsFlowCoordinatorBridgePresenter: NSObject { // MARK: - Private - private func startUserSessionsFlow(mxSession: MXSession, navigationController: UINavigationController?) { - var navigationRouter: NavigationRouterType? - - if let navigationController = navigationController { - navigationRouter = NavigationRouterStore.shared.navigationRouter(for: navigationController) - } + private func startUserSessionsFlow(mxSession: MXSession, navigationController: UINavigationController) { + let navigationRouter = NavigationRouterStore.shared.navigationRouter(for: navigationController) let parameters = UserSessionsFlowCoordinatorParameters(session: mxSession, router: navigationRouter) let coordinator = UserSessionsFlowCoordinator(parameters: parameters) diff --git a/RiotSwiftUI/Modules/UserSessions/UserSessionOverview/View/UserSessionOverviewItem.swift b/RiotSwiftUI/Modules/UserSessions/UserSessionOverview/View/UserSessionOverviewItem.swift index 65247bc70..de622b768 100644 --- a/RiotSwiftUI/Modules/UserSessions/UserSessionOverview/View/UserSessionOverviewItem.swift +++ b/RiotSwiftUI/Modules/UserSessions/UserSessionOverview/View/UserSessionOverviewItem.swift @@ -51,7 +51,7 @@ struct UserSessionOverviewItem: View { } } -struct UserSessionOverviewButtonCell_Previews: PreviewProvider { +struct UserSessionOverviewItem_Previews: PreviewProvider { static var buttons: some View { NavigationView { ScrollView {