2021-03-11 08:41:27 +01:00
|
|
|
//
|
|
|
|
// ComposeViewModel.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-3-11.
|
|
|
|
//
|
|
|
|
|
2021-03-26 12:16:19 +01:00
|
|
|
import os.log
|
2021-03-11 08:41:27 +01:00
|
|
|
import UIKit
|
|
|
|
import Combine
|
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
2021-03-18 10:33:07 +01:00
|
|
|
import GameplayKit
|
2021-03-25 12:34:30 +01:00
|
|
|
import MastodonSDK
|
2022-01-27 14:23:39 +01:00
|
|
|
import MastodonAsset
|
2022-10-08 07:43:06 +02:00
|
|
|
import MastodonCore
|
2022-01-27 14:23:39 +01:00
|
|
|
import MastodonLocalization
|
|
|
|
import MastodonMeta
|
|
|
|
import MastodonUI
|
2021-03-11 08:41:27 +01:00
|
|
|
|
2022-11-13 15:08:26 +01:00
|
|
|
final class ComposeViewModel {
|
2021-03-11 08:41:27 +01:00
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
let logger = Logger(subsystem: "ComposeViewModel", category: "ViewModel")
|
2021-03-26 12:16:19 +01:00
|
|
|
|
2021-03-12 07:18:07 +01:00
|
|
|
var disposeBag = Set<AnyCancellable>()
|
2021-07-26 14:09:23 +02:00
|
|
|
|
|
|
|
let id = UUID()
|
2021-03-12 07:18:07 +01:00
|
|
|
|
2021-03-11 08:41:27 +01:00
|
|
|
// input
|
|
|
|
let context: AppContext
|
2022-10-09 14:07:57 +02:00
|
|
|
let authContext: AuthContext
|
2022-10-10 13:14:52 +02:00
|
|
|
let kind: ComposeContentViewModel.Kind
|
2022-01-27 14:23:39 +01:00
|
|
|
|
2022-10-31 13:41:19 +01:00
|
|
|
let traitCollectionDidChangePublisher = CurrentValueSubject<Void, Never>(Void()) // use CurrentValueSubject to make initial event emit
|
2021-03-11 08:41:27 +01:00
|
|
|
|
|
|
|
// output
|
2022-11-13 15:08:26 +01:00
|
|
|
|
|
|
|
// UI & UX
|
|
|
|
@Published var title: String
|
2021-03-23 11:47:21 +01:00
|
|
|
|
2021-03-11 08:41:27 +01:00
|
|
|
init(
|
|
|
|
context: AppContext,
|
2022-10-10 13:14:52 +02:00
|
|
|
authContext: AuthContext,
|
|
|
|
kind: ComposeContentViewModel.Kind
|
2021-03-11 08:41:27 +01:00
|
|
|
) {
|
|
|
|
self.context = context
|
2022-10-09 14:07:57 +02:00
|
|
|
self.authContext = authContext
|
2022-10-10 13:14:52 +02:00
|
|
|
self.kind = kind
|
2022-11-13 15:08:26 +01:00
|
|
|
// end init
|
2022-10-09 14:07:57 +02:00
|
|
|
|
2022-11-13 15:08:26 +01:00
|
|
|
self.title = {
|
|
|
|
switch kind {
|
|
|
|
case .post, .hashtag, .mention: return L10n.Scene.Compose.Title.newPost
|
|
|
|
case .reply: return L10n.Scene.Compose.Title.newReply
|
|
|
|
}
|
|
|
|
}()
|
2021-03-11 08:41:27 +01:00
|
|
|
}
|
2021-03-12 07:18:07 +01:00
|
|
|
|
2021-03-26 12:16:19 +01:00
|
|
|
deinit {
|
|
|
|
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
|
|
|
|
}
|
|
|
|
|
2021-03-11 08:41:27 +01:00
|
|
|
}
|