From bb8b0cf6b9bfebff0b2d0d1fddb3b585da28c368 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Thu, 10 Oct 2024 18:44:22 +0300 Subject: [PATCH] Expose requesting device details to the final client --- .../src/session_verification.rs | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/session_verification.rs b/bindings/matrix-sdk-ffi/src/session_verification.rs index 5b65b2c44..6cc4dea8b 100644 --- a/bindings/matrix-sdk-ffi/src/session_verification.rs +++ b/bindings/matrix-sdk-ffi/src/session_verification.rs @@ -38,9 +38,20 @@ pub enum SessionVerificationData { Decimals { values: Vec }, } +/// Details about the incoming verification request +#[derive(Debug, uniffi::Record)] +pub struct SessionVerificationRequestDetails { + sender_id: String, + flow_id: String, + device_id: String, + display_name: Option, + /// First time this device was seen in milliseconds since epoch. + first_seen_timestamp: u64, +} + #[matrix_sdk_ffi_macros::export(callback_interface)] pub trait SessionVerificationControllerDelegate: Sync + Send { - fn did_receive_verification_request(&self, sender_id: String, flow_id: String); + fn did_receive_verification_request(&self, details: SessionVerificationRequestDetails); fn did_accept_verification_request(&self); fn did_start_sas_verification(&self); fn did_receive_verification_data(&self, data: SessionVerificationData); @@ -66,7 +77,8 @@ impl SessionVerificationController { *self.delegate.write().unwrap() = delegate; } - /// Set this particular request as the currently active one and register for events pertaining it. + /// Set this particular request as the currently active one and register for + /// events pertaining it. /// * `sender_id` - The user requesting verification. /// * `flow_id` - - The ID that uniquely identifies the verification flow. pub async fn acknowledge_verification_request( @@ -125,7 +137,8 @@ impl SessionVerificationController { Ok(()) } - /// Transition the current verification request into a SAS verification flow. + /// Transition the current verification request into a SAS verification + /// flow. pub async fn start_sas_verification(&self) -> Result<(), ClientError> { let verification_request = self.verification_request.read().unwrap().clone(); @@ -217,11 +230,20 @@ impl SessionVerificationController { return; } + let VerificationRequestState::Requested { other_device_data, .. } = request.state() + else { + error!("Received key verification event but the request is in the wrong state."); + return; + }; + if let Some(delegate) = &*self.delegate.read().unwrap() { - delegate.did_receive_verification_request( - request.other_user_id().into(), - request.flow_id().into(), - ); + delegate.did_receive_verification_request(SessionVerificationRequestDetails { + sender_id: request.other_user_id().into(), + flow_id: request.flow_id().into(), + device_id: other_device_data.device_id().into(), + display_name: other_device_data.display_name().map(str::to_string), + first_seen_timestamp: other_device_data.first_time_seen_ts().get().into(), + }); } } }