diff --git a/crates/matrix-sdk-indexeddb/src/media_store/builder.rs b/crates/matrix-sdk-indexeddb/src/media_store/builder.rs index eb3317bda..d91390c53 100644 --- a/crates/matrix-sdk-indexeddb/src/media_store/builder.rs +++ b/crates/matrix-sdk-indexeddb/src/media_store/builder.rs @@ -20,7 +20,7 @@ use matrix_sdk_store_encryption::StoreCipher; use crate::{ media_store::{ error::IndexeddbMediaStoreError, migrations::open_and_upgrade_db, - serializer::IndexeddbMediaStoreSerializer, IndexeddbMediaStore, + serializer::IndexedTypeSerializer, IndexeddbMediaStore, }, serializer::SafeEncodeSerializer, }; @@ -66,9 +66,7 @@ impl IndexeddbMediaStoreBuilder { pub async fn build(self) -> Result { Ok(IndexeddbMediaStore { inner: Rc::new(open_and_upgrade_db(&self.database_name).await?), - serializer: IndexeddbMediaStoreSerializer::new(SafeEncodeSerializer::new( - self.store_cipher, - )), + serializer: IndexedTypeSerializer::new(SafeEncodeSerializer::new(self.store_cipher)), media_service: MediaService::new(), memory_store: MemoryMediaStore::new(), }) diff --git a/crates/matrix-sdk-indexeddb/src/media_store/mod.rs b/crates/matrix-sdk-indexeddb/src/media_store/mod.rs index d87955311..f44920ec3 100644 --- a/crates/matrix-sdk-indexeddb/src/media_store/mod.rs +++ b/crates/matrix-sdk-indexeddb/src/media_store/mod.rs @@ -36,7 +36,7 @@ use matrix_sdk_base::{ timer, }; use ruma::{time::SystemTime, MilliSecondsSinceUnixEpoch, MxcUri}; -use serializer::IndexeddbMediaStoreSerializer; +use serializer::IndexedTypeSerializer; use tracing::instrument; use web_sys::IdbTransactionMode; @@ -54,7 +54,7 @@ pub struct IndexeddbMediaStore { // A handle to the IndexedDB database inner: Rc, // A serializer with functionality tailored to `IndexeddbMediaStore` - serializer: IndexeddbMediaStoreSerializer, + serializer: IndexedTypeSerializer, // A service for conveniently delegating media-related queries to an `MediaStoreInner` // implementation media_service: MediaService, diff --git a/crates/matrix-sdk-indexeddb/src/media_store/serializer/mod.rs b/crates/matrix-sdk-indexeddb/src/media_store/serializer/mod.rs index 9503c09eb..31ccfd1d2 100644 --- a/crates/matrix-sdk-indexeddb/src/media_store/serializer/mod.rs +++ b/crates/matrix-sdk-indexeddb/src/media_store/serializer/mod.rs @@ -31,14 +31,14 @@ pub mod traits; pub mod types; #[derive(Debug, Error)] -pub enum IndexeddbMediaStoreSerializerError { +pub enum IndexedTypeSerializerError { #[error("indexing: {0}")] Indexing(IndexingError), #[error("serialization: {0}")] Serialization(#[from] serde_json::Error), } -impl From for IndexeddbMediaStoreSerializerError { +impl From for IndexedTypeSerializerError { fn from(e: serde_wasm_bindgen::Error) -> Self { Self::Serialization(serde::de::Error::custom(e.to_string())) } @@ -52,11 +52,11 @@ impl From for IndexeddbMediaStoreSerializerError Self { Self { inner } } @@ -140,29 +140,22 @@ impl IndexeddbMediaStoreSerializer { } /// Serializes an [`Indexed`] type into a [`JsValue`] - pub fn serialize( - &self, - t: &T, - ) -> Result> + pub fn serialize(&self, t: &T) -> Result> where T: Indexed, T::IndexedType: Serialize, { - let indexed = - t.to_indexed(&self.inner).map_err(IndexeddbMediaStoreSerializerError::Indexing)?; + let indexed = t.to_indexed(&self.inner).map_err(IndexedTypeSerializerError::Indexing)?; serde_wasm_bindgen::to_value(&indexed).map_err(Into::into) } /// Deserializes an [`Indexed`] type from a [`JsValue`] - pub fn deserialize( - &self, - value: JsValue, - ) -> Result> + pub fn deserialize(&self, value: JsValue) -> Result> where T: Indexed, T::IndexedType: DeserializeOwned, { let indexed: T::IndexedType = value.into_serde()?; - T::from_indexed(indexed, &self.inner).map_err(IndexeddbMediaStoreSerializerError::Indexing) + T::from_indexed(indexed, &self.inner).map_err(IndexedTypeSerializerError::Indexing) } } diff --git a/crates/matrix-sdk-indexeddb/src/media_store/transaction.rs b/crates/matrix-sdk-indexeddb/src/media_store/transaction.rs index e4891ba68..5fa9664bc 100644 --- a/crates/matrix-sdk-indexeddb/src/media_store/transaction.rs +++ b/crates/matrix-sdk-indexeddb/src/media_store/transaction.rs @@ -26,7 +26,7 @@ use crate::media_store::{ serializer::{ traits::{Indexed, IndexedKey}, types::{IndexedCoreIdKey, IndexedKeyRange, IndexedLeaseIdKey}, - IndexeddbMediaStoreSerializer, + IndexedTypeSerializer, }, types::Lease, }; @@ -72,14 +72,11 @@ impl From for MediaStoreError { /// [`MediaStore`](matrix_sdk_base::media::store::MediaStore). pub struct IndexeddbMediaStoreTransaction<'a> { transaction: IdbTransaction<'a>, - serializer: &'a IndexeddbMediaStoreSerializer, + serializer: &'a IndexedTypeSerializer, } impl<'a> IndexeddbMediaStoreTransaction<'a> { - pub fn new( - transaction: IdbTransaction<'a>, - serializer: &'a IndexeddbMediaStoreSerializer, - ) -> Self { + pub fn new(transaction: IdbTransaction<'a>, serializer: &'a IndexedTypeSerializer) -> Self { Self { transaction, serializer } }