mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-07 15:33:45 -04:00
fix(base): Put timeline behind exprimental-timeline-feature-flag
This commit is contained in:
@@ -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"]
|
||||
|
||||
@@ -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?;
|
||||
|
||||
@@ -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<impl Stream<Item = SyncRoomEvent>> {
|
||||
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<impl Stream<Item = Result<SyncRoomEvent, TimelineStreamError>>> {
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -85,6 +85,7 @@ pub struct MemoryStore {
|
||||
>,
|
||||
media: Arc<Mutex<LruCache<String, Vec<u8>>>>,
|
||||
custom: Arc<DashMap<Vec<u8>, Vec<u8>>>,
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
room_timeline: Arc<DashMap<OwnedRoomId, TimelineData>>,
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<OwnedRoomId, Vec<Notification>>,
|
||||
/// A mapping of `RoomId` to a `TimelineSlice`
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
pub timeline: BTreeMap<OwnedRoomId, TimelineSlice>,
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user