Dynamically adjusting the visibleRoomsView's timeline limit based on the app state

This commit is contained in:
Stefan Ceriu
2023-01-31 15:43:15 +02:00
committed by Stefan Ceriu
parent a8f154740e
commit 8f3842f74a
9 changed files with 64 additions and 25 deletions
@@ -259,7 +259,7 @@ class ClientProxy: ClientProxyProtocol {
// Build the visibleRoomsSlidingSyncView here so that it can take advantage of the SS builder cold cache
// We will still register the allRoomsSlidingSyncView later, and than will have no cache
let visibleRoomsView = try SlidingSyncViewBuilder()
.timelineLimit(limit: 1)
.timelineLimit(limit: UInt32(SlidingSyncConstants.initialTimelineLimit)) // Starts off with zero to quickly load rooms, then goes to 1 while scrolling to quickly load last messages and 20 when the scrolling stops to load room history
.requiredState(requiredState: slidingSyncRequiredState)
.filters(filters: slidingSyncFilters)
.name(name: "CurrentlyVisibleRooms")
@@ -301,8 +301,8 @@ class ClientProxy: ClientProxyProtocol {
// The allRoomsSlidingSyncView will be registered as soon as the visibleRoomsSlidingSyncView receives its first update
visibleRoomsViewProxyStateObservationToken = visibleRoomsViewProxy.diffPublisher.sink { [weak self] _ in
MXLog.info("Visible rooms view received first update, registering all rooms view")
self?.registerAllRoomSlidingSyncView()
MXLog.info("Visible rooms view received first update, configuring views post initial sync")
self?.configureViewsPostInitialSync()
self?.visibleRoomsViewProxyStateObservationToken = nil
}
}
@@ -349,13 +349,21 @@ class ClientProxy: ClientProxyProtocol {
tags: [],
notTags: [])
private func registerAllRoomSlidingSyncView() {
guard let allRoomsSlidingSyncView else {
MXLog.error("All rooms sliding sync view unavailable")
return
private func configureViewsPostInitialSync() {
if let visibleRoomsSlidingSyncView {
MXLog.info("Setting visible rooms view timeline limit to \(SlidingSyncConstants.lastMessageTimelineLimit)")
visibleRoomsSlidingSyncView.setTimelineLimit(value: UInt32(SlidingSyncConstants.lastMessageTimelineLimit))
} else {
MXLog.error("Visible rooms sliding sync view unavailable")
}
if let allRoomsSlidingSyncView {
MXLog.info("Registering all rooms view")
_ = slidingSync?.addView(view: allRoomsSlidingSyncView)
} else {
MXLog.error("All rooms sliding sync view unavailable")
}
_ = slidingSync?.addView(view: allRoomsSlidingSyncView)
restartSync()
}
@@ -58,6 +58,12 @@ enum PushFormat {
// }
}
enum SlidingSyncConstants {
static let initialTimelineLimit: UInt = 0
static let lastMessageTimelineLimit: UInt = 1
static let timelinePrecachingTimelineLimit: UInt = 20
}
protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
var callbacks: PassthroughSubject<ClientProxyCallback, Never> { get }
@@ -102,10 +102,11 @@ class SlidingSyncViewProxy {
try slidingSync.getRoom(roomId: identifier)
}
func updateVisibleRange(_ range: Range<Int>) {
MXLog.info("Setting sliding sync view range to \(range)")
func updateVisibleRange(_ range: Range<Int>, timelineLimit: UInt) {
MXLog.info("Setting sliding sync view range to \(range), timelineLimit: \(timelineLimit)")
slidingSyncView.setRange(start: UInt32(range.lowerBound), end: UInt32(range.upperBound))
slidingSyncView.setTimelineLimit(value: UInt32(timelineLimit))
visibleRangeUpdatePublisher.send(())
}