@@ -82,36 +82,6 @@ impl RoomEvents {
82
82
self . chunks . clear ( ) ;
83
83
}
84
84
85
- fn inhibit_updates_to_ordering_tracker < F : FnOnce ( & mut Self ) -> R , R > ( & mut self , f : F ) -> R {
86
- // Start by flushing previous pending updates to the chunk ordering, if any.
87
- self . order_tracker . flush_updates ( false ) ;
88
-
89
- // Call the function.
90
- let r = f ( self ) ;
91
-
92
- // Now, flush other pending updates which have been caused by the function, and
93
- // ignore them.
94
- self . order_tracker . flush_updates ( true ) ;
95
-
96
- r
97
- }
98
-
99
- /// Replace the events with the given last chunk of events and generator.
100
- ///
101
- /// This clears all the chunks in memory before resetting to the new chunk,
102
- /// if provided.
103
- pub ( super ) fn replace_with (
104
- & mut self ,
105
- last_chunk : Option < RawChunk < Event , Gap > > ,
106
- chunk_identifier_generator : ChunkIdentifierGenerator ,
107
- ) -> Result < ( ) , LazyLoaderError > {
108
- // Since `replace_with` is used only to unload some chunks, we don't want it to
109
- // affect the chunk ordering.
110
- self . inhibit_updates_to_ordering_tracker ( move |this| {
111
- lazy_loader:: replace_with ( & mut this. chunks , last_chunk, chunk_identifier_generator)
112
- } )
113
- }
114
-
115
85
/// Push events after all events or gaps.
116
86
///
117
87
/// The last event in `events` is the most recent one.
@@ -347,8 +317,49 @@ impl RoomEvents {
347
317
}
348
318
}
349
319
350
- // Private implementations, implementation specific .
320
+ // Methods related to lazy-loading .
351
321
impl RoomEvents {
322
+ /// Inhibits all the linked chunk updates caused by the function `f` on the
323
+ /// ordering tracker.
324
+ ///
325
+ /// Updates to the linked chunk that happen because of lazy loading must not
326
+ /// be taken into account by the order tracker, otherwise the
327
+ /// fully-loaded state (tracked by the order tracker) wouldn't match
328
+ /// reality anymore. This provides a facility to help applying such
329
+ /// updates.
330
+ fn inhibit_updates_to_ordering_tracker < F : FnOnce ( & mut Self ) -> R , R > ( & mut self , f : F ) -> R {
331
+ // Start by flushing previous pending updates to the chunk ordering, if any.
332
+ self . order_tracker . flush_updates ( false ) ;
333
+
334
+ // Call the function.
335
+ let r = f ( self ) ;
336
+
337
+ // Now, flush other pending updates which have been caused by the function, and
338
+ // ignore them.
339
+ self . order_tracker . flush_updates ( true ) ;
340
+
341
+ r
342
+ }
343
+
344
+ /// Replace the events with the given last chunk of events and generator.
345
+ ///
346
+ /// Happens only during lazy loading.
347
+ ///
348
+ /// This clears all the chunks in memory before resetting to the new chunk,
349
+ /// if provided.
350
+ pub ( super ) fn replace_with (
351
+ & mut self ,
352
+ last_chunk : Option < RawChunk < Event , Gap > > ,
353
+ chunk_identifier_generator : ChunkIdentifierGenerator ,
354
+ ) -> Result < ( ) , LazyLoaderError > {
355
+ // Since `replace_with` is used only to unload some chunks, we don't want it to
356
+ // affect the chunk ordering.
357
+ self . inhibit_updates_to_ordering_tracker ( move |this| {
358
+ lazy_loader:: replace_with ( & mut this. chunks , last_chunk, chunk_identifier_generator)
359
+ } )
360
+ }
361
+
362
+ /// Prepends a lazily-loaded chunk at the beginning of the linked chunk.
352
363
pub ( super ) fn insert_new_chunk_as_first (
353
364
& mut self ,
354
365
raw_new_first_chunk : RawChunk < Event , Gap > ,
0 commit comments