diff --git a/Cargo.lock b/Cargo.lock index be3ee36dc0b..82b50241897 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2983,9 +2983,11 @@ version = "0.7.0" dependencies = [ "assert_matches", "async-trait", + "eyeball-im", "futures-core", "futures-util", "gloo-timers", + "imbl", "js-sys", "matrix-sdk-test", "proptest", diff --git a/crates/matrix-sdk-base/src/event_cache/mod.rs b/crates/matrix-sdk-base/src/event_cache/mod.rs index 355d613dd0e..70bd71760a6 100644 --- a/crates/matrix-sdk-base/src/event_cache/mod.rs +++ b/crates/matrix-sdk-base/src/event_cache/mod.rs @@ -12,4 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. +//! Event cache store and common types shared with `matrix_sdk::event_cache`. + pub mod store; diff --git a/crates/matrix-sdk-common/Cargo.toml b/crates/matrix-sdk-common/Cargo.toml index 87d52a1f3fe..e5e0995c083 100644 --- a/crates/matrix-sdk-common/Cargo.toml +++ b/crates/matrix-sdk-common/Cargo.toml @@ -21,7 +21,10 @@ uniffi = ["dep:uniffi"] [dependencies] async-trait = { workspace = true } +eyeball-im = { workspace = true } futures-core = { workspace = true } +futures-util = { workspace = true } +imbl = { workspace = true } ruma = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } diff --git a/crates/matrix-sdk-common/src/lib.rs b/crates/matrix-sdk-common/src/lib.rs index 451a86fa16c..29c6709ec3d 100644 --- a/crates/matrix-sdk-common/src/lib.rs +++ b/crates/matrix-sdk-common/src/lib.rs @@ -25,6 +25,7 @@ pub mod debug; pub mod deserialized_responses; pub mod executor; pub mod failures_cache; +pub mod linked_chunk; pub mod ring_buffer; pub mod store_locks; pub mod timeout; diff --git a/crates/matrix-sdk/src/event_cache/linked_chunk/as_vector.rs b/crates/matrix-sdk-common/src/linked_chunk/as_vector.rs similarity index 100% rename from crates/matrix-sdk/src/event_cache/linked_chunk/as_vector.rs rename to crates/matrix-sdk-common/src/linked_chunk/as_vector.rs diff --git a/crates/matrix-sdk/src/event_cache/linked_chunk/mod.rs b/crates/matrix-sdk-common/src/linked_chunk/mod.rs similarity index 99% rename from crates/matrix-sdk/src/event_cache/linked_chunk/mod.rs rename to crates/matrix-sdk-common/src/linked_chunk/mod.rs index c3c69a77719..63d8599ddeb 100644 --- a/crates/matrix-sdk/src/event_cache/linked_chunk/mod.rs +++ b/crates/matrix-sdk-common/src/linked_chunk/mod.rs @@ -56,7 +56,7 @@ macro_rules! assert_items_eq { let chunk = $iterator .next().expect("next chunk (expect items)"); assert!(chunk.is_items(), "chunk should contain items"); - let $crate::event_cache::linked_chunk::ChunkContent::Items(items) = chunk.content() else { + let $crate::linked_chunk::ChunkContent::Items(items) = chunk.content() else { unreachable!() }; @@ -934,7 +934,6 @@ impl ChunkIdentifierGenerator { #[repr(transparent)] pub struct ChunkIdentifier(u64); -#[cfg(test)] impl PartialEq for ChunkIdentifier { fn eq(&self, other: &u64) -> bool { self.0 == *other @@ -963,7 +962,7 @@ impl Position { /// # Panic /// /// This method will panic if it will underflow, i.e. if the index is 0. - pub(super) fn decrement_index(&mut self) { + pub fn decrement_index(&mut self) { self.1 = self.1.checked_sub(1).expect("Cannot decrement the index because it's already 0"); } } @@ -1346,7 +1345,8 @@ where } /// A type representing what to do when the system has to handle an empty chunk. -pub(crate) enum EmptyChunk { +#[derive(Debug)] +pub enum EmptyChunk { /// Keep the empty chunk. Keep, diff --git a/crates/matrix-sdk/src/event_cache/linked_chunk/updates.rs b/crates/matrix-sdk-common/src/linked_chunk/updates.rs similarity index 100% rename from crates/matrix-sdk/src/event_cache/linked_chunk/updates.rs rename to crates/matrix-sdk-common/src/linked_chunk/updates.rs diff --git a/crates/matrix-sdk/src/event_cache/mod.rs b/crates/matrix-sdk/src/event_cache/mod.rs index 7aa31485386..8f0c2f19212 100644 --- a/crates/matrix-sdk/src/event_cache/mod.rs +++ b/crates/matrix-sdk/src/event_cache/mod.rs @@ -54,7 +54,6 @@ use self::paginator::PaginatorError; use crate::{client::WeakClient, Client}; mod deduplicator; -mod linked_chunk; mod pagination; mod room; diff --git a/crates/matrix-sdk/src/event_cache/pagination.rs b/crates/matrix-sdk/src/event_cache/pagination.rs index 7eb5d62a84e..c5b605ab6e0 100644 --- a/crates/matrix-sdk/src/event_cache/pagination.rs +++ b/crates/matrix-sdk/src/event_cache/pagination.rs @@ -18,11 +18,11 @@ use std::{future::Future, ops::ControlFlow, sync::Arc, time::Duration}; use eyeball::Subscriber; use matrix_sdk_base::deserialized_responses::SyncTimelineEvent; +use matrix_sdk_common::linked_chunk::ChunkContent; use tokio::time::timeout; use tracing::{debug, instrument, trace}; use super::{ - linked_chunk::ChunkContent, paginator::{PaginationResult, PaginatorState}, room::{ events::{Gap, RoomEvents}, diff --git a/crates/matrix-sdk/src/event_cache/room/events.rs b/crates/matrix-sdk/src/event_cache/room/events.rs index 0f714e9498b..90d998923ed 100644 --- a/crates/matrix-sdk/src/event_cache/room/events.rs +++ b/crates/matrix-sdk/src/event_cache/room/events.rs @@ -15,13 +15,13 @@ use std::cmp::Ordering; use matrix_sdk_common::deserialized_responses::SyncTimelineEvent; +use matrix_sdk_common::linked_chunk::{ + Chunk, ChunkIdentifier, EmptyChunk, Error, Iter, LinkedChunk, Position, +}; use ruma::OwnedEventId; use tracing::{debug, error, warn}; -use super::super::{ - deduplicator::{Decoration, Deduplicator}, - linked_chunk::{Chunk, ChunkIdentifier, EmptyChunk, Error, Iter, LinkedChunk, Position}, -}; +use super::super::deduplicator::{Decoration, Deduplicator}; /// An alias for the real event type. pub(crate) type Event = SyncTimelineEvent;