@@ -154,6 +154,12 @@ pub struct InboundGroupSession {
154154
155155 /// Was this room key backed up to the server.
156156 backed_up : Arc < AtomicBool > ,
157+
158+ /// Whether this [`InboundGroupSession`] can be shared with newly joined
159+ /// users, allowing access to history, as defined in [MSC3061].
160+ ///
161+ /// MSC3061: https://github.com/matrix-org/matrix-spec-proposals/pull/3061
162+ shared_history : bool ,
157163}
158164
159165impl InboundGroupSession {
@@ -176,6 +182,7 @@ impl InboundGroupSession {
176182 ///
177183 /// * `sender_data` - Information about the sender of the to-device message
178184 /// that established this session.
185+ #[ allow( clippy:: too_many_arguments) ]
179186 pub fn new (
180187 sender_key : Curve25519PublicKey ,
181188 signing_key : Ed25519PublicKey ,
@@ -184,6 +191,7 @@ impl InboundGroupSession {
184191 sender_data : SenderData ,
185192 encryption_algorithm : EventEncryptionAlgorithm ,
186193 history_visibility : Option < HistoryVisibility > ,
194+ shared_history : bool ,
187195 ) -> Result < Self , SessionCreationError > {
188196 let config = OutboundGroupSession :: session_config ( & encryption_algorithm) ?;
189197
@@ -208,6 +216,7 @@ impl InboundGroupSession {
208216 imported : false ,
209217 algorithm : encryption_algorithm. into ( ) ,
210218 backed_up : AtomicBool :: new ( false ) . into ( ) ,
219+ shared_history,
211220 } )
212221 }
213222
@@ -228,7 +237,13 @@ impl InboundGroupSession {
228237 signing_key : Ed25519PublicKey ,
229238 content : & room_key:: MegolmV1AesSha2Content ,
230239 ) -> Result < Self , SessionCreationError > {
231- let room_key:: MegolmV1AesSha2Content { room_id, session_id : _, session_key, .. } = content;
240+ let room_key:: MegolmV1AesSha2Content {
241+ room_id,
242+ session_id : _,
243+ session_key,
244+ shared_history,
245+ ..
246+ } = content;
232247
233248 Self :: new (
234249 sender_key,
@@ -238,6 +253,7 @@ impl InboundGroupSession {
238253 SenderData :: unknown ( ) ,
239254 EventEncryptionAlgorithm :: MegolmV1AesSha2 ,
240255 None ,
256+ * shared_history,
241257 )
242258 }
243259
@@ -265,6 +281,7 @@ impl InboundGroupSession {
265281 backed_up : self . backed_up ( ) ,
266282 history_visibility : self . history_visibility . as_ref ( ) . clone ( ) ,
267283 algorithm : ( * self . algorithm ) . to_owned ( ) ,
284+ shared_history : self . shared_history ,
268285 }
269286 }
270287
@@ -317,6 +334,7 @@ impl InboundGroupSession {
317334 forwarding_curve25519_key_chain : vec ! [ ] ,
318335 sender_claimed_keys : ( * self . creator_info . signing_keys ) . clone ( ) ,
319336 session_key,
337+ shared_history : self . shared_history ,
320338 }
321339 }
322340
@@ -342,6 +360,7 @@ impl InboundGroupSession {
342360 backed_up,
343361 history_visibility,
344362 algorithm,
363+ shared_history,
345364 } = pickle;
346365
347366 let session: InnerSession = pickle. into ( ) ;
@@ -362,6 +381,7 @@ impl InboundGroupSession {
362381 backed_up : AtomicBool :: from ( backed_up) . into ( ) ,
363382 algorithm : algorithm. into ( ) ,
364383 imported,
384+ shared_history,
365385 } )
366386 }
367387
@@ -511,6 +531,14 @@ impl InboundGroupSession {
511531 pub fn sender_data_type ( & self ) -> SenderDataType {
512532 self . sender_data . to_type ( )
513533 }
534+
535+ /// Whether this [`InboundGroupSession`] can be shared with newly joined
536+ /// users, allowing access to history, as defined in [MSC3061].
537+ ///
538+ /// MSC3061: https://github.com/matrix-org/matrix-spec-proposals/pull/3061
539+ pub fn shared_history ( & self ) -> bool {
540+ self . shared_history
541+ }
514542}
515543
516544#[ cfg( not( tarpaulin_include) ) ]
@@ -556,6 +584,12 @@ pub struct PickledInboundGroupSession {
556584 /// The algorithm of this inbound group session.
557585 #[ serde( default = "default_algorithm" ) ]
558586 pub algorithm : EventEncryptionAlgorithm ,
587+ /// Whether this [`InboundGroupSession`] can be shared with newly joined
588+ /// users, allowing access to history, as defined in [MSC3061].
589+ ///
590+ /// MSC3061: https://github.com/matrix-org/matrix-spec-proposals/pull/3061
591+ #[ serde( default ) ]
592+ pub shared_history : bool ,
559593}
560594
561595fn default_algorithm ( ) -> EventEncryptionAlgorithm {
@@ -574,6 +608,7 @@ impl TryFrom<&ExportedRoomKey> for InboundGroupSession {
574608 session_key,
575609 sender_claimed_keys,
576610 forwarding_curve25519_key_chain : _,
611+ shared_history,
577612 } = key;
578613
579614 let config = OutboundGroupSession :: session_config ( & key. algorithm ) ?;
@@ -596,6 +631,7 @@ impl TryFrom<&ExportedRoomKey> for InboundGroupSession {
596631 imported : true ,
597632 algorithm : algorithm. to_owned ( ) . into ( ) ,
598633 backed_up : AtomicBool :: from ( false ) . into ( ) ,
634+ shared_history : * shared_history,
599635 } )
600636 }
601637}
@@ -626,6 +662,7 @@ impl From<&ForwardedMegolmV1AesSha2Content> for InboundGroupSession {
626662 imported : true ,
627663 algorithm : EventEncryptionAlgorithm :: MegolmV1AesSha2 . into ( ) ,
628664 backed_up : AtomicBool :: from ( false ) . into ( ) ,
665+ shared_history : false ,
629666 }
630667 }
631668}
@@ -652,6 +689,7 @@ impl From<&ForwardedMegolmV2AesSha2Content> for InboundGroupSession {
652689 imported : true ,
653690 algorithm : EventEncryptionAlgorithm :: MegolmV1AesSha2 . into ( ) ,
654691 backed_up : AtomicBool :: from ( false ) . into ( ) ,
692+ shared_history : false ,
655693 }
656694 }
657695}
@@ -768,6 +806,7 @@ mod tests {
768806 SenderData :: unknown ( ) ,
769807 EventEncryptionAlgorithm :: MegolmV1AesSha2 ,
770808 Some ( HistoryVisibility :: Shared ) ,
809+ false ,
771810 )
772811 . unwrap ( ) ;
773812
0 commit comments