@@ -17,7 +17,7 @@ use std::{collections::BTreeMap, fmt, sync::Arc};
1717#[ cfg( doc) ]
1818use ruma:: events:: AnyTimelineEvent ;
1919use ruma:: {
20- events:: { AnyMessageLikeEvent , AnySyncTimelineEvent } ,
20+ events:: { AnyMessageLikeEvent , AnySyncTimelineEvent , AnyToDeviceEvent } ,
2121 push:: Action ,
2222 serde:: {
2323 AsRefStr , AsStrAsRefStr , DebugAsRefStr , DeserializeFromCowStr , FromString , JsonObject , Raw ,
@@ -1165,6 +1165,53 @@ impl From<SyncTimelineEventDeserializationHelperV0> for TimelineEvent {
11651165 }
11661166}
11671167
1168+ /// Represents a to-device event after it has been processed by the Olm machine.
1169+ #[ derive( Clone , Debug ) ]
1170+ pub enum ProcessedToDeviceEvent {
1171+ /// A successfully-decrypted encrypted event.
1172+ /// Contains the raw decrypted event and encryption info
1173+ Decrypted {
1174+ /// The raw decrypted event
1175+ raw : Raw < AnyToDeviceEvent > ,
1176+ /// The Olm encryption info
1177+ encryption_info : EncryptionInfo ,
1178+ } ,
1179+
1180+ /// An encrypted event which could not be decrypted.
1181+ UnableToDecrypt ( Raw < AnyToDeviceEvent > ) ,
1182+
1183+ /// An unencrypted event.
1184+ PlainText ( Raw < AnyToDeviceEvent > ) ,
1185+
1186+ /// An invalid to device event that was ignored because it is missing some
1187+ /// required information to be processed (like no event `type` for
1188+ /// example)
1189+ Invalid ( Raw < AnyToDeviceEvent > ) ,
1190+ }
1191+
1192+ impl ProcessedToDeviceEvent {
1193+ /// Converts a ProcessedToDeviceEvent to the `Raw<AnyToDeviceEvent>` it
1194+ /// encapsulates
1195+ pub fn to_raw ( & self ) -> Raw < AnyToDeviceEvent > {
1196+ match self {
1197+ ProcessedToDeviceEvent :: Decrypted { raw, .. } => raw. clone ( ) ,
1198+ ProcessedToDeviceEvent :: UnableToDecrypt ( event) => event. clone ( ) ,
1199+ ProcessedToDeviceEvent :: PlainText ( event) => event. clone ( ) ,
1200+ ProcessedToDeviceEvent :: Invalid ( event) => event. clone ( ) ,
1201+ }
1202+ }
1203+
1204+ /// Gets the raw to-device event.
1205+ pub fn as_raw ( & self ) -> & Raw < AnyToDeviceEvent > {
1206+ match self {
1207+ ProcessedToDeviceEvent :: Decrypted { raw, .. } => raw,
1208+ ProcessedToDeviceEvent :: UnableToDecrypt ( event) => event,
1209+ ProcessedToDeviceEvent :: PlainText ( event) => event,
1210+ ProcessedToDeviceEvent :: Invalid ( event) => event,
1211+ }
1212+ }
1213+ }
1214+
11681215#[ cfg( test) ]
11691216mod tests {
11701217 use std:: { collections:: BTreeMap , sync:: Arc } ;
0 commit comments