2021-04-01 08:39:15 +02:00
|
|
|
//
|
|
|
|
// UserTimelineViewModel.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-3-29.
|
|
|
|
//
|
|
|
|
|
|
|
|
import os.log
|
|
|
|
import UIKit
|
|
|
|
import GameplayKit
|
|
|
|
import Combine
|
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
|
|
|
import MastodonSDK
|
2022-10-08 07:43:06 +02:00
|
|
|
import MastodonCore
|
2021-04-01 08:39:15 +02:00
|
|
|
|
2021-04-07 08:24:28 +02:00
|
|
|
final class UserTimelineViewModel {
|
2021-04-01 08:39:15 +02:00
|
|
|
|
|
|
|
var disposeBag = Set<AnyCancellable>()
|
|
|
|
|
|
|
|
// input
|
|
|
|
let context: AppContext
|
2022-10-09 14:07:57 +02:00
|
|
|
let authContext: AuthContext
|
2022-05-26 17:19:47 +02:00
|
|
|
let title: String
|
2021-04-01 08:39:15 +02:00
|
|
|
let statusFetchedResultsController: StatusFetchedResultsController
|
2021-11-10 10:55:12 +01:00
|
|
|
let listBatchFetchViewModel = ListBatchFetchViewModel()
|
2022-05-26 17:19:47 +02:00
|
|
|
@Published var userIdentifier: UserIdentifier?
|
|
|
|
@Published var queryFilter: QueryFilter
|
|
|
|
|
|
|
|
@Published var isBlocking = false
|
|
|
|
@Published var isBlockedBy = false
|
|
|
|
@Published var isSuspended = false
|
2021-07-15 11:26:04 +02:00
|
|
|
|
2022-05-26 17:19:47 +02:00
|
|
|
// let userDisplayName = CurrentValueSubject<String?, Never>(nil) // for suspended prompt label
|
|
|
|
// var dataSourceDidUpdate = PassthroughSubject<Void, Never>()
|
2021-04-01 08:39:15 +02:00
|
|
|
|
|
|
|
// output
|
2022-01-27 14:23:39 +01:00
|
|
|
var diffableDataSource: UITableViewDiffableDataSource<StatusSection, StatusItem>?
|
2021-04-01 08:39:15 +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),
|
2021-04-07 08:24:28 +02:00
|
|
|
State.Loading(viewModel: self),
|
2021-04-01 08:39:15 +02:00
|
|
|
State.NoMore(viewModel: self),
|
|
|
|
])
|
|
|
|
stateMachine.enter(State.Initial.self)
|
|
|
|
return stateMachine
|
|
|
|
}()
|
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
init(
|
|
|
|
context: AppContext,
|
2022-10-09 14:07:57 +02:00
|
|
|
authContext: AuthContext,
|
2022-05-26 17:19:47 +02:00
|
|
|
title: String,
|
2022-01-27 14:23:39 +01:00
|
|
|
queryFilter: QueryFilter
|
|
|
|
) {
|
2021-04-01 08:39:15 +02:00
|
|
|
self.context = context
|
2022-10-09 14:07:57 +02:00
|
|
|
self.authContext = authContext
|
2022-05-26 17:19:47 +02:00
|
|
|
self.title = title
|
2021-04-01 08:39:15 +02:00
|
|
|
self.statusFetchedResultsController = StatusFetchedResultsController(
|
|
|
|
managedObjectContext: context.managedObjectContext,
|
2022-10-09 14:07:57 +02:00
|
|
|
domain: authContext.mastodonAuthenticationBox.domain,
|
2022-05-13 11:23:35 +02:00
|
|
|
additionalTweetPredicate: nil
|
2021-04-01 08:39:15 +02:00
|
|
|
)
|
2022-01-27 14:23:39 +01:00
|
|
|
self.queryFilter = queryFilter
|
2021-04-01 08:39:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
deinit {
|
2022-05-13 11:23:35 +02:00
|
|
|
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
|
2021-04-01 08:39:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extension UserTimelineViewModel {
|
|
|
|
struct QueryFilter {
|
|
|
|
let excludeReplies: Bool?
|
|
|
|
let excludeReblogs: Bool?
|
|
|
|
let onlyMedia: Bool?
|
|
|
|
|
|
|
|
init(
|
|
|
|
excludeReplies: Bool? = nil,
|
|
|
|
excludeReblogs: Bool? = nil,
|
|
|
|
onlyMedia: Bool? = nil
|
|
|
|
) {
|
|
|
|
self.excludeReplies = excludeReplies
|
|
|
|
self.excludeReblogs = excludeReblogs
|
|
|
|
self.onlyMedia = onlyMedia
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|