diff --git a/src/session/model/verification/identity_verification.rs b/src/session/model/verification/identity_verification.rs index 375fa06a..de2c8c29 100644 --- a/src/session/model/verification/identity_verification.rs +++ b/src/session/model/verification/identity_verification.rs @@ -381,6 +381,9 @@ impl IdentityVerification { } fn start_handler(&self) { + let Some(flow_id) = self.flow_id() else { + return; + }; let imp = self.imp(); let main_sender = if let Some(main_sender) = imp.main_sender.take() { @@ -392,7 +395,7 @@ impl IdentityVerification { let client = self.session().client(); let user_id = self.user().user_id(); - let flow_id = self.flow_id().to_owned(); + let flow_id = flow_id.to_owned(); let (sync_sender, sync_receiver) = mpsc::channel(100); imp.sync_sender.replace(Some(sync_sender)); @@ -627,15 +630,17 @@ impl IdentityVerification { } /// The flow ID of this verification request. - pub fn flow_id(&self) -> &str { - self.imp() - .flow_id - .get() - .expect("Flow Id isn't always set on verifications with error state.") + pub fn flow_id(&self) -> Option<&str> { + self.imp().flow_id.get().map(AsRef::as_ref) } /// Set the flow ID of this verification request. - fn set_flow_id(&self, flow_id: String) { + fn set_flow_id(&self, flow_id: Option) { + let Some(flow_id) = flow_id else { + // Ignore missiing flow ID. + return; + }; + self.imp().flow_id.set(flow_id).unwrap(); } diff --git a/src/session/model/verification/verification_list.rs b/src/session/model/verification/verification_list.rs index 97b0ed52..584e1bec 100644 --- a/src/session/model/verification/verification_list.rs +++ b/src/session/model/verification/verification_list.rs @@ -341,6 +341,10 @@ impl VerificationList { /// Add a new `IdentityVerification` request pub fn add(&self, request: IdentityVerification) { + // Don't add requests that failed to start. + let Some(flow_id) = request.flow_id() else { + return; + }; // Don't add requests that are already finished if request.is_finished() { return; @@ -359,7 +363,7 @@ impl VerificationList { ); list.insert( - FlowId::new(request.user().user_id(), request.flow_id().to_owned()), + FlowId::new(request.user().user_id(), flow_id.to_owned()), request, ); length as u32 @@ -369,13 +373,18 @@ impl VerificationList { } pub fn remove(&self, request: &IdentityVerification) { + // Requests without a flow ID are never added. + let Some(flow_id) = request.flow_id() else { + return; + }; + let position = if let Some((position, ..)) = self.imp() .list .borrow_mut() .shift_remove_full(&FlowIdUnowned::new( request.user().user_id().as_ref(), - request.flow_id(), + flow_id, )) { position } else { @@ -388,7 +397,7 @@ impl VerificationList { pub fn get_by_id( &self, user_id: &UserId, - flow_id: &impl AsRef, + flow_id: impl AsRef, ) -> Option { let flow_id = FlowIdUnowned::new(user_id, flow_id.as_ref()); self.imp().list.borrow().get(&flow_id).cloned()