Commit f987e71a46
Unsigned
Layout: unified · split
src/room/verification.rs +45 −16
| @@ -32,7 +32,10 @@ pub struct Verification { | |||
| 32 | #[derive(Clone, Debug)] | 32 | #[derive(Clone, Debug)] |
| 33 | enum ActiveVerification { | 33 | enum ActiveVerification { |
| 34 | Request(VerificationRequest), | 34 | Request(VerificationRequest), |
| 35 | Sas(SasVerification), | 35 | Sas { |
| 36 | flow_id: String, | ||
| 37 | verification: SasVerification, | ||
| 38 | }, | ||
| 36 | } | 39 | } |
| 37 | 40 | ||
| 38 | impl From<VerificationRequest> for ActiveVerification { | 41 | impl From<VerificationRequest> for ActiveVerification { |
| @@ -41,17 +44,13 @@ impl From<VerificationRequest> for ActiveVerification { | |||
| 41 | } | 44 | } |
| 42 | } | 45 | } |
| 43 | 46 | ||
| 44 | impl From<SasVerification> for ActiveVerification { | ||
| 45 | fn from(v: SasVerification) -> Self { | ||
| 46 | Self::Sas(v) | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | impl ActiveVerification { | 47 | impl ActiveVerification { |
| 51 | async fn cancel(self) -> Result<(), Error> { | 48 | async fn cancel(self) -> Result<(), Error> { |
| 52 | match self { | 49 | match self { |
| 53 | ActiveVerification::Request(request) => request.cancel().await, | 50 | ActiveVerification::Request(request) => request.cancel().await, |
| 54 | ActiveVerification::Sas(sas) => sas.cancel().await, | 51 | ActiveVerification::Sas { verification, .. } => { |
| 52 | verification.cancel().await | ||
| 53 | } | ||
| 55 | } | 54 | } |
| 56 | } | 55 | } |
| 57 | } | 56 | } |
| @@ -76,7 +75,7 @@ impl Verification { | |||
| 76 | let connection = self.connection.borrow().clone(); | 75 | let connection = self.connection.borrow().clone(); |
| 77 | 76 | ||
| 78 | if let Some(c) = connection { | 77 | if let Some(c) = connection { |
| 79 | if let Some(ActiveVerification::Sas(verification)) = | 78 | if let Some(ActiveVerification::Sas { verification, .. }) = |
| 80 | self.inner.borrow().clone() | 79 | self.inner.borrow().clone() |
| 81 | { | 80 | { |
| 82 | if let Err(e) = | 81 | if let Err(e) = |
| @@ -112,6 +111,7 @@ impl Verification { | |||
| 112 | if let Some(ActiveVerification::Request(verification)) = | 111 | if let Some(ActiveVerification::Request(verification)) = |
| 113 | verification | 112 | verification |
| 114 | { | 113 | { |
| 114 | let flow_id = verification.flow_id().to_owned(); | ||
| 115 | let verification_clone = verification.clone(); | 115 | let verification_clone = verification.clone(); |
| 116 | 116 | ||
| 117 | if let Err(e) = c | 117 | if let Err(e) = c |
| @@ -135,7 +135,11 @@ impl Verification { | |||
| 135 | .await | 135 | .await |
| 136 | { | 136 | { |
| 137 | Ok(Some(sas)) => { | 137 | 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 | }); | ||
| 139 | } | 143 | } |
| 140 | Ok(None) => { | 144 | Ok(None) => { |
| 141 | self.print("Could not start emoji verification"); | 145 | self.print("Could not start emoji verification"); |
| @@ -207,7 +211,11 @@ impl Verification { | |||
| 207 | ); | 211 | ); |
| 208 | self.buffer | 212 | self.buffer |
| 209 | .replace_verification_event(flow_id, rendered); | 213 | .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 | }); | ||
| 211 | 219 | ||
| 212 | // We accept here automatically since the only method | 220 | // We accept here automatically since the only method |
| 213 | // we're supporting is SAS verification | 221 | // we're supporting is SAS verification |
| @@ -240,8 +248,9 @@ impl Verification { | |||
| 240 | return; | 248 | return; |
| 241 | }; | 249 | }; |
| 242 | let flow_id = &e.content.relates_to.event_id; | 250 | let flow_id = &e.content.relates_to.event_id; |
| 243 | if let Some(ActiveVerification::Sas(sas)) = | 251 | if let Some(ActiveVerification::Sas { |
| 244 | self.inner.borrow().clone() | 252 | verification: sas, .. |
| 253 | }) = self.inner.borrow().clone() | ||
| 245 | { | 254 | { |
| 246 | if sas.can_be_presented() { | 255 | if sas.can_be_presented() { |
| 247 | let rendered = e.content.render_with_prefix( | 256 | let rendered = e.content.render_with_prefix( |
| @@ -256,9 +265,29 @@ impl Verification { | |||
| 256 | } | 265 | } |
| 257 | } | 266 | } |
| 258 | AnySyncMessageLikeEvent::KeyVerificationMac(_) => {} | 267 | AnySyncMessageLikeEvent::KeyVerificationMac(_) => {} |
| 259 | AnySyncMessageLikeEvent::KeyVerificationDone(_) => { | 268 | AnySyncMessageLikeEvent::KeyVerificationDone(e) => { |
| 260 | self.inner.borrow_mut().take(); | 269 | let Some(e) = e.as_original() else { |
| 261 | self.print("Verification done"); | 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 | } | ||
| 262 | } | 291 | } |
| 263 | AnySyncMessageLikeEvent::RoomMessage(e) => { | 292 | AnySyncMessageLikeEvent::RoomMessage(e) => { |
| 264 | let Some(e) = e.as_original() else { | 293 | let Some(e) = e.as_original() else { |
src/server.rs +3
| @@ -916,6 +916,9 @@ impl InnerServer { | |||
| 916 | refresh_status_bar = true; | 916 | refresh_status_bar = true; |
| 917 | handle_event(&event, e.content.transaction_id.to_string()).await | 917 | handle_event(&event, e.content.transaction_id.to_string()).await |
| 918 | } | 918 | } |
| 919 | AnyToDeviceEvent::KeyVerificationDone(e) => { | ||
| 920 | handle_event(&event, e.content.transaction_id.to_string()).await | ||
| 921 | } | ||
| 919 | _ => {} | 922 | _ => {} |
| 920 | } | 923 | } |
| 921 | 924 | ||