From 2d02de14b9715f670b8b15ba8e2645c8813dd937 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Tue, 12 Aug 2025 15:41:17 +0100 Subject: [PATCH] refactor(timeline): Make RoomDataProvider provide Decryptor to simplify redecryption --- .../src/timeline/controller/mod.rs | 46 ++---- .../src/timeline/tests/encryption.rs | 138 ++++++++++-------- .../matrix-sdk-ui/src/timeline/tests/mod.rs | 88 ++++++++++- .../src/timeline/tests/read_receipts.rs | 20 +-- crates/matrix-sdk-ui/src/timeline/traits.rs | 36 +---- 5 files changed, 186 insertions(+), 142 deletions(-) diff --git a/crates/matrix-sdk-ui/src/timeline/controller/mod.rs b/crates/matrix-sdk-ui/src/timeline/controller/mod.rs index 655fdd34672..e04ad148a2e 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/mod.rs @@ -21,9 +21,8 @@ use eyeball_im_util::vector::{FilterMap, VectorObserverExt}; use futures_core::Stream; use imbl::Vector; #[cfg(test)] -use matrix_sdk::crypto::OlmMachine; +use matrix_sdk::Result; use matrix_sdk::{ - Result, Room, deserialized_responses::TimelineEvent, event_cache::{RoomEventCache, RoomPaginationStatus}, paginators::{PaginationResult, Paginator}, @@ -31,6 +30,8 @@ use matrix_sdk::{ LocalEcho, LocalEchoContent, RoomSendQueueUpdate, SendHandle, SendReactionHandle, }, }; +#[cfg(test)] +use ruma::events::receipt::ReceiptEventContent; use ruma::{ EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedTransactionId, TransactionId, UserId, api::client::receipt::create_receipt::v3::ReceiptType as SendReceiptType, @@ -46,8 +47,6 @@ use ruma::{ room_version_rules::RoomVersionRules, serde::Raw, }; -#[cfg(test)] -use ruma::{OwnedRoomId, RoomId, events::receipt::ReceiptEventContent}; use tokio::sync::{RwLock, RwLockWriteGuard}; use tracing::{debug, error, field::debug, info, instrument, trace, warn}; @@ -68,11 +67,11 @@ use super::{ event_item::{ReactionStatus, RemoteEventOrigin}, item::TimelineUniqueId, subscriber::TimelineSubscriber, - traits::{Decryptor, RoomDataProvider}, + traits::RoomDataProvider, }; use crate::{ timeline::{ - MsgLikeContent, MsgLikeKind, TimelineEventFilterFn, + MsgLikeContent, MsgLikeKind, Room, TimelineEventFilterFn, algorithms::rfind_event_by_item_id, date_dividers::DateDividerAdjuster, event_item::TimelineItemHandle, @@ -152,7 +151,7 @@ impl TimelineFocusKind

{ } #[derive(Clone, Debug)] -pub(super) struct TimelineController { +pub(super) struct TimelineController { /// Inner mutable state. state: Arc>>, @@ -161,7 +160,8 @@ pub(super) struct TimelineController, + decryption_retry_task: DecryptionRetryTask, } #[derive(Clone)] @@ -290,7 +290,7 @@ pub fn default_event_filter(event: &AnySyncTimelineEvent, rules: &RoomVersionRul } } -impl TimelineController { +impl TimelineController

