@@ -35,7 +35,10 @@ use matrix_sdk_base::{
35
35
media:: { MediaRequestParameters , UniqueKey } ,
36
36
} ;
37
37
use matrix_sdk_crypto:: CryptoStoreError ;
38
- use ruma:: { events:: relation:: RelationType , EventId , OwnedEventId , RoomId } ;
38
+ use ruma:: {
39
+ events:: { relation:: RelationType , room:: MediaSource } ,
40
+ EventId , OwnedEventId , RoomId ,
41
+ } ;
39
42
use serde:: { Deserialize , Serialize } ;
40
43
use thiserror:: Error ;
41
44
@@ -907,6 +910,9 @@ impl IndexedKey<MediaRetentionPolicy> for IndexedCoreIdKey {
907
910
pub struct IndexedMedia {
908
911
/// The primary key of the object store
909
912
pub id : IndexedMediaIdKey ,
913
+ /// The (possibly) hashed source of the media derived from
914
+ /// [`MediaSource::unique_key`]
915
+ pub source : IndexedMediaSourceKey ,
910
916
/// The size (in bytes) of the media content and whether to ignore the
911
917
/// [`MediaRetentionPolicy`]
912
918
pub content_size : IndexedMediaContentSizeKey ,
@@ -944,6 +950,10 @@ impl Indexed for Media {
944
950
& self . metadata . request_parameters ,
945
951
serializer,
946
952
) ,
953
+ source : <IndexedMediaSourceKey as IndexedKey < Self > >:: encode (
954
+ & self . metadata . request_parameters . source ,
955
+ serializer,
956
+ ) ,
947
957
content_size : IndexedMediaContentSizeKey :: encode (
948
958
( self . metadata . ignore_policy , content. len ( ) ) ,
949
959
serializer,
@@ -981,6 +991,23 @@ impl IndexedKey<Media> for IndexedMediaIdKey {
981
991
}
982
992
}
983
993
994
+ /// The value associated with the [`source`](IndexedMedia::source) index of the
995
+ /// [`MEDIA`][1] object store, which is constructed from:
996
+ ///
997
+ /// - The (possibly) hashed value returned by [`MediaSource::unique_key`]
998
+ ///
999
+ /// [1]: crate::event_cache_store::migrations::v1::create_media_object_store
1000
+ #[ derive( Debug , Serialize , Deserialize ) ]
1001
+ pub struct IndexedMediaSourceKey ( String ) ;
1002
+
1003
+ impl IndexedKey < Media > for IndexedMediaSourceKey {
1004
+ type KeyComponents < ' a > = & ' a MediaSource ;
1005
+
1006
+ fn encode ( components : Self :: KeyComponents < ' _ > , serializer : & IndexeddbSerializer ) -> Self {
1007
+ Self ( serializer. encode_key_as_string ( keys:: MEDIA_SOURCE , components. unique_key ( ) ) )
1008
+ }
1009
+ }
1010
+
984
1011
/// The value associated with the [`content_size`](IndexedMedia::content_size)
985
1012
/// index of the [`MEDIA`][1] object store, which is constructed from:
986
1013
///
0 commit comments