Skip to content

Commit

Permalink
Hacky Hack McHackFace
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjbvr committed Nov 25, 2024
1 parent a43569c commit 9a452bd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
46 changes: 44 additions & 2 deletions crates/matrix-sdk/src/event_cache/room/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -47,7 +50,33 @@ impl RoomEvents {
store: EventCacheStoreLock,
) -> Result<Self, EventCacheError> {
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 })
}

Expand All @@ -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(())
}

Expand Down
8 changes: 5 additions & 3 deletions crates/matrix-sdk/src/event_cache/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand All @@ -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(())
}
Expand Down

0 comments on commit 9a452bd

Please sign in to comment.