2021-04-07 08:24:28 +02:00
|
|
|
//
|
|
|
|
// FavoriteViewModel.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-4-6.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import Combine
|
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
|
|
|
import GameplayKit
|
2022-10-08 07:43:06 +02:00
|
|
|
import MastodonCore
|
2021-04-07 08:24:28 +02:00
|
|
|
|
|
|
|
final class FavoriteViewModel {
|
|
|
|
|
|
|
|
var disposeBag = Set<AnyCancellable>()
|
|
|
|
|
|
|
|
// input
|
|
|
|
let context: AppContext
|
2021-07-20 10:40:04 +02:00
|
|
|
let activeMastodonAuthenticationBox: CurrentValueSubject<MastodonAuthenticationBox?, Never>
|
2021-04-07 08:24:28 +02:00
|
|
|
let statusFetchedResultsController: StatusFetchedResultsController
|
2022-01-27 14:23:39 +01:00
|
|
|
let listBatchFetchViewModel = ListBatchFetchViewModel()
|
|
|
|
|
2021-04-07 08:24:28 +02:00
|
|
|
// output
|
2022-01-27 14:23:39 +01:00
|
|
|
var diffableDataSource: UITableViewDiffableDataSource<StatusSection, StatusItem>?
|
2021-04-07 08:24:28 +02:00
|
|
|
private(set) lazy var stateMachine: GKStateMachine = {
|
|
|
|
let stateMachine = GKStateMachine(states: [
|
|
|
|
State.Initial(viewModel: self),
|
|
|
|
State.Reloading(viewModel: self),
|
|
|
|
State.Fail(viewModel: self),
|
|
|
|
State.Idle(viewModel: self),
|
|
|
|
State.Loading(viewModel: self),
|
|
|
|
State.NoMore(viewModel: self),
|
|
|
|
])
|
|
|
|
stateMachine.enter(State.Initial.self)
|
|
|
|
return stateMachine
|
|
|
|
}()
|
|
|
|
|
|
|
|
init(context: AppContext) {
|
|
|
|
self.context = context
|
|
|
|
self.activeMastodonAuthenticationBox = CurrentValueSubject(context.authenticationService.activeMastodonAuthenticationBox.value)
|
|
|
|
self.statusFetchedResultsController = StatusFetchedResultsController(
|
|
|
|
managedObjectContext: context.managedObjectContext,
|
|
|
|
domain: nil,
|
2022-01-27 14:23:39 +01:00
|
|
|
additionalTweetPredicate: nil
|
2021-04-07 08:24:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
context.authenticationService.activeMastodonAuthenticationBox
|
|
|
|
.assign(to: \.value, on: activeMastodonAuthenticationBox)
|
|
|
|
.store(in: &disposeBag)
|
|
|
|
|
|
|
|
activeMastodonAuthenticationBox
|
|
|
|
.map { $0?.domain }
|
2022-10-08 07:43:06 +02:00
|
|
|
.assign(to: \.domain, on: statusFetchedResultsController)
|
2021-04-07 08:24:28 +02:00
|
|
|
.store(in: &disposeBag)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|