User verification: Update device verification flow to support device or user verification.

This commit is contained in:
SBiOSoftWhare
2020-01-31 15:07:30 +01:00
parent 7380baf114
commit 58b08cc51c
10 changed files with 118 additions and 31 deletions
@@ -28,12 +28,13 @@ final class DeviceVerificationCoordinator: DeviceVerificationCoordinatorType {
private let navigationRouter: NavigationRouterType
private let session: MXSession
private let otherUserId: String
private let otherDeviceId: String
private let otherDeviceId: String
private var incomingTransaction: MXIncomingSASTransaction?
private var incomingKeyVerificationRequest: MXKeyVerificationRequest?
var roomMember: MXRoomMember?
private var verificationKind: KeyVerificationKind = .device
private var roomMember: MXRoomMember?
// MARK: Public
@@ -56,6 +57,13 @@ final class DeviceVerificationCoordinator: DeviceVerificationCoordinatorType {
self.otherUserId = otherUserId
self.otherDeviceId = otherDeviceId
}
init(navigationRouter: NavigationRouterType, session: MXSession, userId: String, otherDeviceId: String) {
self.navigationRouter = navigationRouter
self.session = session
self.otherUserId = userId
self.otherDeviceId = otherDeviceId
}
/// Contrustor to manage an incoming SAS device verification transaction
///
@@ -90,6 +98,7 @@ final class DeviceVerificationCoordinator: DeviceVerificationCoordinatorType {
self.otherUserId = roomMember.userId
self.otherDeviceId = ""
self.roomMember = roomMember
self.verificationKind = .user
}
// MARK: - Public methods
@@ -108,8 +117,15 @@ final class DeviceVerificationCoordinator: DeviceVerificationCoordinatorType {
rootCoordinator.start()
self.add(childCoordinator: rootCoordinator)
self.navigationRouter.setRootModule(rootCoordinator) { [weak self] in
self?.remove(childCoordinator: rootCoordinator)
if self.navigationRouter.modules.isEmpty == false {
self.navigationRouter.push(rootCoordinator, animated: true, popCompletion: { [weak self] in
self?.remove(childCoordinator: rootCoordinator)
})
} else {
self.navigationRouter.setRootModule(rootCoordinator) { [weak self] in
self?.remove(childCoordinator: rootCoordinator)
}
}
}
@@ -166,7 +182,7 @@ final class DeviceVerificationCoordinator: DeviceVerificationCoordinatorType {
}
private func showVerify(transaction: MXSASTransaction, animated: Bool) {
let coordinator = DeviceVerificationVerifyCoordinator(session: self.session, transaction: transaction)
let coordinator = DeviceVerificationVerifyCoordinator(session: self.session, transaction: transaction, verificationKind: self.verificationKind)
coordinator.delegate = self
coordinator.start()
@@ -177,7 +193,7 @@ final class DeviceVerificationCoordinator: DeviceVerificationCoordinatorType {
}
private func showVerified(animated: Bool) {
let viewController = DeviceVerificationVerifiedViewController.instantiate()
let viewController = DeviceVerificationVerifiedViewController.instantiate(with: self.verificationKind)
viewController.delegate = self
self.navigationRouter.setRootModule(viewController)
}
@@ -0,0 +1,21 @@
/*
Copyright 2020 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 Foundation
enum KeyVerificationKind {
case device
case user
}
@@ -66,6 +66,13 @@ final class DeviceVerificationDataLoadingViewController: UIViewController {
return self.theme.statusBarStyle
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Hide back button
self.navigationItem.setHidesBackButton(true, animated: animated)
}
// MARK: - Private
private func update(theme: Theme) {
@@ -39,6 +39,7 @@ final class DeviceVerificationVerifiedViewController: UIViewController {
// MARK: Private
private var theme: Theme!
private var verificationKind: KeyVerificationKind = .user
// MARK: Public
@@ -46,9 +47,10 @@ final class DeviceVerificationVerifiedViewController: UIViewController {
// MARK: - Setup
class func instantiate() -> DeviceVerificationVerifiedViewController {
class func instantiate(with verificationKind: KeyVerificationKind) -> DeviceVerificationVerifiedViewController {
let viewController = StoryboardScene.DeviceVerificationVerifiedViewController.initialScene.instantiate()
viewController.theme = ThemeService.shared().theme
viewController.verificationKind = verificationKind
return viewController
}
@@ -59,7 +61,6 @@ final class DeviceVerificationVerifiedViewController: UIViewController {
// Do any additional setup after loading the view.
self.title = VectorL10n.deviceVerificationTitle
self.vc_removeBackTitle()
self.setupViews()
@@ -81,9 +82,28 @@ final class DeviceVerificationVerifiedViewController: UIViewController {
// MARK: - Private
private func setupViews() {
self.titleLabel.text = VectorL10n.deviceVerificationVerifiedTitle
self.description1Label.text = VectorL10n.deviceVerificationVerifiedDescription1
self.description2Label.text = VectorL10n.deviceVerificationVerifiedDescription2
let title: String
let bodyTitle: String
let descriptionTextPart1: String
let descriptionTextPart2: String
switch self.verificationKind {
case .device:
title = VectorL10n.deviceVerificationTitle
bodyTitle = VectorL10n.deviceVerificationVerifiedTitle
descriptionTextPart1 = VectorL10n.deviceVerificationVerifiedDescription1
descriptionTextPart2 = VectorL10n.deviceVerificationVerifiedDescription2
case .user:
title = "Verify user"
bodyTitle = VectorL10n.deviceVerificationVerifiedTitle
descriptionTextPart1 = "Youve successfully verified this user."
descriptionTextPart2 = "Messages with this user in this room are end-to-end encrypted and cant be read by third parties."
}
self.title = title
self.titleLabel.text = bodyTitle
self.description1Label.text = descriptionTextPart1
self.description2Label.text = descriptionTextPart2
self.okButton.setTitle(VectorL10n.deviceVerificationVerifiedGotItButton, for: .normal)
}
@@ -103,7 +123,7 @@ final class DeviceVerificationVerifiedViewController: UIViewController {
self.okButtonBackgroundView.backgroundColor = theme.backgroundColor
theme.applyStyle(onButton: self.okButton)
}
}
private func registerThemeServiceDidChangeThemeNotification() {
NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .themeServiceDidChangeTheme, object: nil)
@@ -38,10 +38,10 @@ final class DeviceVerificationVerifyCoordinator: DeviceVerificationVerifyCoordin
// MARK: - Setup
init(session: MXSession, transaction: MXSASTransaction) {
init(session: MXSession, transaction: MXSASTransaction, verificationKind: KeyVerificationKind) {
self.session = session
let deviceVerificationVerifyViewModel = DeviceVerificationVerifyViewModel(session: self.session, transaction: transaction)
let deviceVerificationVerifyViewModel = DeviceVerificationVerifyViewModel(session: self.session, transaction: transaction, verificationKind: verificationKind)
let deviceVerificationVerifyViewController = DeviceVerificationVerifyViewController.instantiate(with: deviceVerificationVerifyViewModel)
self.deviceVerificationVerifyViewModel = deviceVerificationVerifyViewModel
self.deviceVerificationVerifyViewController = deviceVerificationVerifyViewController
@@ -59,7 +59,6 @@ final class DeviceVerificationVerifyViewController: UIViewController {
// Do any additional setup after loading the view.
self.title = VectorL10n.deviceVerificationTitle
self.vc_removeBackTitle()
self.setupViews()
@@ -123,16 +122,33 @@ final class DeviceVerificationVerifyViewController: UIViewController {
self.scrollView.keyboardDismissMode = .interactive
if viewModel.emojis != nil {
let isVerificationByEmoji = viewModel.emojis != nil
if isVerificationByEmoji {
self.decimalLabel.isHidden = true
self.titleLabel.text = VectorL10n.deviceVerificationVerifyTitleEmoji
} else {
self.emojisCollectionView.isHidden = true
self.titleLabel.text = VectorL10n.deviceVerificationVerifyTitleNumber
self.decimalLabel.text = self.viewModel.decimal
}
let title: String
let instructionText: String
let adviceText: String
switch viewModel.verificationKind {
case .device:
title = VectorL10n.deviceVerificationTitle
instructionText = isVerificationByEmoji ? VectorL10n.deviceVerificationVerifyTitleEmoji : VectorL10n.deviceVerificationVerifyTitleNumber
adviceText = VectorL10n.deviceVerificationSecurityAdvice
case .user:
title = "Verify user"
instructionText = isVerificationByEmoji ? "Verify this user by confirming the following unique emoji appears on their screen, in the same order." : "Verify this user by confirming the following numbers appear on their screen, in the same order."
adviceText = VectorL10n.deviceVerificationSecurityAdvice
}
self.informationLabel.text = VectorL10n.deviceVerificationSecurityAdvice
self.title = title
self.titleLabel.text = instructionText
self.informationLabel.text = adviceText
self.waitingPartnerLabel.text = VectorL10n.deviceVerificationVerifyWaitPartner
self.waitingPartnerLabel.isHidden = true
@@ -223,10 +239,8 @@ extension DeviceVerificationVerifyViewController: UICollectionViewDataSource {
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "VerifyEmojiCollectionViewCell", for: indexPath) as? VerifyEmojiCollectionViewCell else {
return UICollectionViewCell()
}
let cell = collectionView.dequeueReusableCell(for: indexPath, cellType: VerifyEmojiCollectionViewCell.self)
guard let emoji = self.viewModel.emojis?[indexPath.row] else {
return UICollectionViewCell()
@@ -31,16 +31,19 @@ final class DeviceVerificationVerifyViewModel: DeviceVerificationVerifyViewModel
weak var viewDelegate: DeviceVerificationVerifyViewModelViewDelegate?
weak var coordinatorDelegate: DeviceVerificationVerifyViewModelCoordinatorDelegate?
var emojis: [MXEmojiRepresentation]?
var decimal: String?
let emojis: [MXEmojiRepresentation]?
let decimal: String?
let verificationKind: KeyVerificationKind
// MARK: - Setup
init(session: MXSession, transaction: MXSASTransaction) {
init(session: MXSession, transaction: MXSASTransaction, verificationKind: KeyVerificationKind) {
self.session = session
self.transaction = transaction
self.emojis = self.transaction.sasEmoji
self.decimal = self.transaction.sasDecimal
self.verificationKind = verificationKind
}
deinit {
@@ -35,6 +35,7 @@ protocol DeviceVerificationVerifyViewModelType {
func process(viewAction: DeviceVerificationVerifyViewAction)
var emojis: [MXEmojiRepresentation]? { get set }
var decimal: String? { get set }
var emojis: [MXEmojiRepresentation]? { get }
var decimal: String? { get }
var verificationKind: KeyVerificationKind { get }
}
@@ -15,8 +15,9 @@
*/
import UIKit
import Reusable
class VerifyEmojiCollectionViewCell: UICollectionViewCell, Themable {
class VerifyEmojiCollectionViewCell: UICollectionViewCell, Reusable, Themable {
@IBOutlet weak var emoji: UILabel!
@IBOutlet weak var name: UILabel!