User verification: Add start user verification flow to DeviceVerificationCoordinator.

This commit is contained in:
SBiOSoftWhare
2020-01-30 17:57:09 +01:00
parent 0e1a60389e
commit 6baec47dfd
2 changed files with 53 additions and 2 deletions
@@ -32,6 +32,8 @@ final class DeviceVerificationCoordinator: DeviceVerificationCoordinatorType {
private var incomingTransaction: MXIncomingSASTransaction?
private var incomingKeyVerificationRequest: MXKeyVerificationRequest?
var roomMember: MXRoomMember?
// MARK: Public
@@ -77,13 +79,28 @@ final class DeviceVerificationCoordinator: DeviceVerificationCoordinatorType {
self.incomingKeyVerificationRequest = incomingKeyVerificationRequest
}
/// Constructor to start a user verification.
///
/// - Parameters:
/// - session: the MXSession
/// - roomMember: an other room member
init(session: MXSession, roomMember: MXRoomMember) {
self.navigationRouter = NavigationRouter(navigationController: RiotNavigationController())
self.session = session
self.otherUserId = roomMember.userId
self.otherDeviceId = ""
self.roomMember = roomMember
}
// MARK: - Public methods
func start() {
let rootCoordinator: Coordinator & Presentable
let rootCoordinator: Coordinator & Presentable
if let incomingKeyVerificationRequest = self.incomingKeyVerificationRequest {
rootCoordinator = self.createDataLoadingScreenCoordinator(with: incomingKeyVerificationRequest)
} else if let roomMember = self.roomMember {
rootCoordinator = self.createUserVerificationStartCoordinator(with: roomMember)
} else {
rootCoordinator = self.createDataLoadingScreenCoordinator()
}
@@ -117,6 +134,14 @@ final class DeviceVerificationCoordinator: DeviceVerificationCoordinatorType {
return coordinator
}
private func createUserVerificationStartCoordinator(with roomMember: MXRoomMember) -> UserVerificationStartCoordinator {
let coordinator = UserVerificationStartCoordinator(session: self.session, roomMember: roomMember)
coordinator.delegate = self
coordinator.start()
return coordinator
}
private func showStart(otherUser: MXUser, otherDevice: MXDeviceInfo) {
let coordinator = DeviceVerificationStartCoordinator(session: self.session, otherUser: otherUser, otherDevice: otherDevice)
@@ -226,3 +251,17 @@ extension DeviceVerificationCoordinator: DeviceVerificationVerifiedViewControlle
self.delegate?.deviceVerificationCoordinatorDidComplete(self, otherUserId: self.otherUserId, otherDeviceId: self.otherDeviceId)
}
}
extension DeviceVerificationCoordinator: UserVerificationStartCoordinatorDelegate {
func userVerificationStartCoordinator(_ coordinator: UserVerificationStartCoordinatorType, didCompleteWithOutgoingTransaction transaction: MXSASTransaction) {
self.showVerify(transaction: transaction, animated: true)
}
func userVerificationStartCoordinator(_ coordinator: UserVerificationStartCoordinatorType, didTransactionCancelled transaction: MXSASTransaction) {
self.delegate?.deviceVerificationCoordinatorDidComplete(self, otherUserId: self.otherUserId, otherDeviceId: self.otherDeviceId)
}
func userVerificationStartCoordinatorDidCancel(_ coordinator: UserVerificationStartCoordinatorType) {
self.delegate?.deviceVerificationCoordinatorDidComplete(self, otherUserId: self.otherUserId, otherDeviceId: self.otherDeviceId)
}
}
@@ -63,6 +63,18 @@ final class DeviceVerificationCoordinatorBridgePresenter: NSObject {
self.coordinator = deviceVerificationCoordinator
}
func present(from viewController: UIViewController, roomMember: MXRoomMember, animated: Bool) {
NSLog("[DeviceVerificationCoordinatorBridgePresenter] Present from \(viewController)")
let deviceVerificationCoordinator = DeviceVerificationCoordinator(session: self.session, roomMember: roomMember)
deviceVerificationCoordinator.delegate = self
viewController.present(deviceVerificationCoordinator.toPresentable(), animated: animated, completion: nil)
deviceVerificationCoordinator.start()
self.coordinator = deviceVerificationCoordinator
}
func present(from viewController: UIViewController, incomingTransaction: MXIncomingSASTransaction, animated: Bool) {