From 6d289ebd09c135627ec3dc884f810d211d94f395 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Fri, 13 Sep 2024 12:04:55 +0200 Subject: [PATCH] Completely remove stream for new statuses --- .../Timeline/View/TimelineViewModel.swift | 40 ++----------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/Packages/Timeline/Sources/Timeline/View/TimelineViewModel.swift b/Packages/Timeline/Sources/Timeline/View/TimelineViewModel.swift index bcf72575..97445380 100644 --- a/Packages/Timeline/Sources/Timeline/View/TimelineViewModel.swift +++ b/Packages/Timeline/Sources/Timeline/View/TimelineViewModel.swift @@ -148,12 +148,7 @@ extension TimelineViewModel { extension TimelineViewModel: StatusesFetcher { func pullToRefresh() async { timelineTask?.cancel() - - if !pendingStatusesObserver.pendingStatuses.isEmpty { - await dequeuePendingStatuses() - return - } - + if !timeline.supportNewestPagination || UserPreferences.shared.fastRefreshEnabled { await reset() } @@ -302,23 +297,6 @@ extension TimelineViewModel: StatusesFetcher { StatusDataControllerProvider.shared.updateDataControllers(for: newStatuses, client: client) return newStatuses } - - private func dequeuePendingStatuses() async { - canStreamEvents = false - pendingStatusesObserver.disableUpdate = true - let statuses = await datasource.getFiltered() - let newStatuses = pendingStatusesObserver.pendingStatuses.count + 1 - statusesState = .display(statuses: statuses, nextPageState: .hasNextPage) - try? await Task.sleep(for: .milliseconds(0.005)) - scrollToIndex = newStatuses - DispatchQueue.main.async { [weak self] in - self?.pendingStatusesObserver.disableUpdate = false - self?.canStreamEvents = true - } - if pendingStatusesObserver.pendingStatuses.count <= 2 { - pendingStatusesObserver.pendingStatuses = [] - } - } private func updateTimelineWithNewStatuses(_ newStatuses: [Status]) async { let topStatus = await datasource.getFiltered().first @@ -429,7 +407,8 @@ extension TimelineViewModel { switch event { case let updateEvent as StreamEventUpdate: - await handleUpdateEvent(updateEvent, client: client) + // Removed automatic stream for events. + break case let deleteEvent as StreamEventDelete: await handleDeleteEvent(deleteEvent) case let statusUpdateEvent as StreamEventStatusUpdate: @@ -439,19 +418,6 @@ extension TimelineViewModel { } } - private func handleUpdateEvent(_ event: StreamEventUpdate, client: Client) async { - guard timeline == .home, - await !datasource.contains(statusId: event.status.id) else { return } - - pendingStatusesObserver.pendingStatuses.insert(event.status.id, at: 0) - await datasource.insert(event.status, at: 0) - await cache() - StatusDataControllerProvider.shared.updateDataControllers(for: [event.status], client: client) - if scrollToTopVisible, pendingStatusesObserver.pendingStatuses.isEmpty { - await updateStatusesState() - } - } - private func handleDeleteEvent(_ event: StreamEventDelete) async { await datasource.remove(event.status) await cache()