diff --git a/crates/matrix-sdk/src/event_cache/room/events.rs b/crates/matrix-sdk/src/event_cache/room/events.rs index 018b41b6e0e..087d3bb2fe5 100644 --- a/crates/matrix-sdk/src/event_cache/room/events.rs +++ b/crates/matrix-sdk/src/event_cache/room/events.rs @@ -14,8 +14,11 @@ use std::cmp::Ordering; -use matrix_sdk_base::event_cache::store::{EventCacheStoreLock, DEFAULT_CHUNK_CAPACITY}; pub use matrix_sdk_base::event_cache::{Event, Gap}; +use matrix_sdk_base::{ + event_cache::store::{EventCacheStoreLock, DEFAULT_CHUNK_CAPACITY}, + linked_chunk::Update, +}; use matrix_sdk_common::linked_chunk::{ Chunk, ChunkIdentifier, EmptyChunk, Iter, LinkedChunk, Position, }; @@ -47,7 +50,33 @@ impl RoomEvents { store: EventCacheStoreLock, ) -> Result { let locked_store = store.lock().await?; - let chunks = locked_store.reload_linked_chunk(&room).await?; + + let chunks = if let Some(chunks) = locked_store.reload_linked_chunk(&room).await? { + // We could reload the chunks: use them. + + // TODO: we must report changes to observers, one way or another! + chunks + } else { + // Create a new empty linked chunks, and let the store know about its first + // empty chunk. + let chunks = LinkedChunk::new_with_update_history(); + + // TODO(bnjbvr): discuss this with Ivan + locked_store + .handle_linked_chunk_updates( + &room, + &[Update::NewItemsChunk { + previous: None, + // This is breaking API boundaries + new: ChunkIdentifier::from_raw(0), + next: None, + }], + ) + .await?; + + chunks + }; + Ok(Self { chunks, deduplicator: Deduplicator::new(), room, store }) } @@ -73,6 +102,19 @@ impl RoomEvents { let store = self.store.lock().await?; store.reset_linked_chunk(&self.room).await?; + // TODO(bnjbvr): discuss this with Ivan + store + .handle_linked_chunk_updates( + &self.room, + &[Update::NewItemsChunk { + previous: None, + // This is breaking API boundaries + new: ChunkIdentifier::from_raw(0), + next: None, + }], + ) + .await?; + Ok(()) } diff --git a/crates/matrix-sdk/src/event_cache/room/mod.rs b/crates/matrix-sdk/src/event_cache/room/mod.rs index 55599eacb1a..eb550ae2575 100644 --- a/crates/matrix-sdk/src/event_cache/room/mod.rs +++ b/crates/matrix-sdk/src/event_cache/room/mod.rs @@ -240,6 +240,7 @@ impl RoomEventCacheInner { let event_cache_store = client.get().expect("TODO replace with error handling?").event_cache_store().clone(); + let weak_room = WeakRoom::new(client, room_id.clone()); Ok(Self { @@ -359,10 +360,11 @@ impl RoomEventCacheInner { let mut state = self.state.write().await; // Reset the room's state. - state.reset().await?; + // TODO(bnjbvr) + //state.reset().await?; // Propagate to observers. - let _ = self.sender.send(RoomEventCacheUpdate::Clear); + //let _ = self.sender.send(RoomEventCacheUpdate::Clear); // Push the new events. self.append_events_locked_impl( @@ -375,7 +377,7 @@ impl RoomEventCacheInner { .await?; // Reset the paginator status to initial. - self.paginator.set_idle_state(PaginatorState::Initial, prev_batch, None)?; + //self.paginator.set_idle_state(PaginatorState::Initial, prev_batch, None)?; Ok(()) }