{ pub(super) fn new( room_data_provider: P, focus: TimelineFocus, @@ -1103,12 +1103,10 @@ impl TimelineController { true } - async fn retry_event_decryption_inner( - &self, - decryptor: D, - session_ids: Option>, - ) { - self.decryption_retry_task.decrypt(decryptor, session_ids, self.settings.clone()).await; + pub(crate) async fn retry_event_decryption_inner(&self, session_ids: Option>) { + self.decryption_retry_task + .decrypt(self.room_data_provider.clone(), session_ids, self.settings.clone()) + .await; } pub(super) async fn set_sender_profiles_pending(&self) { @@ -1250,7 +1248,7 @@ impl TimelineController { /// Subscribe to changes in the read receipts of our own user. pub async fn subscribe_own_user_read_receipts_changed( &self, - ) -> impl Stream + use { + ) -> impl Stream + use

{ self.state.read().await.meta.read_receipts.subscribe_own_user_read_receipts_changed() } @@ -1604,7 +1602,7 @@ impl TimelineController { #[instrument(skip(self), fields(room_id = ?self.room().room_id()))] pub(super) async fn retry_event_decryption(&self, session_ids: Option>) { - self.retry_event_decryption_inner(self.room().clone(), session_ids).await + self.retry_event_decryption_inner(session_ids).await } /// Combine the global (event cache) pagination status with the local state @@ -1638,18 +1636,6 @@ impl TimelineController { } } -#[cfg(test)] -impl TimelineController { - pub(super) async fn retry_event_decryption_test( - &self, - room_id: &RoomId, - olm_machine: OlmMachine, - session_ids: Option>, - ) { - self.retry_event_decryption_inner((olm_machine, room_id.to_owned()), session_ids).await - } -} - #[allow(clippy::too_many_arguments)] async fn fetch_replied_to_event( mut state_guard: RwLockWriteGuard<'_, TimelineState

>, diff --git a/crates/matrix-sdk-ui/src/timeline/tests/encryption.rs b/crates/matrix-sdk-ui/src/timeline/tests/encryption.rs index d1a4bc94719..24b4eef21bd 100644 --- a/crates/matrix-sdk-ui/src/timeline/tests/encryption.rs +++ b/crates/matrix-sdk-ui/src/timeline/tests/encryption.rs @@ -53,7 +53,7 @@ use super::TestTimeline; use crate::{ timeline::{ EncryptedMessage, MsgLikeContent, MsgLikeKind, TimelineDetails, TimelineItemContent, - tests::{TestRoomDataProvider, TestTimelineBuilder}, + tests::{TestDecryptor, TestRoomDataProvider, TestTimelineBuilder}, }, unable_to_decrypt_hook::{UnableToDecryptHook, UnableToDecryptInfo, UtdHookManager}, }; @@ -90,7 +90,17 @@ async fn test_retry_message_decryption() { let client = test_client_builder(None).build().await.unwrap(); let utd_hook = Arc::new(UtdHookManager::new(hook.clone(), client)); - let timeline = TestTimelineBuilder::new().unable_to_decrypt_hook(utd_hook.clone()).build(); + let own_user_id = user_id!("@example:morheus.localhost"); + let olm_machine = OlmMachine::new(own_user_id, "SomeDeviceId".into()).await; + + let timeline = TestTimelineBuilder::new() + .unable_to_decrypt_hook(utd_hook.clone()) + .provider(TestRoomDataProvider::default().with_decryptor(TestDecryptor::new( + room_id!("!DovneieKSTkdHKpIXy:morpheus.localhost"), + &olm_machine, + ))) + .build(); + let mut stream = timeline.subscribe().await; let f = &timeline.factory; @@ -146,19 +156,13 @@ async fn test_retry_message_decryption() { assert!(utds[0].time_to_decrypt.is_none()); } - let own_user_id = user_id!("@example:morheus.localhost"); let exported_keys = decrypt_room_key_export(Cursor::new(SESSION_KEY), "1234").unwrap(); - let olm_machine = OlmMachine::new(own_user_id, "SomeDeviceId".into()).await; olm_machine.store().import_exported_room_keys(exported_keys, |_, _| {}).await.unwrap(); timeline .controller - .retry_event_decryption_test( - room_id!("!DovneieKSTkdHKpIXy:morpheus.localhost"), - olm_machine, - Some(iter::once(SESSION_ID.to_owned()).collect()), - ) + .retry_event_decryption_test(Some(iter::once(SESSION_ID.to_owned()).collect())) .await; assert_eq!(timeline.controller.items().await.len(), 2); @@ -198,7 +202,16 @@ async fn test_false_positive_late_decryption_regression() { UtdHookManager::new(hook.clone(), client).with_max_delay(Duration::from_millis(500)), ); - let timeline = TestTimelineBuilder::new().unable_to_decrypt_hook(utd_hook.clone()).build(); + let own_user_id = user_id!("@example:morheus.localhost"); + let olm_machine = OlmMachine::new(own_user_id, "SomeDeviceId".into()).await; + + let timeline = TestTimelineBuilder::new() + .unable_to_decrypt_hook(utd_hook.clone()) + .provider(TestRoomDataProvider::default().with_decryptor(TestDecryptor::new( + room_id!("!DovneieKSTkdHKpIXy:morpheus.localhost"), + &olm_machine, + ))) + .build(); let f = &timeline.factory; timeline @@ -227,9 +240,6 @@ async fn test_false_positive_late_decryption_regression() { ) .await; - let own_user_id = user_id!("@example:morheus.localhost"); - let olm_machine = OlmMachine::new(own_user_id, "SomeDeviceId".into()).await; - sleep(Duration::from_millis(200)).await; // Simulate a retry decryption. @@ -237,11 +247,7 @@ async fn test_false_positive_late_decryption_regression() { // retry timeline .controller - .retry_event_decryption_test( - room_id!("!DovneieKSTkdHKpIXy:morpheus.localhost"), - olm_machine, - Some(iter::once(SESSION_ID.to_owned()).collect()), - ) + .retry_event_decryption_test(Some(iter::once(SESSION_ID.to_owned()).collect())) .await; assert_eq!(timeline.controller.items().await.len(), 2); @@ -287,7 +293,16 @@ async fn test_retry_edit_decryption() { rHCyB4ElRjU\n\ -----END MEGOLM SESSION DATA-----"; - let timeline = TestTimeline::new(); + let own_user_id = user_id!("@example:morheus.localhost"); + let olm_machine = OlmMachine::new(own_user_id, "SomeDeviceId".into()).await; + + let timeline = TestTimelineBuilder::new() + .provider(TestRoomDataProvider::default().with_decryptor(TestDecryptor::new( + room_id!("!bdsREiCPHyZAPkpXer:morpheus.localhost"), + &olm_machine, + ))) + .build(); + let f = &timeline.factory; let mut stream = timeline.subscribe_events().await; @@ -353,18 +368,9 @@ async fn test_retry_edit_decryption() { let mut keys = decrypt_room_key_export(Cursor::new(SESSION1_KEY), "1234").unwrap(); keys.extend(decrypt_room_key_export(Cursor::new(SESSION2_KEY), "1234").unwrap()); - let own_user_id = user_id!("@example:morheus.localhost"); - let olm_machine = OlmMachine::new(own_user_id, "SomeDeviceId".into()).await; olm_machine.store().import_exported_room_keys(keys, |_, _| {}).await.unwrap(); - timeline - .controller - .retry_event_decryption_test( - room_id!("!bdsREiCPHyZAPkpXer:morpheus.localhost"), - olm_machine, - None, - ) - .await; + timeline.controller.retry_event_decryption_test(None).await; // Then first, the first item gets decrypted on its own assert_next_matches_with_timeout!(stream, VectorDiff::Set { index: 0, .. }); @@ -419,7 +425,15 @@ async fn test_retry_edit_and_more() { ) } - let timeline = TestTimeline::new(); + let olm_machine = OlmMachine::new(user_id!("@jptest:matrix.org"), DEVICE_ID.into()).await; + + let timeline = TestTimelineBuilder::new() + .provider(TestRoomDataProvider::default().with_decryptor(TestDecryptor::new( + room_id!("!wFnAUSQbxMcfIMgvNX:flipdot.org"), + &olm_machine, + ))) + .build(); + let f = &timeline.factory; let mut stream = timeline.subscribe().await; @@ -480,17 +494,12 @@ async fn test_retry_edit_and_more() { assert_next_matches_with_timeout!(stream, VectorDiff::PushBack { .. }); assert_next_matches_with_timeout!(stream, VectorDiff::PushBack { .. }); - let olm_machine = OlmMachine::new(user_id!("@jptest:matrix.org"), DEVICE_ID.into()).await; let keys = decrypt_room_key_export(Cursor::new(SESSION_KEY), "testing").unwrap(); olm_machine.store().import_exported_room_keys(keys, |_, _| {}).await.unwrap(); timeline .controller - .retry_event_decryption_test( - room_id!("!wFnAUSQbxMcfIMgvNX:flipdot.org"), - olm_machine, - Some(iter::once(SESSION_ID.to_owned()).collect()), - ) + .retry_event_decryption_test(Some(iter::once(SESSION_ID.to_owned()).collect())) .await; // Then first, the original item got decrypted @@ -536,7 +545,16 @@ async fn test_retry_message_decryption_highlighted() { FM8H2PpVkKgrA+tx8LNQD+FWDfp6MyhmEJEvk9r5vU9LtTXtZl4toYvNY0UHUBbZj2xF9U9Z9A\n\ -----END MEGOLM SESSION DATA-----"; - let timeline = TestTimeline::new(); + let own_user_id = user_id!("@example:matrix.org"); + let olm_machine = OlmMachine::new(own_user_id, "SomeDeviceId".into()).await; + + let timeline = TestTimelineBuilder::new() + .provider(TestRoomDataProvider::default().with_decryptor(TestDecryptor::new( + room_id!("!rYtFvMGENJleNQVJzb:matrix.org"), + &olm_machine, + ))) + .build(); + let f = &timeline.factory; let mut stream = timeline.subscribe().await; @@ -583,19 +601,13 @@ async fn test_retry_message_decryption_highlighted() { let date_divider = assert_next_matches!(stream, VectorDiff::PushFront { value } => value); assert!(date_divider.is_date_divider()); - let own_user_id = user_id!("@example:matrix.org"); let exported_keys = decrypt_room_key_export(Cursor::new(SESSION_KEY), "1234").unwrap(); - let olm_machine = OlmMachine::new(own_user_id, "SomeDeviceId".into()).await; olm_machine.store().import_exported_room_keys(exported_keys, |_, _| {}).await.unwrap(); timeline .controller - .retry_event_decryption_test( - room_id!("!rYtFvMGENJleNQVJzb:matrix.org"), - olm_machine, - Some(iter::once(SESSION_ID.to_owned()).collect()), - ) + .retry_event_decryption_test(Some(iter::once(SESSION_ID.to_owned()).collect())) .await; assert_eq!(timeline.controller.items().await.len(), 2); @@ -615,12 +627,19 @@ async fn test_retry_fetching_encryption_info() { let sender = user_id!("@sender:s.co"); let room_id = room_id!("!room:s.co"); + let own_user_id = user_id!("@me:s.co"); + let olm_machine = OlmMachine::new(own_user_id, "SomeDeviceId".into()).await; + // Given when I ask the room for new encryption info for any session, it will // say "verified" let verified_encryption_info = make_encryption_info(SESSION_ID, VerificationState::Verified); - let provider = - TestRoomDataProvider::default().with_encryption_info(SESSION_ID, verified_encryption_info); + + let provider = TestRoomDataProvider::default() + .with_encryption_info(SESSION_ID, verified_encryption_info) + .with_decryptor(TestDecryptor::new(room_id, &olm_machine)); + let timeline = TestTimelineBuilder::new().provider(provider).build(); + let f = &timeline.factory; let mut stream = timeline.subscribe_events().await; @@ -671,15 +690,9 @@ async fn test_retry_fetching_encryption_info() { } // When we retry the session with ID SESSION_ID - let own_user_id = user_id!("@me:s.co"); - let olm_machine = OlmMachine::new(own_user_id, "SomeDeviceId".into()).await; timeline .controller - .retry_event_decryption_test( - room_id, - olm_machine, - Some(iter::once(SESSION_ID.to_owned()).collect()), - ) + .retry_event_decryption_test(Some(iter::once(SESSION_ID.to_owned()).collect())) .await; // Then the event in that session has been updated to be verified @@ -817,7 +830,16 @@ async fn test_retry_decryption_updates_response() { HztoSJUr/2Y\n\ -----END MEGOLM SESSION DATA-----"; - let timeline = TestTimeline::new(); + let own_user_id = user_id!("@example:morheus.localhost"); + let olm_machine = OlmMachine::new(own_user_id, "SomeDeviceId".into()).await; + + let timeline = TestTimelineBuilder::new() + .provider(TestRoomDataProvider::default().with_decryptor(TestDecryptor::new( + room_id!("!DovneieKSTkdHKpIXy:morpheus.localhost"), + &olm_machine, + ))) + .build(); + let mut stream = timeline.subscribe_events().await; let original_event_id = event_id!("$original"); @@ -883,20 +905,14 @@ async fn test_retry_decryption_updates_response() { } // Import a room key backup. - let own_user_id = user_id!("@example:morheus.localhost"); let exported_keys = decrypt_room_key_export(Cursor::new(SESSION_KEY), "1234").unwrap(); - let olm_machine = OlmMachine::new(own_user_id, "SomeDeviceId".into()).await; olm_machine.store().import_exported_room_keys(exported_keys, |_, _| {}).await.unwrap(); // Retry decrypting the UTD. timeline .controller - .retry_event_decryption_test( - room_id!("!DovneieKSTkdHKpIXy:morpheus.localhost"), - olm_machine, - Some(iter::once(SESSION_ID.to_owned()).collect()), - ) + .retry_event_decryption_test(Some(iter::once(SESSION_ID.to_owned()).collect())) .await; // The response is updated. diff --git a/crates/matrix-sdk-ui/src/timeline/tests/mod.rs b/crates/matrix-sdk-ui/src/timeline/tests/mod.rs index 23505e42912..eeba31223da 100644 --- a/crates/matrix-sdk-ui/src/timeline/tests/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/tests/mod.rs @@ -15,7 +15,7 @@ //! Unit tests (based on private methods) for the timeline API. use std::{ - collections::{BTreeMap, HashMap}, + collections::{BTreeMap, BTreeSet, HashMap}, ops::Sub, sync::Arc, time::{Duration, SystemTime}, @@ -29,7 +29,7 @@ use indexmap::IndexMap; use matrix_sdk::{ BoxFuture, config::RequestConfig, - crypto::OlmMachine, + crypto::{DecryptionSettings, OlmMachine, RoomEventDecryptionResult, TrustRequirement}, deserialized_responses::{EncryptionInfo, TimelineEvent}, paginators::{PaginableRoom, PaginatorError, thread::PaginableThread}, room::{EventWithContextResponse, Messages, MessagesOptions, PushContext, Relations}, @@ -41,9 +41,9 @@ use matrix_sdk_base::{ use matrix_sdk_test::{ALICE, DEFAULT_TEST_ROOM_ID, event_factory::EventFactory}; use ruma::{ EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedTransactionId, - OwnedUserId, TransactionId, UInt, UserId, assign, + OwnedUserId, RoomId, TransactionId, UInt, UserId, assign, events::{ - AnyMessageLikeEventContent, AnyTimelineEvent, + AnyMessageLikeEventContent, AnySyncTimelineEvent, AnyTimelineEvent, reaction::ReactionEventContent, receipt::{Receipt, ReceiptThread, ReceiptType}, relation::{Annotation, RelationType}, @@ -64,7 +64,8 @@ use super::{ event_item::RemoteEventOrigin, traits::RoomDataProvider, }; use crate::{ - timeline::pinned_events_loader::PinnedEventsRoom, unable_to_decrypt_hook::UtdHookManager, + timeline::{pinned_events_loader::PinnedEventsRoom, traits::Decryptor}, + unable_to_decrypt_hook::UtdHookManager, }; mod basic; @@ -142,7 +143,7 @@ impl TestTimelineBuilder { } struct TestTimeline { - controller: TimelineController, + controller: TimelineController, /// An [`EventFactory`] that can be used for creating events in this /// timeline. @@ -250,7 +251,7 @@ impl TestTimeline { type ReadReceiptMap = HashMap>>; -#[derive(Clone, Default)] +#[derive(Clone, Debug, Default)] struct TestRoomDataProvider { /// The initial list of user receipts for that room. /// @@ -271,6 +272,9 @@ struct TestRoomDataProvider { /// The [`EncryptionInfo`] describing the Megolm sessions that were used to /// encrypt events. pub encryption_info: HashMap>, + + /// If we are going to do event decryption, the decryptor that does it. + pub decryptor: Option, } impl TestRoomDataProvider { @@ -288,10 +292,15 @@ impl TestRoomDataProvider { mut self, session_id: &str, encryption_info: Arc, - ) -> TestRoomDataProvider { + ) -> Self { self.encryption_info.insert(session_id.to_owned(), encryption_info); self } + + fn with_decryptor(mut self, decryptor: TestDecryptor) -> Self { + self.decryptor = Some(decryptor); + self + } } impl PaginableRoom for TestRoomDataProvider { @@ -461,3 +470,66 @@ impl RoomDataProvider for TestRoomDataProvider { unimplemented!(); } } + +impl Decryptor for TestRoomDataProvider { + async fn decrypt_event_impl( + &self, + raw: &Raw, + push_ctx: Option<&PushContext>, + ) -> matrix_sdk::Result { + let Some(decryptor) = &self.decryptor else { + panic!( + "No TestDecryptor supplied! Use TestRoomDataProvider::with_decryptor to provide one." + ) + }; + + decryptor.decrypt_event_impl(raw, push_ctx).await + } +} + +#[derive(Clone, Debug)] +struct TestDecryptor { + room_id: OwnedRoomId, + olm_machine: OlmMachine, +} + +impl TestDecryptor { + fn new(room_id: &RoomId, olm_machine: &OlmMachine) -> Self { + Self { room_id: room_id.to_owned(), olm_machine: olm_machine.clone() } + } +} + +impl Decryptor for TestDecryptor { + async fn decrypt_event_impl( + &self, + raw: &Raw, + push_ctx: Option<&PushContext>, + ) -> matrix_sdk::Result { + let decryption_settings = + DecryptionSettings { sender_device_trust_requirement: TrustRequirement::Untrusted }; + + match self + .olm_machine + .try_decrypt_room_event(raw.cast_ref_unchecked(), &self.room_id, &decryption_settings) + .await? + { + RoomEventDecryptionResult::Decrypted(decrypted) => { + let push_actions = if let Some(push_ctx) = push_ctx { + Some(push_ctx.for_event(&decrypted.event).await) + } else { + None + }; + Ok(TimelineEvent::from_decrypted(decrypted, push_actions)) + } + RoomEventDecryptionResult::UnableToDecrypt(utd_info) => { + Ok(TimelineEvent::from_utd(raw.clone(), utd_info)) + } + } + } +} + +impl TimelineController

{ + pub(super) async fn retry_event_decryption_test(&self, session_ids: Option>) { + self.retry_event_decryption_inner(session_ids).await + } +} diff --git a/crates/matrix-sdk-ui/src/timeline/tests/read_receipts.rs b/crates/matrix-sdk-ui/src/timeline/tests/read_receipts.rs index 1ccced229a4..fe239ba1a77 100644 --- a/crates/matrix-sdk-ui/src/timeline/tests/read_receipts.rs +++ b/crates/matrix-sdk-ui/src/timeline/tests/read_receipts.rs @@ -32,8 +32,9 @@ use stream_assert::{assert_next_matches, assert_pending}; use super::{ReadReceiptMap, TestRoomDataProvider}; use crate::timeline::{ - MsgLikeContent, MsgLikeKind, TimelineFocus, controller::TimelineSettings, - tests::TestTimelineBuilder, + MsgLikeContent, MsgLikeKind, TimelineFocus, + controller::TimelineSettings, + tests::{TestDecryptor, TestTimelineBuilder}, }; fn filter_notice(ev: &AnySyncTimelineEvent, _rules: &RoomVersionRules) -> bool { @@ -412,12 +413,19 @@ async fn test_read_receipts_updates_on_message_decryption() { HztoSJUr/2Y\n\ -----END MEGOLM SESSION DATA-----"; + let own_user_id = user_id!("@example:morheus.localhost"); + let olm_machine = OlmMachine::new(own_user_id, "SomeDeviceId".into()).await; + let timeline = TestTimelineBuilder::new() .settings(TimelineSettings { track_read_receipts: true, event_filter: Arc::new(filter_text_msg), ..Default::default() }) + .provider(TestRoomDataProvider::default().with_decryptor(TestDecryptor::new( + room_id!("!DovneieKSTkdHKpIXy:morpheus.localhost"), + &olm_machine, + ))) .build(); let mut stream = timeline.subscribe().await; @@ -480,19 +488,13 @@ async fn test_read_receipts_updates_on_message_decryption() { assert!(encrypted_event.read_receipts().get(*BOB).is_some()); // Decrypt encrypted message. - let own_user_id = user_id!("@example:morheus.localhost"); let exported_keys = decrypt_room_key_export(Cursor::new(SESSION_KEY), "1234").unwrap(); - let olm_machine = OlmMachine::new(own_user_id, "SomeDeviceId".into()).await; olm_machine.store().import_exported_room_keys(exported_keys, |_, _| {}).await.unwrap(); timeline .controller - .retry_event_decryption_test( - room_id!("!DovneieKSTkdHKpIXy:morpheus.localhost"), - olm_machine, - Some(iter::once(SESSION_ID.to_owned()).collect()), - ) + .retry_event_decryption_test(Some(iter::once(SESSION_ID.to_owned()).collect())) .await; // The first event now has both receipts. diff --git a/crates/matrix-sdk-ui/src/timeline/traits.rs b/crates/matrix-sdk-ui/src/timeline/traits.rs index 3bb8be847d6..f40b9689928 100644 --- a/crates/matrix-sdk-ui/src/timeline/traits.rs +++ b/crates/matrix-sdk-ui/src/timeline/traits.rs @@ -16,8 +16,6 @@ use std::{future::Future, sync::Arc}; use eyeball::Subscriber; use indexmap::IndexMap; -#[cfg(test)] -use matrix_sdk::crypto::{DecryptionSettings, RoomEventDecryptionResult, TrustRequirement}; use matrix_sdk::{ AsyncTraitDeps, Result, Room, SendOutsideWasm, crypto::types::events::CryptoContextInfo, @@ -88,7 +86,7 @@ impl RoomExt for Room { } pub(super) trait RoomDataProvider: - Clone + PaginableRoom + PaginableThread + PinnedEventsRoom + 'static + Clone + Decryptor + PaginableRoom + PaginableThread + PinnedEventsRoom + 'static { fn own_user_id(&self) -> &UserId; fn room_version_rules(&self) -> RoomVersionRules; @@ -309,7 +307,7 @@ impl RoomDataProvider for Room { // Internal helper to make most of retry_event_decryption independent of a room // object, which is annoying to create for testing and not really needed -pub(super) trait Decryptor: AsyncTraitDeps + Clone + 'static { +pub(crate) trait Decryptor: AsyncTraitDeps + Clone + 'static { fn decrypt_event_impl( &self, raw: &Raw, @@ -326,33 +324,3 @@ impl Decryptor for Room { self.decrypt_event(raw.cast_ref_unchecked(), push_ctx).await } } - -#[cfg(test)] -impl Decryptor for (matrix_sdk_base::crypto::OlmMachine, ruma::OwnedRoomId) { - async fn decrypt_event_impl( - &self, - raw: &Raw, - push_ctx: Option<&PushContext>, - ) -> Result { - let (olm_machine, room_id) = self; - let decryption_settings = - DecryptionSettings { sender_device_trust_requirement: TrustRequirement::Untrusted }; - - match olm_machine - .try_decrypt_room_event(raw.cast_ref_unchecked(), room_id, &decryption_settings) - .await? - { - RoomEventDecryptionResult::Decrypted(decrypted) => { - let push_actions = if let Some(push_ctx) = push_ctx { - Some(push_ctx.for_event(&decrypted.event).await) - } else { - None - }; - Ok(TimelineEvent::from_decrypted(decrypted, push_actions)) - } - RoomEventDecryptionResult::UnableToDecrypt(utd_info) => { - Ok(TimelineEvent::from_utd(raw.clone(), utd_info)) - } - } - } -}