mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 10:33:45 +00:00
TimelineKind refactor (#3193)
This commit is contained in:
@@ -27,7 +27,7 @@ final class TimelineProxy: TimelineProxyProtocol {
|
||||
private let backPaginationStatusSubject = CurrentValueSubject<PaginationStatus, Never>(.timelineEndReached)
|
||||
private let forwardPaginationStatusSubject = CurrentValueSubject<PaginationStatus, Never>(.timelineEndReached)
|
||||
|
||||
let isLive: Bool
|
||||
private let kind: TimelineKind
|
||||
|
||||
private var innerTimelineProvider: RoomTimelineProviderProtocol!
|
||||
var timelineProvider: RoomTimelineProviderProtocol {
|
||||
@@ -38,9 +38,9 @@ final class TimelineProxy: TimelineProxyProtocol {
|
||||
backPaginationStatusObservationToken?.cancel()
|
||||
}
|
||||
|
||||
init(timeline: Timeline, isLive: Bool) {
|
||||
init(timeline: Timeline, kind: TimelineKind) {
|
||||
self.timeline = timeline
|
||||
self.isLive = isLive
|
||||
self.kind = kind
|
||||
}
|
||||
|
||||
func subscribeForUpdates() async {
|
||||
@@ -56,7 +56,7 @@ final class TimelineProxy: TimelineProxyProtocol {
|
||||
|
||||
await subscribeToPagination()
|
||||
|
||||
let provider = await RoomTimelineProvider(timeline: timeline, isLive: isLive, paginationStatePublisher: paginationStatePublisher)
|
||||
let provider = await RoomTimelineProvider(timeline: timeline, kind: kind, paginationStatePublisher: paginationStatePublisher)
|
||||
// Make sure the existing items are built so that we have content in the timeline before
|
||||
// determining whether or not the timeline should paginate to load more items.
|
||||
await provider.waitForInitialItems()
|
||||
@@ -84,15 +84,21 @@ final class TimelineProxy: TimelineProxyProtocol {
|
||||
// We can't subscribe to back pagination on detached timelines and as live timelines
|
||||
// can be shared between multiple instances of the same room on the stack, it is
|
||||
// safer to still use the subscription logic for back pagination when live.
|
||||
await if isLive {
|
||||
paginateBackwardsOnLive(requestSize: requestSize)
|
||||
} else {
|
||||
focussedPaginate(.backwards, requestSize: requestSize)
|
||||
switch kind {
|
||||
case .live:
|
||||
return await paginateBackwardsOnLive(requestSize: requestSize)
|
||||
case .detached:
|
||||
return await focussedPaginate(.backwards, requestSize: requestSize)
|
||||
case .pinned:
|
||||
return .success(())
|
||||
}
|
||||
}
|
||||
|
||||
func paginateForwards(requestSize: UInt16) async -> Result<Void, TimelineProxyError> {
|
||||
await focussedPaginate(.forwards, requestSize: requestSize)
|
||||
guard kind != .pinned else {
|
||||
return .success(())
|
||||
}
|
||||
return await focussedPaginate(.forwards, requestSize: requestSize)
|
||||
}
|
||||
|
||||
/// Paginate backwards using the subscription from Rust to drive the pagination state.
|
||||
@@ -538,7 +544,8 @@ final class TimelineProxy: TimelineProxyProtocol {
|
||||
}
|
||||
|
||||
private func subscribeToPagination() async {
|
||||
if isLive {
|
||||
switch kind {
|
||||
case .live:
|
||||
let backPaginationListener = RoomPaginationStatusListener { [weak self] status in
|
||||
guard let self else {
|
||||
return
|
||||
@@ -557,13 +564,15 @@ final class TimelineProxy: TimelineProxyProtocol {
|
||||
} catch {
|
||||
MXLog.error("Failed to subscribe to back pagination status with error: \(error)")
|
||||
}
|
||||
} else {
|
||||
forwardPaginationStatusSubject.send(.timelineEndReached)
|
||||
case .detached:
|
||||
// Detached timelines don't support observation, set the initial state ourself.
|
||||
backPaginationStatusSubject.send(.idle)
|
||||
forwardPaginationStatusSubject.send(.idle)
|
||||
case .pinned:
|
||||
backPaginationStatusSubject.send(.timelineEndReached)
|
||||
forwardPaginationStatusSubject.send(.timelineEndReached)
|
||||
}
|
||||
|
||||
// Detached timelines don't support observation, set the initial state ourself.
|
||||
forwardPaginationStatusSubject.send(isLive ? .timelineEndReached : .idle)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user