2022-02-08 05:36:06 +01:00
|
|
|
//
|
2022-05-10 12:34:39 +02:00
|
|
|
// ReportStatusViewModel.swift
|
2022-02-08 05:36:06 +01:00
|
|
|
// Mastodon
|
|
|
|
//
|
2022-05-10 12:34:39 +02:00
|
|
|
// Created by MainasuK on 2022-5-10.
|
2022-02-08 05:36:06 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
import Combine
|
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
|
|
|
import Foundation
|
|
|
|
import GameplayKit
|
|
|
|
import MastodonSDK
|
|
|
|
import OrderedCollections
|
|
|
|
import os.log
|
|
|
|
import UIKit
|
2022-10-08 07:43:06 +02:00
|
|
|
import MastodonCore
|
2022-02-08 05:36:06 +01:00
|
|
|
|
2022-05-10 12:34:39 +02:00
|
|
|
class ReportStatusViewModel {
|
2022-02-08 05:36:06 +01:00
|
|
|
|
|
|
|
var disposeBag = Set<AnyCancellable>()
|
|
|
|
|
2022-05-10 12:34:39 +02:00
|
|
|
weak var delegate: ReportStatusViewControllerDelegate?
|
|
|
|
|
2022-02-08 05:36:06 +01:00
|
|
|
// input
|
|
|
|
let context: AppContext
|
2022-10-09 14:07:57 +02:00
|
|
|
let authContext: AuthContext
|
2022-02-08 05:36:06 +01:00
|
|
|
let user: ManagedObjectRecord<MastodonUser>
|
|
|
|
let status: ManagedObjectRecord<Status>?
|
|
|
|
let statusFetchedResultsController: StatusFetchedResultsController
|
|
|
|
let listBatchFetchViewModel = ListBatchFetchViewModel()
|
|
|
|
|
2022-05-10 12:34:39 +02:00
|
|
|
@Published var isSkip = false
|
2022-02-08 05:36:06 +01:00
|
|
|
@Published var selectStatuses = OrderedSet<ManagedObjectRecord<Status>>()
|
|
|
|
|
|
|
|
// output
|
|
|
|
var diffableDataSource: UITableViewDiffableDataSource<ReportSection, ReportItem>?
|
|
|
|
private(set) lazy var stateMachine: GKStateMachine = {
|
|
|
|
let stateMachine = GKStateMachine(states: [
|
|
|
|
State.Initial(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
|
|
|
|
}()
|
|
|
|
|
|
|
|
@Published var isNextButtonEnabled = false
|
|
|
|
|
|
|
|
init(
|
|
|
|
context: AppContext,
|
2022-10-09 14:07:57 +02:00
|
|
|
authContext: AuthContext,
|
2022-02-08 05:36:06 +01:00
|
|
|
user: ManagedObjectRecord<MastodonUser>,
|
|
|
|
status: ManagedObjectRecord<Status>?
|
|
|
|
) {
|
|
|
|
self.context = context
|
2022-10-09 14:07:57 +02:00
|
|
|
self.authContext = authContext
|
2022-02-08 05:36:06 +01:00
|
|
|
self.user = user
|
|
|
|
self.status = status
|
|
|
|
self.statusFetchedResultsController = StatusFetchedResultsController(
|
|
|
|
managedObjectContext: context.managedObjectContext,
|
2022-10-09 14:07:57 +02:00
|
|
|
domain: authContext.mastodonAuthenticationBox.domain,
|
2022-02-08 05:36:06 +01:00
|
|
|
additionalTweetPredicate: nil
|
|
|
|
)
|
|
|
|
// end init
|
|
|
|
|
|
|
|
if let status = status {
|
|
|
|
selectStatuses.append(status)
|
|
|
|
}
|
2022-10-09 14:07:57 +02:00
|
|
|
|
2022-02-08 05:36:06 +01:00
|
|
|
$selectStatuses
|
2022-11-21 11:27:14 +01:00
|
|
|
.map { !$0.isEmpty }
|
2022-02-08 05:36:06 +01:00
|
|
|
.assign(to: &$isNextButtonEnabled)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|