Rename properties
This commit is contained in:
parent
4561dc5495
commit
c1ad3e2a9c
|
@ -29,11 +29,11 @@ extension HashtagTimelineViewController: DataSourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(status: MastodonStatus) {
|
func update(status: MastodonStatus) {
|
||||||
viewModel.fetchedResultsController.update(status: status)
|
viewModel.dataController.update(status: status)
|
||||||
}
|
}
|
||||||
|
|
||||||
func delete(status: MastodonStatus) {
|
func delete(status: MastodonStatus) {
|
||||||
viewModel.fetchedResultsController.deleteRecord(status)
|
viewModel.dataController.deleteRecord(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
|
|
|
@ -34,7 +34,7 @@ extension HashtagTimelineViewModel {
|
||||||
snapshot.appendSections([.main])
|
snapshot.appendSections([.main])
|
||||||
diffableDataSource?.apply(snapshot)
|
diffableDataSource?.apply(snapshot)
|
||||||
|
|
||||||
fetchedResultsController.$records
|
dataController.$records
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.sink { [weak self] records in
|
.sink { [weak self] records in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
|
|
|
@ -146,7 +146,7 @@ extension HashtagTimelineViewModel.State {
|
||||||
self.maxID = newMaxID
|
self.maxID = newMaxID
|
||||||
|
|
||||||
var hasNewStatusesAppend = false
|
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 {
|
for status in response.value {
|
||||||
guard !statusIDs.contains(status) else { continue }
|
guard !statusIDs.contains(status) else { continue }
|
||||||
statusIDs.append(status)
|
statusIDs.append(status)
|
||||||
|
@ -159,7 +159,7 @@ extension HashtagTimelineViewModel.State {
|
||||||
await enter(state: NoMore.self)
|
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()
|
viewModel.didLoadLatest.send()
|
||||||
} catch {
|
} catch {
|
||||||
await enter(state: Fail.self)
|
await enter(state: Fail.self)
|
||||||
|
|
|
@ -24,7 +24,7 @@ final class HashtagTimelineViewModel {
|
||||||
// input
|
// input
|
||||||
let context: AppContext
|
let context: AppContext
|
||||||
let authContext: AuthContext
|
let authContext: AuthContext
|
||||||
let fetchedResultsController: StatusDataController
|
let dataController: StatusDataController
|
||||||
let isFetchingLatestTimeline = CurrentValueSubject<Bool, Never>(false)
|
let isFetchingLatestTimeline = CurrentValueSubject<Bool, Never>(false)
|
||||||
let timelinePredicate = CurrentValueSubject<NSPredicate?, Never>(nil)
|
let timelinePredicate = CurrentValueSubject<NSPredicate?, Never>(nil)
|
||||||
let hashtagEntity = CurrentValueSubject<Mastodon.Entity.Tag?, Never>(nil)
|
let hashtagEntity = CurrentValueSubject<Mastodon.Entity.Tag?, Never>(nil)
|
||||||
|
@ -55,7 +55,7 @@ final class HashtagTimelineViewModel {
|
||||||
self.context = context
|
self.context = context
|
||||||
self.authContext = authContext
|
self.authContext = authContext
|
||||||
self.hashtag = hashtag
|
self.hashtag = hashtag
|
||||||
self.fetchedResultsController = StatusDataController()
|
self.dataController = StatusDataController()
|
||||||
updateTagInformation()
|
updateTagInformation()
|
||||||
// end init
|
// end init
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,11 @@ extension HomeTimelineViewController: DataSourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(status: MastodonStatus) {
|
func update(status: MastodonStatus) {
|
||||||
viewModel.fetchedResultsController.update(status: status)
|
viewModel.dataController.update(status: status)
|
||||||
}
|
}
|
||||||
|
|
||||||
func delete(status: MastodonStatus) {
|
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
|
@MainActor
|
||||||
|
|
|
@ -34,7 +34,7 @@ extension HomeTimelineViewModel {
|
||||||
snapshot.appendSections([.main])
|
snapshot.appendSections([.main])
|
||||||
diffableDataSource?.apply(snapshot)
|
diffableDataSource?.apply(snapshot)
|
||||||
|
|
||||||
fetchedResultsController.$records
|
dataController.$records
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.sink { [weak self] records in
|
.sink { [weak self] records in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
|
|
|
@ -84,7 +84,7 @@ extension HomeTimelineViewModel.LoadLatestState {
|
||||||
|
|
||||||
guard let viewModel else { return }
|
guard let viewModel else { return }
|
||||||
|
|
||||||
let latestFeedRecords = viewModel.fetchedResultsController.records.prefix(APIService.onceRequestStatusMaxCount)
|
let latestFeedRecords = viewModel.dataController.records.prefix(APIService.onceRequestStatusMaxCount)
|
||||||
|
|
||||||
Task {
|
Task {
|
||||||
let latestStatusIDs: [Status.ID] = latestFeedRecords.compactMap { record in
|
let latestStatusIDs: [Status.ID] = latestFeedRecords.compactMap { record in
|
||||||
|
@ -115,8 +115,8 @@ extension HomeTimelineViewModel.LoadLatestState {
|
||||||
var newRecords: [MastodonFeed] = newStatuses.map {
|
var newRecords: [MastodonFeed] = newStatuses.map {
|
||||||
MastodonFeed.fromStatus(.fromEntity($0), kind: .home)
|
MastodonFeed.fromStatus(.fromEntity($0), kind: .home)
|
||||||
}
|
}
|
||||||
viewModel.fetchedResultsController.records = {
|
viewModel.dataController.records = {
|
||||||
var oldRecords = viewModel.fetchedResultsController.records
|
var oldRecords = viewModel.dataController.records
|
||||||
for (i, record) in newRecords.enumerated() {
|
for (i, record) in newRecords.enumerated() {
|
||||||
if let index = oldRecords.firstIndex(where: { $0.status?.reblog?.id == record.id || $0.status?.id == record.id }) {
|
if let index = oldRecords.firstIndex(where: { $0.status?.reblog?.id == record.id || $0.status?.id == record.id }) {
|
||||||
oldRecords[index] = record
|
oldRecords[index] = record
|
||||||
|
|
|
@ -31,7 +31,7 @@ extension HomeTimelineViewModel.LoadOldestState {
|
||||||
class Initial: HomeTimelineViewModel.LoadOldestState {
|
class Initial: HomeTimelineViewModel.LoadOldestState {
|
||||||
override func isValidNextState(_ stateClass: AnyClass) -> Bool {
|
override func isValidNextState(_ stateClass: AnyClass) -> Bool {
|
||||||
guard let viewModel = viewModel else { return false }
|
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
|
return stateClass == Loading.self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ extension HomeTimelineViewModel.LoadOldestState {
|
||||||
|
|
||||||
guard let viewModel = viewModel, let stateMachine = stateMachine else { return }
|
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)
|
stateMachine.enter(Idle.self)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ final class HomeTimelineViewModel: NSObject {
|
||||||
// input
|
// input
|
||||||
let context: AppContext
|
let context: AppContext
|
||||||
let authContext: AuthContext
|
let authContext: AuthContext
|
||||||
let fetchedResultsController: FeedDataController
|
let dataController: FeedDataController
|
||||||
let homeTimelineNavigationBarTitleViewModel: HomeTimelineNavigationBarTitleViewModel
|
let homeTimelineNavigationBarTitleViewModel: HomeTimelineNavigationBarTitleViewModel
|
||||||
let listBatchFetchViewModel = ListBatchFetchViewModel()
|
let listBatchFetchViewModel = ListBatchFetchViewModel()
|
||||||
|
|
||||||
|
@ -81,10 +81,10 @@ final class HomeTimelineViewModel: NSObject {
|
||||||
init(context: AppContext, authContext: AuthContext) {
|
init(context: AppContext, authContext: AuthContext) {
|
||||||
self.context = context
|
self.context = context
|
||||||
self.authContext = authContext
|
self.authContext = authContext
|
||||||
self.fetchedResultsController = FeedDataController(context: context, authContext: authContext)
|
self.dataController = FeedDataController(context: context, authContext: authContext)
|
||||||
self.homeTimelineNavigationBarTitleViewModel = HomeTimelineNavigationBarTitleViewModel(context: context)
|
self.homeTimelineNavigationBarTitleViewModel = HomeTimelineNavigationBarTitleViewModel(context: context)
|
||||||
super.init()
|
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)
|
MastodonFeed.fromStatus($0, kind: .home)
|
||||||
}) ?? []
|
}) ?? []
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ final class HomeTimelineViewModel: NSObject {
|
||||||
}
|
}
|
||||||
.store(in: &disposeBag)
|
.store(in: &disposeBag)
|
||||||
|
|
||||||
self.fetchedResultsController.$records
|
self.dataController.$records
|
||||||
.removeDuplicates()
|
.removeDuplicates()
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.sink(receiveValue: { feeds in
|
.sink(receiveValue: { feeds in
|
||||||
|
@ -115,7 +115,7 @@ final class HomeTimelineViewModel: NSObject {
|
||||||
})
|
})
|
||||||
.store(in: &disposeBag)
|
.store(in: &disposeBag)
|
||||||
|
|
||||||
self.fetchedResultsController.loadInitial(kind: .home)
|
self.dataController.loadInitial(kind: .home)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ extension HomeTimelineViewModel {
|
||||||
|
|
||||||
extension HomeTimelineViewModel {
|
extension HomeTimelineViewModel {
|
||||||
func timelineDidReachEnd() {
|
func timelineDidReachEnd() {
|
||||||
fetchedResultsController.loadNext(kind: .home)
|
dataController.loadNext(kind: .home)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue