1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15- use std:: { collections:: BTreeMap , fmt} ;
15+ use std:: { collections:: BTreeMap , fmt, sync :: Arc } ;
1616
1717#[ cfg( doc) ]
1818use ruma:: events:: AnyTimelineEvent ;
@@ -462,7 +462,7 @@ impl TimelineEvent {
462462
463463 /// If the event was a decrypted event that was successfully decrypted, get
464464 /// its encryption info. Otherwise, `None`.
465- pub fn encryption_info ( & self ) -> Option < & EncryptionInfo > {
465+ pub fn encryption_info ( & self ) -> Option < & Arc < EncryptionInfo > > {
466466 self . kind . encryption_info ( )
467467 }
468468
@@ -569,7 +569,7 @@ impl TimelineEventKind {
569569
570570 /// If the event was a decrypted event that was successfully decrypted, get
571571 /// its encryption info. Otherwise, `None`.
572- pub fn encryption_info ( & self ) -> Option < & EncryptionInfo > {
572+ pub fn encryption_info ( & self ) -> Option < & Arc < EncryptionInfo > > {
573573 match self {
574574 TimelineEventKind :: Decrypted ( d) => Some ( & d. encryption_info ) ,
575575 TimelineEventKind :: UnableToDecrypt { .. } | TimelineEventKind :: PlainText { .. } => None ,
@@ -649,7 +649,7 @@ pub struct DecryptedRoomEvent {
649649 pub event : Raw < AnyMessageLikeEvent > ,
650650
651651 /// The encryption info about the event.
652- pub encryption_info : EncryptionInfo ,
652+ pub encryption_info : Arc < EncryptionInfo > ,
653653
654654 /// The encryption info about the events bundled in the `unsigned`
655655 /// object.
@@ -706,15 +706,15 @@ impl UnsignedEventLocation {
706706#[ derive( Debug , Clone , Serialize , Deserialize ) ]
707707pub enum UnsignedDecryptionResult {
708708 /// The event was successfully decrypted.
709- Decrypted ( EncryptionInfo ) ,
709+ Decrypted ( Arc < EncryptionInfo > ) ,
710710 /// The event failed to be decrypted.
711711 UnableToDecrypt ( UnableToDecryptInfo ) ,
712712}
713713
714714impl UnsignedDecryptionResult {
715715 /// Returns the encryption info for this bundled event if it was
716716 /// successfully decrypted.
717- pub fn encryption_info ( & self ) -> Option < & EncryptionInfo > {
717+ pub fn encryption_info ( & self ) -> Option < & Arc < EncryptionInfo > > {
718718 match self {
719719 Self :: Decrypted ( info) => Some ( info) ,
720720 Self :: UnableToDecrypt ( _) => None ,
@@ -918,9 +918,10 @@ struct SyncTimelineEventDeserializationHelperV0 {
918918 /// The actual event.
919919 event : Raw < AnySyncTimelineEvent > ,
920920
921- /// The encryption info about the event. Will be `None` if the event
922- /// was not encrypted.
923- encryption_info : Option < EncryptionInfo > ,
921+ /// The encryption info about the event.
922+ ///
923+ /// Will be `None` if the event was not encrypted.
924+ encryption_info : Option < Arc < EncryptionInfo > > ,
924925
925926 /// The push actions associated with this event.
926927 #[ serde( default ) ]
@@ -966,7 +967,7 @@ impl From<SyncTimelineEventDeserializationHelperV0> for TimelineEvent {
966967
967968#[ cfg( test) ]
968969mod tests {
969- use std:: collections:: BTreeMap ;
970+ use std:: { collections:: BTreeMap , sync :: Arc } ;
970971
971972 use assert_matches:: assert_matches;
972973 use insta:: { assert_json_snapshot, with_settings} ;
@@ -1118,7 +1119,7 @@ mod tests {
11181119 let room_event = TimelineEvent {
11191120 kind : TimelineEventKind :: Decrypted ( DecryptedRoomEvent {
11201121 event : Raw :: new ( & example_event ( ) ) . unwrap ( ) . cast ( ) ,
1121- encryption_info : EncryptionInfo {
1122+ encryption_info : Arc :: new ( EncryptionInfo {
11221123 sender : user_id ! ( "@sender:example.com" ) . to_owned ( ) ,
11231124 sender_device : None ,
11241125 algorithm_info : AlgorithmInfo :: MegolmV1AesSha2 {
@@ -1127,7 +1128,7 @@ mod tests {
11271128 session_id : Some ( "xyz" . to_owned ( ) ) ,
11281129 } ,
11291130 verification_state : VerificationState :: Verified ,
1130- } ,
1131+ } ) ,
11311132 unsigned_encryption_info : Some ( BTreeMap :: from ( [ (
11321133 UnsignedEventLocation :: RelationsReplace ,
11331134 UnsignedDecryptionResult :: UnableToDecrypt ( UnableToDecryptInfo {
@@ -1490,7 +1491,7 @@ mod tests {
14901491 let room_event = TimelineEvent {
14911492 kind : TimelineEventKind :: Decrypted ( DecryptedRoomEvent {
14921493 event : Raw :: new ( & example_event ( ) ) . unwrap ( ) . cast ( ) ,
1493- encryption_info : EncryptionInfo {
1494+ encryption_info : Arc :: new ( EncryptionInfo {
14941495 sender : user_id ! ( "@sender:example.com" ) . to_owned ( ) ,
14951496 sender_device : Some ( device_id ! ( "ABCDEFGHIJ" ) . to_owned ( ) ) ,
14961497 algorithm_info : AlgorithmInfo :: MegolmV1AesSha2 {
@@ -1508,7 +1509,7 @@ mod tests {
15081509 session_id : Some ( "mysessionid112" . to_owned ( ) ) ,
15091510 } ,
15101511 verification_state : VerificationState :: Verified ,
1511- } ,
1512+ } ) ,
15121513 unsigned_encryption_info : Some ( BTreeMap :: from ( [ (
15131514 UnsignedEventLocation :: RelationsThreadLatestEvent ,
15141515 UnsignedDecryptionResult :: UnableToDecrypt ( UnableToDecryptInfo {
0 commit comments