2021-11-02 07:56:42 +01:00
|
|
|
//
|
|
|
|
// FollowingListViewModel.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by Cirno MainasuK on 2021-11-2.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import Combine
|
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
|
|
|
import GameplayKit
|
2022-10-08 07:43:06 +02:00
|
|
|
import MastodonCore
|
2021-11-02 07:56:42 +01:00
|
|
|
import MastodonSDK
|
|
|
|
|
|
|
|
final class FollowingListViewModel {
|
|
|
|
|
|
|
|
var disposeBag = Set<AnyCancellable>()
|
|
|
|
|
|
|
|
// input
|
|
|
|
let context: AppContext
|
2022-10-09 14:07:57 +02:00
|
|
|
let authContext: AuthContext
|
2021-11-02 07:56:42 +01:00
|
|
|
let userFetchedResultsController: UserFetchedResultsController
|
2022-01-27 14:23:39 +01:00
|
|
|
let listBatchFetchViewModel = ListBatchFetchViewModel()
|
2021-11-02 07:56:42 +01:00
|
|
|
|
2022-10-09 14:07:57 +02:00
|
|
|
@Published var domain: String?
|
|
|
|
@Published var userID: String?
|
|
|
|
|
2021-11-02 07:56:42 +01:00
|
|
|
// output
|
|
|
|
var diffableDataSource: UITableViewDiffableDataSource<UserSection, UserItem>?
|
|
|
|
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
|
|
|
|
}()
|
|
|
|
|
2022-10-09 14:07:57 +02:00
|
|
|
init(
|
|
|
|
context: AppContext,
|
|
|
|
authContext: AuthContext,
|
|
|
|
domain: String?,
|
|
|
|
userID: String?
|
|
|
|
) {
|
2021-11-02 07:56:42 +01:00
|
|
|
self.context = context
|
2022-10-09 14:07:57 +02:00
|
|
|
self.authContext = authContext
|
2021-11-02 07:56:42 +01:00
|
|
|
self.userFetchedResultsController = UserFetchedResultsController(
|
|
|
|
managedObjectContext: context.managedObjectContext,
|
|
|
|
domain: domain,
|
2022-02-16 10:25:55 +01:00
|
|
|
additionalPredicate: nil
|
2021-11-02 07:56:42 +01:00
|
|
|
)
|
2022-10-09 14:07:57 +02:00
|
|
|
self.domain = domain
|
|
|
|
self.userID = userID
|
2021-11-02 07:56:42 +01:00
|
|
|
// super.init()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|