@@ -1344,73 +1344,72 @@ mod private {
1344
1344
prev_batch = None ;
1345
1345
}
1346
1346
1347
+ if all_duplicates {
1348
+ // No new events and no gap (per the previous check), thus no need to change the
1349
+ // room state. We're done!
1350
+ return Ok ( false ) ;
1351
+ }
1352
+
1347
1353
// During a sync, when a duplicated event is found, the old event is removed and
1348
1354
// the new event is added.
1349
1355
//
1350
1356
// Let's remove the old events that are duplicated.
1351
- let timeline_event_diffs = if all_duplicates {
1352
- // No new events, thus no need to change the room events.
1353
- vec ! [ ]
1354
- } else {
1355
- // Remove the old duplicated events.
1356
- //
1357
- // We don't have to worry the removals can change the position of the
1358
- // existing events, because we are pushing all _new_
1359
- // `events` at the back.
1360
- let mut timeline_event_diffs = self
1361
- . remove_events ( in_memory_duplicated_event_ids, in_store_duplicated_event_ids)
1362
- . await ?;
1363
1357
1364
- // Add the previous back-pagination token (if present), followed by the timeline
1365
- // events themselves.
1366
- let new_timeline_event_diffs = self
1367
- . with_events_mut ( true , |room_events| {
1368
- // If we only received duplicated events, we don't need to store the gap: if
1369
- // there was a gap, we'd have received an unknown event at the tail of
1370
- // the room's timeline (unless the server reordered sync events since the
1371
- // last time we sync'd).
1372
- if let Some ( prev_token) = & prev_batch {
1373
- // As a tiny optimization: remove the last chunk if it's an empty event
1374
- // one, as it's not useful to keep it before a gap.
1375
- let prev_chunk_to_remove =
1376
- room_events. rchunks ( ) . next ( ) . and_then ( |chunk| {
1377
- ( chunk. is_items ( ) && chunk. num_items ( ) == 0 )
1378
- . then_some ( chunk. identifier ( ) )
1379
- } ) ;
1380
-
1381
- room_events. push_gap ( Gap { prev_token : prev_token. clone ( ) } ) ;
1382
-
1383
- if let Some ( prev_chunk_to_remove) = prev_chunk_to_remove {
1384
- room_events. remove_empty_chunk_at ( prev_chunk_to_remove) . expect (
1358
+ // Remove the old duplicated events.
1359
+ //
1360
+ // We don't have to worry the removals can change the position of the
1361
+ // existing events, because we are pushing all _new_
1362
+ // `events` at the back.
1363
+ let mut timeline_event_diffs = self
1364
+ . remove_events ( in_memory_duplicated_event_ids, in_store_duplicated_event_ids)
1365
+ . await ?;
1366
+
1367
+ // Add the previous back-pagination token (if present), followed by the timeline
1368
+ // events themselves.
1369
+ let new_timeline_event_diffs = self
1370
+ . with_events_mut ( true , |room_events| {
1371
+ // If we only received duplicated events, we don't need to store the gap: if
1372
+ // there was a gap, we'd have received an unknown event at the tail of
1373
+ // the room's timeline (unless the server reordered sync events since the
1374
+ // last time we sync'd).
1375
+ if let Some ( prev_token) = & prev_batch {
1376
+ // As a tiny optimization: remove the last chunk if it's an empty event
1377
+ // one, as it's not useful to keep it before a gap.
1378
+ let prev_chunk_to_remove = room_events. rchunks ( ) . next ( ) . and_then ( |chunk| {
1379
+ ( chunk. is_items ( ) && chunk. num_items ( ) == 0 )
1380
+ . then_some ( chunk. identifier ( ) )
1381
+ } ) ;
1382
+
1383
+ room_events. push_gap ( Gap { prev_token : prev_token. clone ( ) } ) ;
1384
+
1385
+ if let Some ( prev_chunk_to_remove) = prev_chunk_to_remove {
1386
+ room_events. remove_empty_chunk_at ( prev_chunk_to_remove) . expect (
1385
1387
"we just checked the chunk is there, and it's an empty item chunk" ,
1386
1388
) ;
1387
- }
1388
1389
}
1390
+ }
1389
1391
1390
- room_events. push_events ( events. clone ( ) ) ;
1392
+ room_events. push_events ( events. clone ( ) ) ;
1391
1393
1392
- events. clone ( )
1393
- } )
1394
- . await ?;
1394
+ events. clone ( )
1395
+ } )
1396
+ . await ?;
1395
1397
1396
- timeline_event_diffs. extend ( new_timeline_event_diffs) ;
1397
-
1398
- if timeline. limited && prev_batch. is_some ( ) {
1399
- // If there was a previous batch token for a limited timeline, unload the chunks
1400
- // so it only contains the last one; otherwise, there might be a
1401
- // valid gap in between, and observers may not render it (yet).
1402
- //
1403
- // We must do this *after* the above call to `.with_events_mut`, so the new
1404
- // events and gaps are properly persisted to storage.
1405
- if let Some ( diffs) = self . shrink_to_last_chunk ( ) . await ? {
1406
- // Override the diffs with the new ones, as per `shrink_to_last_chunk`'s API
1407
- // contract.
1408
- timeline_event_diffs = diffs;
1409
- }
1410
- }
1398
+ timeline_event_diffs. extend ( new_timeline_event_diffs) ;
1411
1399
1412
- timeline_event_diffs
1413
- } ;
1400
+ if timeline. limited && prev_batch. is_some ( ) {
1401
+ // If there was a previous batch token for a limited timeline, unload the chunks
1402
+ // so it only contains the last one; otherwise, there might be a
1403
+ // valid gap in between, and observers may not render it (yet).
1404
+ //
1405
+ // We must do this *after* the above call to `.with_events_mut`, so the new
1406
+ // events and gaps are properly persisted to storage.
1407
+ if let Some ( diffs) = self . shrink_to_last_chunk ( ) . await ? {
1408
+ // Override the diffs with the new ones, as per `shrink_to_last_chunk`'s API
1409
+ // contract.
1410
+ timeline_event_diffs = diffs;
1411
+ }
1412
+ }
1414
1413
1415
1414
if !timeline_event_diffs. is_empty ( ) {
1416
1415
let _ = sender. send ( RoomEventCacheUpdate :: UpdateTimelineEvents {
0 commit comments