File tree 3 files changed +39
-4
lines changed
crates/matrix-sdk-ui/src/timeline
3 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -410,7 +410,28 @@ impl<P: RoomDataProvider> TimelineController<P> {
410
410
}
411
411
}
412
412
413
- /// Run a backward pagination (in focused mode) and append the results to
413
+ /// Run a lazy backwards pagination (in live mode).
414
+ ///
415
+ /// It adjusts the `count` value of the `Skip` higher-order stream so that
416
+ /// more items are pushed front in the timeline.
417
+ ///
418
+ /// If no more items are available (i.e. if the `count` is zero), this
419
+ /// method returns `Some(needs)` where `needs` is the number of events that
420
+ /// must be unlazily backwards paginated.
421
+ pub ( super ) async fn live_lazy_paginate_backwards ( & self , num_events : u16 ) -> Option < usize > {
422
+ let state = self . state . read ( ) . await ;
423
+
424
+ let ( count, needs) = state
425
+ . meta
426
+ . subscriber_skip_count
427
+ . compute_next_when_paginating_backwards ( num_events. into ( ) ) ;
428
+
429
+ state. meta . subscriber_skip_count . update ( count, & state. timeline_focus ) ;
430
+
431
+ needs
432
+ }
433
+
434
+ /// Run a backwards pagination (in focused mode) and append the results to
414
435
/// the timeline.
415
436
///
416
437
/// Returns whether we hit the start of the timeline.
@@ -439,7 +460,7 @@ impl<P: RoomDataProvider> TimelineController<P> {
439
460
Ok ( hit_end_of_timeline)
440
461
}
441
462
442
- /// Run a forward pagination (in focused mode) and append the results to
463
+ /// Run a forwards pagination (in focused mode) and append the results to
443
464
/// the timeline.
444
465
///
445
466
/// Returns whether we hit the end of the timeline.
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ pub(in crate::timeline) struct TimelineState {
58
58
pub meta : TimelineMetadata ,
59
59
60
60
/// The kind of focus of this timeline.
61
- timeline_focus : TimelineFocusKind ,
61
+ pub timeline_focus : TimelineFocusKind ,
62
62
}
63
63
64
64
impl TimelineState {
@@ -100,6 +100,7 @@ impl TimelineState {
100
100
let previous_number_of_items = self . items . len ( ) ;
101
101
102
102
let mut transaction = self . transaction ( ) ;
103
+ // Apply the diffs.
103
104
transaction. handle_remote_events_with_diffs ( diffs, origin, room_data, settings) . await ;
104
105
transaction. commit ( ) ;
105
106
Original file line number Diff line number Diff line change @@ -32,8 +32,21 @@ impl super::Timeline {
32
32
///
33
33
/// Returns whether we hit the start of the timeline.
34
34
#[ instrument( skip_all, fields( room_id = ?self . room( ) . room_id( ) ) ) ]
35
- pub async fn paginate_backwards ( & self , num_events : u16 ) -> Result < bool , Error > {
35
+ pub async fn paginate_backwards ( & self , mut num_events : u16 ) -> Result < bool , Error > {
36
36
if self . controller . is_live ( ) . await {
37
+ match self . controller . live_lazy_paginate_backwards ( num_events) . await {
38
+ Some ( needed_num_events) => {
39
+ num_events = needed_num_events. try_into ( ) . expect (
40
+ "failed to cast `needed_num_events` (`usize`) into `num_events` (`usize`)" ,
41
+ ) ;
42
+ }
43
+ None => {
44
+ // TODO: returning `false` is not true everytime, we need a way to know if
45
+ // lazy-loading has reached the end of the timeline.
46
+ return Ok ( false ) ;
47
+ }
48
+ }
49
+
37
50
Ok ( self . live_paginate_backwards ( num_events) . await ?)
38
51
} else {
39
52
Ok ( self . controller . focused_paginate_backwards ( num_events) . await ?)
You can’t perform that action at this time.
0 commit comments