Commit f987e71a46

f987e71a46827b8e69112cfb8e5977cf59fc313a

parent: effa2711ea

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-07-10 14:29 UTC
committer: <strk@kbt.io>

fix: match verification completion flows

Layout: unified · split

src/room/verification.rs +45 −16
@@ -32,7 +32,10 @@ pub struct Verification {
3232#[derive(Clone, Debug)]
3333enum ActiveVerification {
3434 Request(VerificationRequest),
35 Sas(SasVerification),
35 Sas {
36 flow_id: String,
37 verification: SasVerification,
38 },
3639}
3740
3841impl From<VerificationRequest> for ActiveVerification {
@@ -41,17 +44,13 @@ impl From<VerificationRequest> for ActiveVerification {
4144 }
4245}
4346
44impl From<SasVerification> for ActiveVerification {
45 fn from(v: SasVerification) -> Self {
46 Self::Sas(v)
47 }
48}
49
5047impl ActiveVerification {
5148 async fn cancel(self) -> Result<(), Error> {
5249 match self {
5350 ActiveVerification::Request(request) => request.cancel().await,
54 ActiveVerification::Sas(sas) => sas.cancel().await,
51 ActiveVerification::Sas { verification, .. } => {
52 verification.cancel().await
53 }
5554 }
5655 }
5756}
@@ -76,7 +75,7 @@ impl Verification {
7675 let connection = self.connection.borrow().clone();
7776
7877 if let Some(c) = connection {
79 if let Some(ActiveVerification::Sas(verification)) =
78 if let Some(ActiveVerification::Sas { verification, .. }) =
8079 self.inner.borrow().clone()
8180 {
8281 if let Err(e) =
@@ -112,6 +111,7 @@ impl Verification {
112111 if let Some(ActiveVerification::Request(verification)) =
113112 verification
114113 {
114 let flow_id = verification.flow_id().to_owned();
115115 let verification_clone = verification.clone();
116116
117117 if let Err(e) = c
@@ -135,7 +135,11 @@ impl Verification {
135135 .await
136136 {
137137 Ok(Some(sas)) => {
138 *self.inner.borrow_mut() = Some(sas.into());
138 *self.inner.borrow_mut() =
139 Some(ActiveVerification::Sas {
140 flow_id,
141 verification: sas,
142 });
139143 }
140144 Ok(None) => {
141145 self.print("Could not start emoji verification");
@@ -207,7 +211,11 @@ impl Verification {
207211 );
208212 self.buffer
209213 .replace_verification_event(flow_id, rendered);
210 *self.inner.borrow_mut() = Some(sas.clone().into());
214 *self.inner.borrow_mut() =
215 Some(ActiveVerification::Sas {
216 flow_id: flow_id.to_string(),
217 verification: sas.clone(),
218 });
211219
212220 // We accept here automatically since the only method
213221 // we're supporting is SAS verification
@@ -240,8 +248,9 @@ impl Verification {
240248 return;
241249 };
242250 let flow_id = &e.content.relates_to.event_id;
243 if let Some(ActiveVerification::Sas(sas)) =
244 self.inner.borrow().clone()
251 if let Some(ActiveVerification::Sas {
252 verification: sas, ..
253 }) = self.inner.borrow().clone()
245254 {
246255 if sas.can_be_presented() {
247256 let rendered = e.content.render_with_prefix(
@@ -256,9 +265,29 @@ impl Verification {
256265 }
257266 }
258267 AnySyncMessageLikeEvent::KeyVerificationMac(_) => {}
259 AnySyncMessageLikeEvent::KeyVerificationDone(_) => {
260 self.inner.borrow_mut().take();
261 self.print("Verification done");
268 AnySyncMessageLikeEvent::KeyVerificationDone(e) => {
269 let Some(e) = e.as_original() else {
270 return;
271 };
272 let completed_flow = e.content.relates_to.event_id.as_str();
273 let matches_active = self
274 .inner
275 .borrow()
276 .as_ref()
277 .map(|active| match active {
278 ActiveVerification::Request(request) => {
279 request.flow_id() == completed_flow
280 }
281 ActiveVerification::Sas { flow_id, .. } => {
282 flow_id == completed_flow
283 }
284 })
285 .unwrap_or(false);
286
287 if matches_active {
288 self.inner.borrow_mut().take();
289 self.print("Verification done");
290 }
262291 }
263292 AnySyncMessageLikeEvent::RoomMessage(e) => {
264293 let Some(e) = e.as_original() else {
src/server.rs +3
@@ -916,6 +916,9 @@ impl InnerServer {
916916 refresh_status_bar = true;
917917 handle_event(&event, e.content.transaction_id.to_string()).await
918918 }
919 AnyToDeviceEvent::KeyVerificationDone(e) => {
920 handle_event(&event, e.content.transaction_id.to_string()).await
921 }
919922 _ => {}
920923 }
921924