diff --git a/crates/matrix-sdk-base/Cargo.toml b/crates/matrix-sdk-base/Cargo.toml index 9525b9a64..d12cad364 100644 --- a/crates/matrix-sdk-base/Cargo.toml +++ b/crates/matrix-sdk-base/Cargo.toml @@ -19,6 +19,7 @@ rustdoc-args = ["--cfg", "docsrs"] default = [] encryption = ["matrix-sdk-crypto"] qrcode = ["matrix-sdk-crypto/qrcode"] +experimental-timeline = [] # helpers for testing features build upon this testing = ["http"] diff --git a/crates/matrix-sdk-base/src/client.rs b/crates/matrix-sdk-base/src/client.rs index b1ad9743f..42af14b71 100644 --- a/crates/matrix-sdk-base/src/client.rs +++ b/crates/matrix-sdk-base/src/client.rs @@ -673,6 +673,7 @@ impl BaseClient { true, ); + #[cfg(feature = "experimental-timeline")] changes.add_timeline(&room_id, timeline_slice); new_rooms.join.insert( @@ -795,6 +796,7 @@ impl BaseClient { } } + #[cfg(feature = "experimental-timeline")] for (room_id, timeline_slice) in &changes.timeline { if let Some(room) = self.store.get_room(room_id) { room.add_timeline_slice(timeline_slice).await; @@ -810,6 +812,7 @@ impl BaseClient { pub async fn receive_messages(&self, room_id: &RoomId, timeline: TimelineSlice) -> Result<()> { let mut changes = StateChanges::default(); + #[cfg(feature = "experimental-timeline")] changes.add_timeline(room_id, timeline); self.store().save_changes(&changes).await?; diff --git a/crates/matrix-sdk-base/src/rooms/normal.rs b/crates/matrix-sdk-base/src/rooms/normal.rs index 53a5cee5f..8a452c3f6 100644 --- a/crates/matrix-sdk-base/src/rooms/normal.rs +++ b/crates/matrix-sdk-base/src/rooms/normal.rs @@ -484,6 +484,7 @@ impl Room { /// Get two stream into the timeline. /// First one is forward in time and the second one is backward in time. + #[cfg(feature = "experimental-timeline")] pub async fn timeline( &self, ) -> StoreResult<( @@ -522,6 +523,7 @@ impl Room { /// /// If you need also a backward stream you should use /// [`timeline`][`crate::Room::timeline`] + #[cfg(feature = "experimental-timeline")] pub async fn timeline_forward(&self) -> StoreResult> { let mut forward_timeline_streams = self.forward_timeline_streams.lock().await; let event_ids = Arc::new(DashSet::new()); @@ -537,6 +539,7 @@ impl Room { /// /// If you need also a forward stream you should use /// [`timeline`][`crate::Room::timeline`] + #[cfg(feature = "experimental-timeline")] pub async fn timeline_backward( &self, ) -> StoreResult>> { @@ -558,6 +561,7 @@ impl Room { } /// Add a new timeline slice to the timeline streams. + #[cfg(feature = "experimental-timeline")] pub async fn add_timeline_slice(&self, timeline: &TimelineSlice) { if timeline.sync { let mut streams = self.forward_timeline_streams.lock().await; diff --git a/crates/matrix-sdk-base/src/store/integration_tests.rs b/crates/matrix-sdk-base/src/store/integration_tests.rs index c873f8643..bdf4f7244 100644 --- a/crates/matrix-sdk-base/src/store/integration_tests.rs +++ b/crates/matrix-sdk-base/src/store/integration_tests.rs @@ -572,6 +572,7 @@ macro_rules! statestore_integration_tests { } #[async_test] + #[cfg(feature = "experimental-timeline")] async fn test_room_timeline() { let store = get_store().await.unwrap(); let mut stored_events = Vec::new(); @@ -699,6 +700,7 @@ macro_rules! statestore_integration_tests { check_timeline_events(room_id, &store, &Vec::new(), end_token.as_deref()).await; } + #[cfg(feature = "experimental-timeline")] async fn check_timeline_events( room_id: &RoomId, store: &dyn StateStore, diff --git a/crates/matrix-sdk-base/src/store/memory_store.rs b/crates/matrix-sdk-base/src/store/memory_store.rs index ca06b3e1d..27522c38e 100644 --- a/crates/matrix-sdk-base/src/store/memory_store.rs +++ b/crates/matrix-sdk-base/src/store/memory_store.rs @@ -85,6 +85,7 @@ pub struct MemoryStore { >, media: Arc>>>, custom: Arc, Vec>>, + #[cfg(feature = "experimental-timeline")] room_timeline: Arc>, } @@ -118,6 +119,7 @@ impl MemoryStore { room_event_receipts: Default::default(), media: Arc::new(Mutex::new(LruCache::new(100))), custom: DashMap::new().into(), + #[cfg(feature = "experimental-timeline")] room_timeline: Default::default(), } } @@ -300,6 +302,7 @@ impl MemoryStore { } } + #[cfg(feature = "experimental-timeline")] for (room, timeline) in &changes.timeline { if timeline.sync { info!("Save new timeline batch from sync response for {}", room); @@ -588,11 +591,14 @@ impl MemoryStore { self.stripped_members.remove(room_id); self.room_user_receipts.remove(room_id); self.room_event_receipts.remove(room_id); + + #[cfg(feature = "experimental-timeline")] self.room_timeline.remove(room_id); Ok(()) } + #[cfg(feature = "experimental-timeline")] async fn room_timeline( &self, room_id: &RoomId, @@ -765,6 +771,7 @@ impl StateStore for MemoryStore { self.remove_room(room_id).await } + #[cfg(feature = "experimental-timeline")] async fn room_timeline( &self, room_id: &RoomId, diff --git a/crates/matrix-sdk-base/src/store/mod.rs b/crates/matrix-sdk-base/src/store/mod.rs index e2f6fce90..1e712f239 100644 --- a/crates/matrix-sdk-base/src/store/mod.rs +++ b/crates/matrix-sdk-base/src/store/mod.rs @@ -344,6 +344,7 @@ pub trait StateStore: AsyncTraitDeps { /// /// Returns a stream of events and a token that can be used to request /// previous events. + #[cfg(feature = "experimental-timeline")] async fn room_timeline( &self, room_id: &RoomId, @@ -520,6 +521,7 @@ pub struct StateChanges { /// A map of `RoomId` to a vector of `Notification`s pub notifications: BTreeMap>, /// A mapping of `RoomId` to a `TimelineSlice` + #[cfg(feature = "experimental-timeline")] pub timeline: BTreeMap, } @@ -605,6 +607,7 @@ impl StateChanges { /// Update the `StateChanges` struct with the given room with a new /// `TimelineSlice`. + #[cfg(feature = "experimental-timeline")] pub fn add_timeline(&mut self, room_id: &RoomId, timeline: TimelineSlice) { self.timeline.insert(room_id.to_owned(), timeline); }