From 90ce6e85ada9962b03fe36eeab662d49adea554e Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 4 Apr 2025 17:47:34 +0200 Subject: [PATCH] refactor(base): Centralise processors that require `e2e-encryption`. --- crates/matrix-sdk-base/src/client.rs | 11 ++++++++--- .../matrix-sdk-base/src/response_processors/e2ee.rs | 2 -- .../src/response_processors/latest_event.rs | 2 -- .../matrix-sdk-base/src/response_processors/mod.rs | 12 +++++++++--- crates/matrix-sdk-base/src/sliding_sync.rs | 4 ++-- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/crates/matrix-sdk-base/src/client.rs b/crates/matrix-sdk-base/src/client.rs index 7d1fefca5..90da0d21c 100644 --- a/crates/matrix-sdk-base/src/client.rs +++ b/crates/matrix-sdk-base/src/client.rs @@ -62,13 +62,11 @@ use tokio::sync::{broadcast, Mutex}; use tokio::sync::{RwLock, RwLockReadGuard}; use tracing::{debug, error, info, instrument, trace, warn}; -#[cfg(feature = "e2e-encryption")] -use crate::RoomMemberships; use crate::{ deserialized_responses::{DisplayName, RawAnySyncOrStrippedTimelineEvent, TimelineEvent}, error::{Error, Result}, event_cache::store::EventCacheStoreLock, - response_processors::{self as processors, account_data::AccountDataProcessor, Context}, + response_processors::{account_data::AccountDataProcessor, Context}, rooms::{ normal::{RoomInfoNotableUpdate, RoomInfoNotableUpdateReasons, RoomMembersUpdate}, Room, RoomInfo, RoomState, @@ -81,6 +79,11 @@ use crate::{ sync::{JoinedRoomUpdate, LeftRoomUpdate, Notification, RoomUpdates, SyncResponse, Timeline}, RoomStateFilter, SessionMeta, }; +#[cfg(feature = "e2e-encryption")] +use crate::{ + response_processors::{self as processors}, + RoomMemberships, +}; /// A no (network) IO client implementation. /// @@ -466,6 +469,7 @@ impl BaseClient { ambiguity_cache: &mut AmbiguityCache, ) -> Result { // TODO: should receive `context` from an argument. + #[allow(unused)] let mut context = Context::new(StateChanges::default(), Default::default()); let mut timeline = Timeline::new(limited, prev_batch); let mut push_context = self.get_push_room_context(room, room_info, changes).await?; @@ -938,6 +942,7 @@ impl BaseClient { #[cfg(feature = "e2e-encryption")] let olm_machine = self.olm_machine().await; + #[allow(unused_mut)] let mut context = Context::new(StateChanges::new(response.next_batch.clone()), Default::default()); diff --git a/crates/matrix-sdk-base/src/response_processors/e2ee.rs b/crates/matrix-sdk-base/src/response_processors/e2ee.rs index c50d16054..875e7fbe2 100644 --- a/crates/matrix-sdk-base/src/response_processors/e2ee.rs +++ b/crates/matrix-sdk-base/src/response_processors/e2ee.rs @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#![cfg(feature = "e2e-encryption")] - use std::collections::BTreeMap; use matrix_sdk_crypto::{store::RoomKeyInfo, EncryptionSyncChanges, OlmMachine}; diff --git a/crates/matrix-sdk-base/src/response_processors/latest_event.rs b/crates/matrix-sdk-base/src/response_processors/latest_event.rs index e68f67e23..f13edc3da 100644 --- a/crates/matrix-sdk-base/src/response_processors/latest_event.rs +++ b/crates/matrix-sdk-base/src/response_processors/latest_event.rs @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#![cfg(feature = "e2e-encryption")] - use matrix_sdk_common::deserialized_responses::TimelineEvent; use matrix_sdk_crypto::{ DecryptionSettings, OlmMachine, RoomEventDecryptionResult, TrustRequirement, diff --git a/crates/matrix-sdk-base/src/response_processors/mod.rs b/crates/matrix-sdk-base/src/response_processors/mod.rs index 06c0aab8b..6887fd77f 100644 --- a/crates/matrix-sdk-base/src/response_processors/mod.rs +++ b/crates/matrix-sdk-base/src/response_processors/mod.rs @@ -13,16 +13,22 @@ // limitations under the License. pub mod account_data; +#[cfg(feature = "e2e-encryption")] pub mod e2ee; +#[cfg(feature = "e2e-encryption")] pub mod latest_event; +#[cfg(feature = "e2e-encryption")] pub mod verification; use std::collections::BTreeMap; -pub use e2ee::e2ee; -pub use latest_event::decrypt_latest_events; +#[cfg(feature = "e2e-encryption")] +mod with_e2ee { + pub use super::{e2ee::e2ee, latest_event::decrypt_latest_events, verification::verification}; +} use ruma::OwnedRoomId; -pub use verification::verification; +#[cfg(feature = "e2e-encryption")] +pub use with_e2ee::*; use crate::{RoomInfoNotableUpdateReasons, StateChanges}; diff --git a/crates/matrix-sdk-base/src/sliding_sync.rs b/crates/matrix-sdk-base/src/sliding_sync.rs index 3b7a7c711..2cd7487d1 100644 --- a/crates/matrix-sdk-base/src/sliding_sync.rs +++ b/crates/matrix-sdk-base/src/sliding_sync.rs @@ -40,7 +40,7 @@ use super::BaseClient; use crate::{ error::Result, read_receipts::{compute_unread_counts, PreviousEventsProvider}, - response_processors::{self as processors, account_data::AccountDataProcessor}, + response_processors::account_data::AccountDataProcessor, rooms::{ normal::{RoomHero, RoomInfoNotableUpdateReasons}, RoomState, @@ -53,7 +53,7 @@ use crate::{ #[cfg(feature = "e2e-encryption")] use crate::{ latest_event::{is_suitable_for_latest_event, LatestEvent, PossibleLatestEvent}, - RoomMemberships, + response_processors as processors, RoomMemberships, }; impl BaseClient {