@@ -37,7 +37,7 @@ use crate::{
37
37
event_cache_store:: {
38
38
migrations:: current:: keys,
39
39
serializer:: traits:: { Indexed , IndexedKey , IndexedKeyBounds } ,
40
- types:: { Chunk , Event , Position } ,
40
+ types:: { Chunk , Event , Gap , Position } ,
41
41
} ,
42
42
serializer:: { IndexeddbSerializer , MaybeEncrypted } ,
43
43
} ;
@@ -405,6 +405,33 @@ pub struct IndexedGap {
405
405
pub content : IndexedGapContent ,
406
406
}
407
407
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
+
408
435
/// The primary key of the [`GAPS`][1] object store, which is constructed from:
409
436
///
410
437
/// - The (possibly) encrypted Room ID
@@ -413,4 +440,26 @@ pub struct IndexedGap {
413
440
/// [1]: crate::event_cache_store::migrations::v1::create_gaps_object_store
414
441
pub type IndexedGapIdKey = IndexedChunkIdKey ;
415
442
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
+
416
465
pub type IndexedGapContent = MaybeEncrypted ;
0 commit comments