Device Verification: Plug the legacy verification modal

This commit is contained in:
manuroe 2019-04-16 15:00:57 +02:00
parent 4889690698
commit e8ed9a19f9
5 changed files with 41 additions and 5 deletions

View file

@ -20,7 +20,8 @@ import Foundation
/// DeviceVerificationStartViewController view actions exposed to view model
enum DeviceVerificationStartViewAction {
case useLegacyVerification
case beginVerifying
case verifyUsingLegacy
case verifiedUsingLegacy
case cancel
}

View file

@ -158,6 +158,8 @@ final class DeviceVerificationStartViewController: UIViewController {
self.renderLoading()
case .loaded:
self.renderStarted()
case .verifyUsingLegacy(let session, let deviceInfo):
self.renderVerifyUsingLegacy(session: session, deviceInfo: deviceInfo)
case .cancelled(let reason):
self.renderCancelled(reason: reason)
case .error(let error):
@ -177,6 +179,24 @@ final class DeviceVerificationStartViewController: UIViewController {
self.useLegacyVerificationLabel.isHidden = false
}
private func renderVerifyUsingLegacy(session: MXSession, deviceInfo: MXDeviceInfo) {
self.activityPresenter.removeCurrentActivityIndicator(animated: true)
guard let encryptionInfoView = EncryptionInfoView(deviceInfo: deviceInfo, andMatrixSession: session) else {
return
}
encryptionInfoView.delegate = self
// Skip the intro page
encryptionInfoView.onButtonPressed(encryptionInfoView.verifyButton)
// Display the legacy verification view in full screen
// TODO: Do not reuse the legacy EncryptionInfoView and create a screen from scratch
self.view.vc_addSubViewMatchingParent(encryptionInfoView)
self.navigationController?.isNavigationBarHidden = true
}
private func renderCancelled(reason: MXTransactionCancelCode) {
self.activityPresenter.removeCurrentActivityIndicator(animated: true)
@ -198,7 +218,7 @@ final class DeviceVerificationStartViewController: UIViewController {
}
@IBAction private func useLegacyVerificationButtonAction(_ sender: Any) {
self.viewModel.process(viewAction: .useLegacyVerification)
self.viewModel.process(viewAction: .verifyUsingLegacy)
}
private func cancelButtonAction() {
@ -214,3 +234,14 @@ extension DeviceVerificationStartViewController: DeviceVerificationStartViewMode
self.render(viewState: viewSate)
}
}
// MARK: - DeviceVerificationStartViewModelViewDelegate
extension DeviceVerificationStartViewController: MXKEncryptionInfoViewDelegate {
func encryptionInfoView(_ encryptionInfoView: MXKEncryptionInfoView!, didDeviceInfoVerifiedChange deviceInfo: MXDeviceInfo!) {
self.viewModel.process(viewAction: .verifiedUsingLegacy)
}
func encryptionInfoViewDidClose(_ encryptionInfoView: MXKEncryptionInfoView!) {
self.viewModel.process(viewAction: .cancel)
}
}

View file

@ -52,11 +52,13 @@ final class DeviceVerificationStartViewModel: DeviceVerificationStartViewModelTy
func process(viewAction: DeviceVerificationStartViewAction) {
switch viewAction {
case .useLegacyVerification:
self.cancelTransaction()
self.coordinatorDelegate?.deviceVerificationStartViewModelUseLegacyVerification(self)
case .beginVerifying:
self.beginVerifying()
case .verifyUsingLegacy:
self.cancelTransaction()
self.update(viewState: .verifyUsingLegacy(self.session, self.otherDevice))
case .verifiedUsingLegacy:
self.coordinatorDelegate?.deviceVerificationStartViewModelUseLegacyVerification(self)
case .cancel:
self.cancelTransaction()
self.coordinatorDelegate?.deviceVerificationStartViewModelDidCancel(self)

View file

@ -22,6 +22,7 @@ import Foundation
enum DeviceVerificationStartViewState {
case loading
case loaded // started
case verifyUsingLegacy(MXSession, MXDeviceInfo)
case cancelled(MXTransactionCancelCode)
case error(Error)
}

View file

@ -11,3 +11,4 @@
#import "TableViewCellWithCheckBoxAndLabel.h"
#import "RecentsDataSource.h"
#import "AvatarGenerator.h"
#import "EncryptionInfoView.h"