@@ -40,8 +40,8 @@ use ruma::{
40
40
AnyToDeviceEvent , MessageLikeEventContent ,
41
41
} ,
42
42
serde:: Raw ,
43
- DeviceId , DeviceKeyAlgorithm , OwnedDeviceId , OwnedDeviceKeyId , OwnedTransactionId , OwnedUserId ,
44
- RoomId , TransactionId , UInt , UserId ,
43
+ DeviceId , DeviceKeyAlgorithm , MilliSecondsSinceUnixEpoch , OwnedDeviceId , OwnedDeviceKeyId ,
44
+ OwnedTransactionId , OwnedUserId , RoomId , TransactionId , UInt , UserId ,
45
45
} ;
46
46
use serde_json:: value:: to_raw_value;
47
47
use tokio:: sync:: Mutex ;
@@ -346,6 +346,16 @@ impl OlmMachine {
346
346
& self . inner . device_id
347
347
}
348
348
349
+ /// The time at which the `Account` backing this `OlmMachine` was created.
350
+ ///
351
+ /// An [`Account`] is created when an `OlmMachine` is first instantiated
352
+ /// against a given [`Store`], at which point it creates identity keys etc.
353
+ /// This method returns the timestamp, according to the local clock, at
354
+ /// which that happened.
355
+ pub fn device_creation_time ( & self ) -> MilliSecondsSinceUnixEpoch {
356
+ self . inner . store . static_account ( ) . creation_local_time ( )
357
+ }
358
+
349
359
/// Get the public parts of our Olm identity keys.
350
360
pub fn identity_keys ( & self ) -> IdentityKeys {
351
361
let account = self . inner . store . static_account ( ) ;
@@ -2410,8 +2420,13 @@ pub(crate) mod tests {
2410
2420
2411
2421
#[ async_test]
2412
2422
async fn test_create_olm_machine ( ) {
2423
+ let test_start_ts = MilliSecondsSinceUnixEpoch :: now ( ) ;
2413
2424
let machine = OlmMachine :: new ( user_id ( ) , alice_device_id ( ) ) . await ;
2414
2425
2426
+ let device_creation_time = machine. device_creation_time ( ) ;
2427
+ assert ! ( device_creation_time <= MilliSecondsSinceUnixEpoch :: now( ) ) ;
2428
+ assert ! ( device_creation_time >= test_start_ts) ;
2429
+
2415
2430
let cache = machine. store ( ) . cache ( ) . await . unwrap ( ) ;
2416
2431
let account = cache. account ( ) . await . unwrap ( ) ;
2417
2432
assert ! ( !account. shared( ) ) ;
0 commit comments