From 31ca8ed7f25ed1d19647d4bc17870469baebb0a7 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Fri, 2 Feb 2024 15:25:11 +0200 Subject: [PATCH] Prevent unnecessary backpagination requests from running every time a room is entered - related to #1760 which moved initial timeline item computations to a serial queue --- ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift | 2 +- .../Screens/RoomScreen/View/Timeline/UITimelineView.swift | 4 ---- .../Timeline/TimelineController/RoomTimelineController.swift | 3 +++ 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift index e8b7c1f38..34088d18c 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift @@ -215,7 +215,7 @@ struct RoomMemberState { /// Is also nice to have this as a wrapper for any state that is directly connected to the timeline. struct TimelineViewState { var canBackPaginate = true - var isBackPaginating = false + var isBackPaginating = true // These can be removed when we have full swiftUI and moved as @State values in the view var scrollToBottomPublisher = PassthroughSubject() diff --git a/ElementX/Sources/Screens/RoomScreen/View/Timeline/UITimelineView.swift b/ElementX/Sources/Screens/RoomScreen/View/Timeline/UITimelineView.swift index 21570e634..56db4163b 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/Timeline/UITimelineView.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/Timeline/UITimelineView.swift @@ -46,10 +46,6 @@ struct UITimelineView: UIViewControllerRepresentable { init(viewModelContext: RoomScreenViewModel.Context) { context = viewModelContext - - if viewModelContext.viewState.timelineViewState.itemViewStates.isEmpty { - viewModelContext.send(viewAction: .paginateBackwards) - } } /// Updates the specified table view's properties from the current view state. diff --git a/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift b/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift index fcb186582..f470395b1 100644 --- a/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift +++ b/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift @@ -57,8 +57,11 @@ class RoomTimelineController: RoomTimelineControllerProtocol { } .store(in: &cancellables) + // Inform the world that the initial items are loading from the store + callbacks.send(.isBackPaginating(true)) serialDispatchQueue.async { self.updateTimelineItems() + self.callbacks.send(.isBackPaginating(false)) } NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil)