From 93ad810f31dff19594ef03b007a9db185f8361d4 Mon Sep 17 00:00:00 2001 From: Kevin Boos Date: Fri, 4 Oct 2024 23:50:43 -0700 Subject: [PATCH 1/4] Device verification is almost fully implemented. Untested. A background async task runs a sync loop that adds event handlers to the Client and then listens for incoming verification requests. When it receives one asynchronously, it posts a `VerificationAction` to the main UI thread, which is then handled by the top-level `App`. The top-level `App` opens up and populates a `VerificationModal`, which uses a tokio async channel that was sent along with the `VerificationAction` to send user interactive responses back to the async task. The background async task uses those responses to communicate with to the other device participating in the verificaiton via standard Matrix SDK calls. So basically, there are two state machines that get kept in lockstep based on user-side actions and SDK-side actions, and the async task and main UI thread communicate with each other by posting actions to the main UI thread and then sending responses back to the async task over a tokio channel. Other changes: * Consolidate Robrix-styled icon buttons into a separate widget, extracting it out of `user_profile`rs. * Add a checkmark SVG icon to be used for Ok/Accept buttons. --- resources/icons/checkmark.svg | 9 + src/app.rs | 41 +++- src/lib.rs | 3 + src/profile/user_profile.rs | 103 +--------- src/shared/icon_button.rs | 96 +++++++++ src/shared/mod.rs | 2 + src/shared/styles.rs | 7 + src/sliding_sync.rs | 8 +- src/verification.rs | 296 +++++++++++++++++++++++++++ src/verification_modal.rs | 367 ++++++++++++++++++++++++++++++++++ 10 files changed, 831 insertions(+), 101 deletions(-) create mode 100644 resources/icons/checkmark.svg create mode 100644 src/shared/icon_button.rs create mode 100644 src/verification.rs create mode 100644 src/verification_modal.rs diff --git a/resources/icons/checkmark.svg b/resources/icons/checkmark.svg new file mode 100644 index 00000000..1e8e409e --- /dev/null +++ b/resources/icons/checkmark.svg @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/src/app.rs b/src/app.rs index 77cd32ba..6dcdc44e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,7 +1,11 @@ use makepad_widgets::*; use matrix_sdk::ruma::OwnedRoomId; -use crate::home::rooms_list::RoomListAction; +use crate::{ + home::rooms_list::RoomListAction, + verification::VerificationAction, + verification_modal::{VerificationModalAction, VerificationModalWidgetRefExt}, +}; live_design! { import makepad_widgets::base::*; @@ -103,7 +107,19 @@ live_design! { pass: {clear_color: #2A} body = { - home_screen = {} + // A wrapper view for showing top-level app modals/dialogs/popups + { + width: Fill, height: Fill, + flow: Overlay, + + home_screen = {} + + verification_modal = { + content: { + verification_modal_inner = {} + } + } + } } // end of body } } @@ -128,6 +144,7 @@ impl LiveRegister for App { // then other modules widgets. makepad_widgets::live_design(cx); crate::shared::live_design(cx); + crate::verification_modal::live_design(cx); crate::home::live_design(cx); crate::profile::live_design(cx); } @@ -168,7 +185,24 @@ impl MatchEvent for App { ); self.ui.redraw(cx); } - _ => (), + RoomListAction::None => { } + } + + // TODO FIXME: need to add a cast_ref() method to WidgetAction + // that doesn't require the action to be clonable. + match action.as_widget_action().cast() { + VerificationAction::RequestReceived { request, response_sender } => { + log!("Received a new verification request: {:?}", request); + self.ui.verification_modal(id!(verification_modal_inner)) + .initialize_with_data(request, response_sender); + self.ui.modal(id!(verification_modal)).open(cx); + } + // other verification actions are handled by the verification modal itself. + _ => { } + } + + if let VerificationModalAction::Close = action.as_widget_action().cast() { + self.ui.modal(id!(verification_modal)).close(cx); } } } @@ -222,3 +256,4 @@ pub struct SelectedRoom { pub id: OwnedRoomId, pub name: Option, } + diff --git a/src/lib.rs b/src/lib.rs index 7c9b8df1..1b4ecf74 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,8 @@ pub mod persistent_state; pub mod home; /// User profile info and a user profile sliding pane. mod profile; +/// A modal/dialog popup for interactive verification of users/devices. +mod verification_modal; /// Shared UI components. pub mod shared; /// Generating text previews of timeline events/messages. @@ -20,6 +22,7 @@ mod event_preview; pub mod sliding_sync; pub mod avatar_cache; pub mod media_cache; +pub mod verification; pub mod utils; pub mod temp_storage; diff --git a/src/profile/user_profile.rs b/src/profile/user_profile.rs index 35f68e5b..6818fd20 100644 --- a/src/profile/user_profile.rs +++ b/src/profile/user_profile.rs @@ -100,6 +100,7 @@ live_design! { import crate::shared::helpers::*; import crate::shared::styles::*; import crate::shared::avatar::*; + import crate::shared::icon_button::*; // Copied from Moxin FadeView = { @@ -113,98 +114,6 @@ live_design! { } } - // Copied from Moxin - // - // Customized button widget, based on the RoundedView shaders with some modifications - // which is a better fit with our application UI design - UserProfileActionButton =