Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License

use std::sync::Arc;
use std::{rc::Rc, sync::Arc};

use matrix_sdk_base::event_cache::store::MemoryStore;
use matrix_sdk_base::event_cache::store::{media::MediaService, MemoryStore};
use matrix_sdk_store_encryption::StoreCipher;
use web_sys::DomException;

Expand Down Expand Up @@ -66,10 +66,11 @@ impl IndexeddbEventCacheStoreBuilder {
/// and the provided store cipher.
pub async fn build(self) -> Result<IndexeddbEventCacheStore, IndexeddbEventCacheStoreError> {
Ok(IndexeddbEventCacheStore {
inner: open_and_upgrade_db(&self.database_name).await?,
inner: Rc::new(open_and_upgrade_db(&self.database_name).await?),
serializer: IndexeddbEventCacheStoreSerializer::new(IndexeddbSerializer::new(
self.store_cipher,
)),
media_service: MediaService::new(),
memory_store: MemoryStore::new(),
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,3 +684,30 @@ macro_rules! indexeddb_event_cache_store_integration_tests {
}
};
}

/// This is a partial copy of
/// [`matrix_sdk_base::event_cache_store_media_integration_tests`] that contains
/// tests for functions of [`EventCacheStoreMedia`] that are implemented by
/// [`IndexeddbEventCacheStore`].
///
/// This is useful for adding functionality to [`IndexeddbEventCacheStore`] over
/// multiple pull requests. Once a full implementation [`EventCacheStoreMedia`]
/// exists, this will be replaced with the actual integration tests referenced
/// above.
#[macro_export]
macro_rules! event_cache_store_media_integration_tests {
() => {
mod event_cache_store_media_integration_tests {
use matrix_sdk_base::event_cache::store::media::EventCacheStoreMediaIntegrationTests;
use matrix_sdk_test::async_test;

use super::get_event_cache_store;

#[async_test]
async fn test_store_media_retention_policy() {
let event_cache_store_media = get_event_cache_store().await.unwrap();
event_cache_store_media.test_store_media_retention_policy().await;
}
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ pub mod v1 {

pub mod keys {
pub const CORE: &str = "core";
pub const CORE_KEY_PATH: &str = "id";
pub const LEASES: &str = "leases";
pub const LEASES_KEY_PATH: &str = "id";
pub const ROOMS: &str = "rooms";
Expand All @@ -129,6 +130,7 @@ pub mod v1 {
pub const EVENTS_RELATION_RELATION_TYPES: &str = "events_relation_relation_type";
pub const GAPS: &str = "gaps";
pub const GAPS_KEY_PATH: &str = "id";
pub const MEDIA_RETENTION_POLICY_KEY: &str = "media_retention_policy";
}

/// Create all object stores and indices for v1 database
Expand All @@ -142,8 +144,12 @@ pub mod v1 {
}

/// Create an object store for tracking miscellaneous information
///
/// * Primary Key - `id`
fn create_core_object_store(db: &IdbDatabase) -> Result<(), DomException> {
let _ = db.create_object_store(keys::CORE)?;
let mut object_store_params = IdbObjectStoreParameters::new();
object_store_params.key_path(Some(&keys::CORE_KEY_PATH.into()));
let _ = db.create_object_store_with_params(keys::CORE, &object_store_params)?;
Ok(())
}

Expand Down
Loading
Loading