mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Add support for manually starting SaS verification flows and accepting remotely started ones
This commit is contained in:
committed by
Stefan Ceriu
parent
7888736a4d
commit
956e92a9ac
@@ -24,6 +24,12 @@ class SessionVerificationStateMachine {
|
||||
case initial
|
||||
/// Waiting for verification acceptance
|
||||
case requestingVerification
|
||||
/// Verification request accepted. Waiting for start
|
||||
case verificationRequestAccepted
|
||||
/// Waiting for SaS verification start
|
||||
case startingSasVerification
|
||||
/// A SaS verification flow has been started
|
||||
case sasVerificationStarted
|
||||
/// Verification accepted and emojis received
|
||||
case showingChallenge(emojis: [SessionVerificationEmoji])
|
||||
/// Emojis match locally
|
||||
@@ -42,6 +48,12 @@ class SessionVerificationStateMachine {
|
||||
enum Event: EventType {
|
||||
/// Request verification
|
||||
case requestVerification
|
||||
/// The current verification request has been accepted
|
||||
case didAcceptVerificationRequest
|
||||
/// Start a SaS verification flow
|
||||
case startSasVerification
|
||||
/// Started a SaS verification flow
|
||||
case didStartSasVerification
|
||||
/// Has received emojis
|
||||
case didReceiveChallenge(emojis: [SessionVerificationEmoji])
|
||||
/// Emojis match
|
||||
@@ -69,15 +81,19 @@ class SessionVerificationStateMachine {
|
||||
init() {
|
||||
stateMachine = StateMachine(state: .initial) { machine in
|
||||
machine.addRoutes(event: .requestVerification, transitions: [.initial => .requestingVerification])
|
||||
machine.addRoutes(event: .didAcceptVerificationRequest, transitions: [.requestingVerification => .verificationRequestAccepted])
|
||||
machine.addRoutes(event: .startSasVerification, transitions: [.verificationRequestAccepted => .startingSasVerification])
|
||||
machine.addRoutes(event: .didFail, transitions: [.requestingVerification => .initial])
|
||||
machine.addRoutes(event: .restart, transitions: [.cancelled => .initial])
|
||||
|
||||
// Transitions with associated values need to be handled through `addRouteMapping`
|
||||
machine.addRouteMapping { event, fromState, _ in
|
||||
switch (event, fromState) {
|
||||
case (.didReceiveChallenge(let emojis), .requestingVerification):
|
||||
case (.didStartSasVerification, _):
|
||||
return .sasVerificationStarted
|
||||
|
||||
case (.didReceiveChallenge(let emojis), .sasVerificationStarted):
|
||||
return .showingChallenge(emojis: emojis)
|
||||
|
||||
case (.acceptChallenge, .showingChallenge(let emojis)):
|
||||
return .acceptingChallenge(emojis: emojis)
|
||||
case (.didFail, .acceptingChallenge(let emojis)):
|
||||
@@ -100,6 +116,14 @@ class SessionVerificationStateMachine {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
addTransitionHandler { context in
|
||||
if let event = context.event {
|
||||
MXLog.info("Transitioning from `\(context.fromState)` to `\(context.toState)` with event `\(event)`")
|
||||
} else {
|
||||
MXLog.info("Transitioning from \(context.fromState)` to `\(context.toState)`")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user