From 49791d2c86928df155682bf5eb44f7d7c1d61d48 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Wed, 8 Feb 2023 06:52:15 +0100 Subject: [PATCH] Fix timeline cache caching something else than home Fix #710 --- .../Status/Sources/Status/Editor/StatusEditorViewModel.swift | 1 + Packages/Timeline/Sources/Timeline/TimelineViewModel.swift | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift b/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift index 79743919..ad87563f 100644 --- a/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift +++ b/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift @@ -20,6 +20,7 @@ public class StatusEditorViewModel: NSObject, ObservableObject { textView?.pasteDelegate = self } } + var selectedRange: NSRange { get { guard let textView else { diff --git a/Packages/Timeline/Sources/Timeline/TimelineViewModel.swift b/Packages/Timeline/Sources/Timeline/TimelineViewModel.swift index 68310d1d..98238459 100644 --- a/Packages/Timeline/Sources/Timeline/TimelineViewModel.swift +++ b/Packages/Timeline/Sources/Timeline/TimelineViewModel.swift @@ -149,7 +149,7 @@ extension TimelineViewModel: StatusesFetcher { func fetchStatuses() async { guard let client else { return } do { - if statuses.isEmpty { + if statuses.isEmpty || timeline == .trending { try await fetchFirstPage(client: client) } else if let latest = statuses.first { try await fetchNewPagesFrom(latestStatus: latest, client: client) @@ -193,12 +193,13 @@ extension TimelineViewModel: StatusesFetcher { statuses = try await client.get(endpoint: timeline.endpoint(sinceId: nil, maxId: nil, minId: nil, - offset: statuses.count)) + offset: 0)) updateMentionsToBeHighlighted(&statuses) ReblogCache.shared.removeDuplicateReblogs(&statuses) await cacheHome() + withAnimation { statusesState = .display(statuses: statuses, nextPageState: statuses.count < 20 ? .none : .hasNextPage) }