@@ -253,13 +253,19 @@ impl Context {
253253 /// If an error is returned, the caller shall not try over because some sync items could be
254254 /// already executed. Sync items are considered independent and executed in the given order but
255255 /// regardless of whether executing of the previous items succeeded.
256- pub ( crate ) async fn execute_sync_items ( & self , items : & SyncItems ) {
256+ pub ( crate ) async fn execute_sync_items ( & self , items : & SyncItems , timestamp_sent : i64 ) {
257257 info ! ( self , "executing {} sync item(s)" , items. items. len( ) ) ;
258258 for item in & items. items {
259+ // Limit the timestamp to ensure it is not in the future.
260+ //
261+ // `sent_timestamp` should be already corrected
262+ // if the `Date` header is in the future.
263+ let timestamp = std:: cmp:: min ( item. timestamp , timestamp_sent) ;
264+
259265 match & item. data {
260266 SyncDataOrUnknown :: SyncData ( data) => match data {
261- AddQrToken ( token) => self . add_qr_token ( token, item . timestamp ) . await ,
262- DeleteQrToken ( token) => self . delete_qr_token ( token, item . timestamp ) . await ,
267+ AddQrToken ( token) => self . add_qr_token ( token, timestamp) . await ,
268+ DeleteQrToken ( token) => self . delete_qr_token ( token, timestamp) . await ,
263269 AlterChat { id, action } => self . sync_alter_chat ( id, action) . await ,
264270 SyncData :: Config { key, val } => self . sync_config ( key, val) . await ,
265271 SyncData :: SaveMessage { src, dest } => self . save_message ( src, dest) . await ,
@@ -557,6 +563,7 @@ mod tests {
557563
558564 assert ! ( !token:: exists( & t, Namespace :: Auth , "yip-auth" ) . await ?) ;
559565
566+ let timestamp_sent = time ( ) ;
560567 let sync_items = t
561568 . parse_sync_items (
562569 r#"{"items":[
@@ -571,7 +578,7 @@ mod tests {
571578 . to_string ( ) ,
572579 )
573580 ?;
574- t. execute_sync_items ( & sync_items) . await ;
581+ t. execute_sync_items ( & sync_items, timestamp_sent ) . await ;
575582
576583 assert ! (
577584 Contact :: lookup_id_by_addr( & t, "bob@example.net" , Origin :: Unknown )
0 commit comments