verification: Set flow ID as optional
Since it is not set if an error happens when trying to create one. We might forget to check whether creation failed or not.
This commit is contained in:
parent
556d470074
commit
81660826c2
2 changed files with 24 additions and 10 deletions
|
@ -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<String>) {
|
||||
let Some(flow_id) = flow_id else {
|
||||
// Ignore missiing flow ID.
|
||||
return;
|
||||
};
|
||||
|
||||
self.imp().flow_id.set(flow_id).unwrap();
|
||||
}
|
||||
|
||||
|
|
|
@ -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<str>,
|
||||
flow_id: impl AsRef<str>,
|
||||
) -> Option<IdentityVerification> {
|
||||
let flow_id = FlowIdUnowned::new(user_id, flow_id.as_ref());
|
||||
self.imp().list.borrow().get(&flow_id).cloned()
|
||||
|
|
Loading…
Reference in a new issue