mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 09:32:52 +02:00
Incoming verification requests with Crypto V2
This commit is contained in:
+26
-13
@@ -102,7 +102,7 @@ final class KeyVerificationVerifyByScanningViewModel: KeyVerificationVerifyBySca
|
||||
|
||||
self.update(viewState: .loaded(viewData: viewData))
|
||||
|
||||
self.registerTransactionDidStateChangeNotification()
|
||||
self.registerDidStateChangeNotification()
|
||||
}
|
||||
|
||||
private func canShowScanAction(from verificationMethods: [String]) -> Bool {
|
||||
@@ -112,7 +112,7 @@ final class KeyVerificationVerifyByScanningViewModel: KeyVerificationVerifyBySca
|
||||
private func cancel() {
|
||||
self.cancelQRCodeTransaction()
|
||||
self.keyVerificationRequest.cancel(with: MXTransactionCancelCode.user(), success: nil, failure: nil)
|
||||
self.unregisterTransactionDidStateChangeNotification()
|
||||
self.unregisterDidStateChangeNotification()
|
||||
self.coordinatorDelegate?.keyVerificationVerifyByScanningViewModelDidCancel(self)
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ final class KeyVerificationVerifyByScanningViewModel: KeyVerificationVerifyBySca
|
||||
return
|
||||
}
|
||||
|
||||
self.unregisterTransactionDidStateChangeNotification()
|
||||
self.unregisterDidStateChangeNotification()
|
||||
self.coordinatorDelegate?.keyVerificationVerifyByScanningViewModel(self, didScanOtherQRCodeData: scannedQRCodeData, withTransaction: qrCodeTransaction)
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ final class KeyVerificationVerifyByScanningViewModel: KeyVerificationVerifyBySca
|
||||
// Check due to legacy implementation of key verification which could pass incorrect type of transaction
|
||||
if keyVerificationTransaction is MXIncomingSASTransaction {
|
||||
MXLog.debug("[KeyVerificationVerifyByScanningViewModel] SAS transaction should be outgoing")
|
||||
self.unregisterTransactionDidStateChangeNotification()
|
||||
self.unregisterDidStateChangeNotification()
|
||||
self.update(viewState: .error(KeyVerificationVerifyByScanningViewModelError.unknown))
|
||||
}
|
||||
|
||||
@@ -191,14 +191,27 @@ final class KeyVerificationVerifyByScanningViewModel: KeyVerificationVerifyBySca
|
||||
|
||||
// MARK: - MXKeyVerificationTransactionDidChange
|
||||
|
||||
private func registerTransactionDidStateChangeNotification() {
|
||||
private func registerDidStateChangeNotification() {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(requestDidStateChange(notification:)), name: .MXKeyVerificationRequestDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(transactionDidStateChange(notification:)), name: .MXKeyVerificationTransactionDidChange, object: nil)
|
||||
}
|
||||
|
||||
private func unregisterTransactionDidStateChangeNotification() {
|
||||
private func unregisterDidStateChangeNotification() {
|
||||
NotificationCenter.default.removeObserver(self, name: .MXKeyVerificationRequestDidChange, object: nil)
|
||||
NotificationCenter.default.removeObserver(self, name: .MXKeyVerificationTransactionDidChange, object: nil)
|
||||
}
|
||||
|
||||
@objc private func requestDidStateChange(notification: Notification) {
|
||||
guard let request = notification.object as? MXKeyVerificationRequest else {
|
||||
return
|
||||
}
|
||||
|
||||
if request.state == MXKeyVerificationRequestStateCancelled, let reason = request.reasonCancelCode {
|
||||
self.unregisterDidStateChangeNotification()
|
||||
self.update(viewState: .cancelled(cancelCode: reason, verificationKind: verificationKind))
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func transactionDidStateChange(notification: Notification) {
|
||||
guard let transaction = notification.object as? MXKeyVerificationTransaction else {
|
||||
return
|
||||
@@ -219,19 +232,19 @@ final class KeyVerificationVerifyByScanningViewModel: KeyVerificationVerifyBySca
|
||||
private func sasTransactionDidStateChange(_ transaction: MXSASTransaction) {
|
||||
switch transaction.state {
|
||||
case MXSASTransactionStateShowSAS:
|
||||
self.unregisterTransactionDidStateChangeNotification()
|
||||
self.unregisterDidStateChangeNotification()
|
||||
self.coordinatorDelegate?.keyVerificationVerifyByScanningViewModel(self, didStartSASVerificationWithTransaction: transaction)
|
||||
case MXSASTransactionStateCancelled:
|
||||
guard let reason = transaction.reasonCancelCode else {
|
||||
return
|
||||
}
|
||||
self.unregisterTransactionDidStateChangeNotification()
|
||||
self.unregisterDidStateChangeNotification()
|
||||
self.update(viewState: .cancelled(cancelCode: reason, verificationKind: verificationKind))
|
||||
case MXSASTransactionStateCancelledByMe:
|
||||
guard let reason = transaction.reasonCancelCode else {
|
||||
return
|
||||
}
|
||||
self.unregisterTransactionDidStateChangeNotification()
|
||||
self.unregisterDidStateChangeNotification()
|
||||
self.update(viewState: .cancelledByMe(reason))
|
||||
default:
|
||||
break
|
||||
@@ -242,22 +255,22 @@ final class KeyVerificationVerifyByScanningViewModel: KeyVerificationVerifyBySca
|
||||
switch transaction.state {
|
||||
case .verified:
|
||||
// Should not happen
|
||||
self.unregisterTransactionDidStateChangeNotification()
|
||||
self.unregisterDidStateChangeNotification()
|
||||
self.coordinatorDelegate?.keyVerificationVerifyByScanningViewModelDidCancel(self)
|
||||
case .qrScannedByOther:
|
||||
self.unregisterTransactionDidStateChangeNotification()
|
||||
self.unregisterDidStateChangeNotification()
|
||||
self.coordinatorDelegate?.keyVerificationVerifyByScanningViewModel(self, qrCodeDidScannedByOtherWithTransaction: transaction)
|
||||
case .cancelled:
|
||||
guard let reason = transaction.reasonCancelCode else {
|
||||
return
|
||||
}
|
||||
self.unregisterTransactionDidStateChangeNotification()
|
||||
self.unregisterDidStateChangeNotification()
|
||||
self.update(viewState: .cancelled(cancelCode: reason, verificationKind: verificationKind))
|
||||
case .cancelledByMe:
|
||||
guard let reason = transaction.reasonCancelCode else {
|
||||
return
|
||||
}
|
||||
self.unregisterTransactionDidStateChangeNotification()
|
||||
self.unregisterDidStateChangeNotification()
|
||||
self.update(viewState: .cancelledByMe(reason))
|
||||
default:
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user