Skip to content

Commit 841131f

Browse files
mgoldenbergHywan
authored andcommitted
refactor(indexeddb): add indexing trait impls for gap
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
1 parent a22d592 commit 841131f

File tree

1 file changed

+50
-1
lines changed
  • crates/matrix-sdk-indexeddb/src/event_cache_store/serializer

1 file changed

+50
-1
lines changed

crates/matrix-sdk-indexeddb/src/event_cache_store/serializer/types.rs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::{
3737
event_cache_store::{
3838
migrations::current::keys,
3939
serializer::traits::{Indexed, IndexedKey, IndexedKeyBounds},
40-
types::{Chunk, Event, Position},
40+
types::{Chunk, Event, Gap, Position},
4141
},
4242
serializer::{IndexeddbSerializer, MaybeEncrypted},
4343
};
@@ -405,6 +405,33 @@ pub struct IndexedGap {
405405
pub content: IndexedGapContent,
406406
}
407407

408+
impl Indexed for Gap {
409+
type IndexedType = IndexedGap;
410+
type Error = CryptoStoreError;
411+
412+
fn to_indexed(
413+
&self,
414+
room_id: &RoomId,
415+
serializer: &IndexeddbSerializer,
416+
) -> Result<Self::IndexedType, Self::Error> {
417+
Ok(IndexedGap {
418+
id: <IndexedGapIdKey as IndexedKey<Gap>>::encode(
419+
room_id,
420+
&ChunkIdentifier::new(self.chunk_identifier),
421+
serializer,
422+
),
423+
content: serializer.maybe_encrypt_value(self)?,
424+
})
425+
}
426+
427+
fn from_indexed(
428+
indexed: Self::IndexedType,
429+
serializer: &IndexeddbSerializer,
430+
) -> Result<Self, Self::Error> {
431+
serializer.maybe_decrypt_value(indexed.content)
432+
}
433+
}
434+
408435
/// The primary key of the [`GAPS`][1] object store, which is constructed from:
409436
///
410437
/// - The (possibly) encrypted Room ID
@@ -413,4 +440,26 @@ pub struct IndexedGap {
413440
/// [1]: crate::event_cache_store::migrations::v1::create_gaps_object_store
414441
pub type IndexedGapIdKey = IndexedChunkIdKey;
415442

443+
impl IndexedKey<Gap> for IndexedGapIdKey {
444+
type KeyComponents = <IndexedChunkIdKey as IndexedKey<Chunk>>::KeyComponents;
445+
446+
fn encode(
447+
room_id: &RoomId,
448+
components: &Self::KeyComponents,
449+
serializer: &IndexeddbSerializer,
450+
) -> Self {
451+
<IndexedChunkIdKey as IndexedKey<Chunk>>::encode(room_id, components, serializer)
452+
}
453+
}
454+
455+
impl IndexedKeyBounds<Gap> for IndexedGapIdKey {
456+
fn encode_lower(room_id: &RoomId, serializer: &IndexeddbSerializer) -> Self {
457+
<IndexedChunkIdKey as IndexedKeyBounds<Chunk>>::encode_lower(room_id, serializer)
458+
}
459+
460+
fn encode_upper(room_id: &RoomId, serializer: &IndexeddbSerializer) -> Self {
461+
<IndexedChunkIdKey as IndexedKeyBounds<Chunk>>::encode_upper(room_id, serializer)
462+
}
463+
}
464+
416465
pub type IndexedGapContent = MaybeEncrypted;

0 commit comments

Comments
 (0)