Skip to content

Commit 8a47e3c

Browse files
committed
refactor(event cache): inline conclude_load_more_for_fully_loaded_chunk into its only caller
And that's one overlong function name less!
1 parent 973d71f commit 8a47e3c

File tree

1 file changed

+21
-25
lines changed
  • crates/matrix-sdk/src/event_cache/room

1 file changed

+21
-25
lines changed

crates/matrix-sdk/src/event_cache/room/mod.rs

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -909,29 +909,6 @@ mod private {
909909
Ok(Some(all_chunks))
910910
}
911911

912-
/// Given a fully-loaded linked chunk with no gaps, return the
913-
/// [`LoadMoreEventsBackwardsOutcome`] expected for this room's cache.
914-
fn conclude_load_more_for_fully_loaded_chunk(&mut self) -> LoadMoreEventsBackwardsOutcome {
915-
// If we never received events for this room, this means we've never
916-
// received a sync for that room, because every room must have at least a
917-
// room creation event. Otherwise, we have reached the start of the
918-
// timeline.
919-
if self.room_linked_chunk.events().next().is_some() {
920-
// If there's at least one event, this means we've reached the start of the
921-
// timeline, since the chunk is fully loaded.
922-
trace!("chunk is fully loaded and non-empty: reached_start=true");
923-
LoadMoreEventsBackwardsOutcome::StartOfTimeline
924-
} else if !self.waited_for_initial_prev_token {
925-
// There's no events. Since we haven't yet, wait for an initial previous-token.
926-
LoadMoreEventsBackwardsOutcome::WaitForInitialPrevToken
927-
} else {
928-
// Otherwise, we've already waited, *and* received no previous-batch token from
929-
// the sync, *and* there are still no events in the fully-loaded
930-
// chunk: start back-pagination from the end of the room.
931-
LoadMoreEventsBackwardsOutcome::Gap { prev_token: None }
932-
}
933-
}
934-
935912
/// Load more events backwards if the last chunk is **not** a gap.
936913
pub(in super::super) async fn load_more_events_backwards(
937914
&mut self,
@@ -965,8 +942,27 @@ mod private {
965942
}
966943

967944
Ok(None) => {
968-
// There's no previous chunk. The chunk is now fully-loaded. Conclude.
969-
return Ok(self.conclude_load_more_for_fully_loaded_chunk());
945+
// If we never received events for this room, this means we've never received a
946+
// sync for that room, because every room must have *at least* a room creation
947+
// event. Otherwise, we have reached the start of the timeline.
948+
949+
let result = if self.room_linked_chunk.events().next().is_some() {
950+
// If there's at least one event, this means we've reached the start of the
951+
// timeline, since the chunk is fully loaded.
952+
trace!("chunk is fully loaded and non-empty: reached_start=true");
953+
LoadMoreEventsBackwardsOutcome::StartOfTimeline
954+
} else if !self.waited_for_initial_prev_token {
955+
// There no events. Since we haven't yet, wait for an initial
956+
// previous-token.
957+
LoadMoreEventsBackwardsOutcome::WaitForInitialPrevToken
958+
} else {
959+
// Otherwise, we've already waited, *and* received no previous-batch token
960+
// from the sync, *and* there are still no events in the fully-loaded
961+
// chunk: start back-pagination from the end of the room.
962+
LoadMoreEventsBackwardsOutcome::Gap { prev_token: None }
963+
};
964+
965+
return Ok(result);
970966
}
971967

972968
Err(err) => {

0 commit comments

Comments
 (0)