@@ -1533,43 +1533,27 @@ mod private {
1533
1533
return Ok ( ( false , Vec :: new ( ) ) ) ;
1534
1534
}
1535
1535
1536
+ let has_new_gap = prev_batch. is_some ( ) ;
1537
+
1538
+ // If we've never waited for an initial previous-batch token, and we've now
1539
+ // inserted a gap, no need to wait for a previous-batch token later.
1540
+ if !self . waited_for_initial_prev_token && has_new_gap {
1541
+ self . waited_for_initial_prev_token = true ;
1542
+ }
1543
+
1536
1544
// Remove the old duplicated events.
1537
1545
//
1538
1546
// We don't have to worry the removals can change the position of the existing
1539
1547
// events, because we are pushing all _new_ `events` at the back.
1540
1548
self . remove_events ( in_memory_duplicated_event_ids, in_store_duplicated_event_ids)
1541
1549
. await ?;
1542
1550
1543
- // Add the previous back-pagination token (if present), followed by the timeline
1544
- // events themselves.
1545
- if let Some ( prev_token) = & prev_batch {
1546
- // As a tiny optimization: remove the last chunk if it's an empty event
1547
- // one, as it's not useful to keep it before a gap.
1548
- let prev_chunk_to_remove =
1549
- self . room_linked_chunk . rchunks ( ) . next ( ) . and_then ( |chunk| {
1550
- ( chunk. is_items ( ) && chunk. num_items ( ) == 0 ) . then_some ( chunk. identifier ( ) )
1551
- } ) ;
1552
-
1553
- self . room_linked_chunk . push_gap ( Gap { prev_token : prev_token. clone ( ) } ) ;
1554
-
1555
- // If we've never waited for an initial previous-batch token, and we've now
1556
- // inserted a gap, no need to wait for a previous-batch token later.
1557
- if !self . waited_for_initial_prev_token && prev_batch. is_some ( ) {
1558
- self . waited_for_initial_prev_token = true ;
1559
- }
1560
-
1561
- if let Some ( prev_chunk_to_remove) = prev_chunk_to_remove {
1562
- self . room_linked_chunk
1563
- . remove_empty_chunk_at ( prev_chunk_to_remove)
1564
- . expect ( "we just checked the chunk is there, and it's an empty item chunk" ) ;
1565
- }
1566
- }
1567
-
1568
- self . room_linked_chunk . push_events ( events. clone ( ) ) ;
1551
+ self . room_linked_chunk
1552
+ . push_live_events ( prev_batch. map ( |prev_token| Gap { prev_token } ) , & events) ;
1569
1553
1570
1554
self . post_process_new_events ( events, true ) . await ?;
1571
1555
1572
- if timeline. limited && prev_batch . is_some ( ) {
1556
+ if timeline. limited && has_new_gap {
1573
1557
// If there was a previous batch token for a limited timeline, unload the chunks
1574
1558
// so it only contains the last one; otherwise, there might be a
1575
1559
// valid gap in between, and observers may not render it (yet).
@@ -1581,7 +1565,7 @@ mod private {
1581
1565
1582
1566
let timeline_event_diffs = self . room_linked_chunk . updates_as_vector_diffs ( ) ;
1583
1567
1584
- Ok ( ( prev_batch . is_some ( ) , timeline_event_diffs) )
1568
+ Ok ( ( has_new_gap , timeline_event_diffs) )
1585
1569
}
1586
1570
1587
1571
#[ must_use = "Propagate `VectorDiff` updates via `RoomEventCacheUpdate`" ]
0 commit comments