diff --git a/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewController+DataSourceProvider.swift b/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewController+DataSourceProvider.swift index 9f89d3058..8c7885017 100644 --- a/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewController+DataSourceProvider.swift +++ b/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewController+DataSourceProvider.swift @@ -29,11 +29,11 @@ extension HashtagTimelineViewController: DataSourceProvider { } func update(status: MastodonStatus) { - viewModel.fetchedResultsController.update(status: status) + viewModel.dataController.update(status: status) } func delete(status: MastodonStatus) { - viewModel.fetchedResultsController.deleteRecord(status) + viewModel.dataController.deleteRecord(status) } @MainActor diff --git a/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewModel+Diffable.swift b/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewModel+Diffable.swift index 8cc185382..fe98ac78a 100644 --- a/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewModel+Diffable.swift +++ b/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewModel+Diffable.swift @@ -34,7 +34,7 @@ extension HashtagTimelineViewModel { snapshot.appendSections([.main]) diffableDataSource?.apply(snapshot) - fetchedResultsController.$records + dataController.$records .receive(on: DispatchQueue.main) .sink { [weak self] records in guard let self = self else { return } diff --git a/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewModel+State.swift b/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewModel+State.swift index aa4d89d77..b78ec0287 100644 --- a/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewModel+State.swift +++ b/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewModel+State.swift @@ -146,7 +146,7 @@ extension HashtagTimelineViewModel.State { self.maxID = newMaxID var hasNewStatusesAppend = false - var statusIDs = isReloading ? [] : await viewModel.fetchedResultsController.records.map { $0.entity } + var statusIDs = isReloading ? [] : await viewModel.dataController.records.map { $0.entity } for status in response.value { guard !statusIDs.contains(status) else { continue } statusIDs.append(status) @@ -159,7 +159,7 @@ extension HashtagTimelineViewModel.State { await enter(state: NoMore.self) } - await viewModel.fetchedResultsController.setRecords(statusIDs.map { MastodonStatus.fromEntity($0) }) + await viewModel.dataController.setRecords(statusIDs.map { MastodonStatus.fromEntity($0) }) viewModel.didLoadLatest.send() } catch { await enter(state: Fail.self) diff --git a/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewModel.swift b/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewModel.swift index df34abbbe..2e3054f80 100644 --- a/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewModel.swift +++ b/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewModel.swift @@ -24,7 +24,7 @@ final class HashtagTimelineViewModel { // input let context: AppContext let authContext: AuthContext - let fetchedResultsController: StatusDataController + let dataController: StatusDataController let isFetchingLatestTimeline = CurrentValueSubject(false) let timelinePredicate = CurrentValueSubject(nil) let hashtagEntity = CurrentValueSubject(nil) @@ -55,7 +55,7 @@ final class HashtagTimelineViewModel { self.context = context self.authContext = authContext self.hashtag = hashtag - self.fetchedResultsController = StatusDataController() + self.dataController = StatusDataController() updateTagInformation() // end init } diff --git a/Mastodon/Scene/HomeTimeline/HomeTimelineViewController+DataSourceProvider.swift b/Mastodon/Scene/HomeTimeline/HomeTimelineViewController+DataSourceProvider.swift index aa4252b46..94a587f79 100644 --- a/Mastodon/Scene/HomeTimeline/HomeTimelineViewController+DataSourceProvider.swift +++ b/Mastodon/Scene/HomeTimeline/HomeTimelineViewController+DataSourceProvider.swift @@ -34,11 +34,11 @@ extension HomeTimelineViewController: DataSourceProvider { } func update(status: MastodonStatus) { - viewModel.fetchedResultsController.update(status: status) + viewModel.dataController.update(status: status) } func delete(status: MastodonStatus) { - viewModel.fetchedResultsController.records = viewModel.fetchedResultsController.records.filter { $0.id != status.id } + viewModel.dataController.records = viewModel.dataController.records.filter { $0.id != status.id } } @MainActor diff --git a/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+Diffable.swift b/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+Diffable.swift index e15d5c4a1..c9e81737f 100644 --- a/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+Diffable.swift +++ b/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+Diffable.swift @@ -34,7 +34,7 @@ extension HomeTimelineViewModel { snapshot.appendSections([.main]) diffableDataSource?.apply(snapshot) - fetchedResultsController.$records + dataController.$records .receive(on: DispatchQueue.main) .sink { [weak self] records in guard let self = self else { return } diff --git a/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+LoadLatestState.swift b/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+LoadLatestState.swift index 19a58c80b..65ec13d66 100644 --- a/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+LoadLatestState.swift +++ b/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+LoadLatestState.swift @@ -84,7 +84,7 @@ extension HomeTimelineViewModel.LoadLatestState { guard let viewModel else { return } - let latestFeedRecords = viewModel.fetchedResultsController.records.prefix(APIService.onceRequestStatusMaxCount) + let latestFeedRecords = viewModel.dataController.records.prefix(APIService.onceRequestStatusMaxCount) Task { let latestStatusIDs: [Status.ID] = latestFeedRecords.compactMap { record in @@ -115,8 +115,8 @@ extension HomeTimelineViewModel.LoadLatestState { var newRecords: [MastodonFeed] = newStatuses.map { MastodonFeed.fromStatus(.fromEntity($0), kind: .home) } - viewModel.fetchedResultsController.records = { - var oldRecords = viewModel.fetchedResultsController.records + viewModel.dataController.records = { + var oldRecords = viewModel.dataController.records for (i, record) in newRecords.enumerated() { if let index = oldRecords.firstIndex(where: { $0.status?.reblog?.id == record.id || $0.status?.id == record.id }) { oldRecords[index] = record diff --git a/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+LoadOldestState.swift b/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+LoadOldestState.swift index 5f306ea20..3f980bada 100644 --- a/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+LoadOldestState.swift +++ b/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+LoadOldestState.swift @@ -31,7 +31,7 @@ extension HomeTimelineViewModel.LoadOldestState { class Initial: HomeTimelineViewModel.LoadOldestState { override func isValidNextState(_ stateClass: AnyClass) -> Bool { guard let viewModel = viewModel else { return false } - guard !viewModel.fetchedResultsController.records.isEmpty else { return false } + guard !viewModel.dataController.records.isEmpty else { return false } return stateClass == Loading.self } } @@ -46,7 +46,7 @@ extension HomeTimelineViewModel.LoadOldestState { guard let viewModel = viewModel, let stateMachine = stateMachine else { return } - guard let lastFeedRecord = viewModel.fetchedResultsController.records.last else { + guard let lastFeedRecord = viewModel.dataController.records.last else { stateMachine.enter(Idle.self) return } diff --git a/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel.swift b/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel.swift index aabcda20e..d56155d9a 100644 --- a/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel.swift +++ b/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel.swift @@ -25,7 +25,7 @@ final class HomeTimelineViewModel: NSObject { // input let context: AppContext let authContext: AuthContext - let fetchedResultsController: FeedDataController + let dataController: FeedDataController let homeTimelineNavigationBarTitleViewModel: HomeTimelineNavigationBarTitleViewModel let listBatchFetchViewModel = ListBatchFetchViewModel() @@ -81,10 +81,10 @@ final class HomeTimelineViewModel: NSObject { init(context: AppContext, authContext: AuthContext) { self.context = context self.authContext = authContext - self.fetchedResultsController = FeedDataController(context: context, authContext: authContext) + self.dataController = FeedDataController(context: context, authContext: authContext) self.homeTimelineNavigationBarTitleViewModel = HomeTimelineNavigationBarTitleViewModel(context: context) super.init() - self.fetchedResultsController.records = (try? FileManager.default.cachedHomeTimeline(for: authContext.mastodonAuthenticationBox).map { + self.dataController.records = (try? FileManager.default.cachedHomeTimeline(for: authContext.mastodonAuthenticationBox).map { MastodonFeed.fromStatus($0, kind: .home) }) ?? [] @@ -103,7 +103,7 @@ final class HomeTimelineViewModel: NSObject { } .store(in: &disposeBag) - self.fetchedResultsController.$records + self.dataController.$records .removeDuplicates() .receive(on: DispatchQueue.main) .sink(receiveValue: { feeds in @@ -115,7 +115,7 @@ final class HomeTimelineViewModel: NSObject { }) .store(in: &disposeBag) - self.fetchedResultsController.loadInitial(kind: .home) + self.dataController.loadInitial(kind: .home) } } @@ -129,7 +129,7 @@ extension HomeTimelineViewModel { extension HomeTimelineViewModel { func timelineDidReachEnd() { - fetchedResultsController.loadNext(kind: .home) + dataController.loadNext(kind: .home) } }