From ed80895fcd36bb812a7397c6dfbef448aacdc301 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Wed, 1 Feb 2023 13:28:04 +0100 Subject: [PATCH] Cache streamed status --- .../Timeline/Sources/Timeline/TimelineViewModel.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Packages/Timeline/Sources/Timeline/TimelineViewModel.swift b/Packages/Timeline/Sources/Timeline/TimelineViewModel.swift index 78b3209e..46860cea 100644 --- a/Packages/Timeline/Sources/Timeline/TimelineViewModel.swift +++ b/Packages/Timeline/Sources/Timeline/TimelineViewModel.swift @@ -72,17 +72,26 @@ class TimelineViewModel: ObservableObject { { pendingStatusesObserver.pendingStatuses.insert(event.status.id, at: 0) statuses.insert(event.status, at: 0) + Task { + await cache(statuses: statuses) + } withAnimation { statusesState = .display(statuses: statuses, nextPageState: .hasNextPage) } } else if let event = event as? StreamEventDelete { withAnimation { statuses.removeAll(where: { $0.id == event.status }) + Task { + await cache(statuses: statuses) + } statusesState = .display(statuses: statuses, nextPageState: .hasNextPage) } } else if let event = event as? StreamEventStatusUpdate { if let originalIndex = statuses.firstIndex(where: { $0.id == event.status.id }) { statuses[originalIndex] = event.status + Task { + await cache(statuses: statuses) + } statusesState = .display(statuses: statuses, nextPageState: .hasNextPage) } }