2021-03-11 08:41:27 +01:00
|
|
|
//
|
|
|
|
// ComposeViewModel.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-3-11.
|
|
|
|
//
|
|
|
|
|
|
|
|
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 {
|
2023-03-02 11:06:13 +01:00
|
|
|
|
|
|
|
enum Context {
|
|
|
|
case composeStatus
|
|
|
|
case editStatus(status: Status, statusSource: Mastodon.Entity.StatusSource)
|
|
|
|
}
|
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
|
2023-03-02 11:06:13 +01:00
|
|
|
let composeContext: Context
|
2022-12-03 19:25:07 +01:00
|
|
|
let destination: ComposeContentViewModel.Destination
|
|
|
|
let initialContent: String
|
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,
|
2023-03-02 11:06:13 +01:00
|
|
|
composeContext: ComposeViewModel.Context,
|
2022-12-03 19:25:07 +01:00
|
|
|
destination: ComposeContentViewModel.Destination,
|
|
|
|
initialContent: String = ""
|
2021-03-11 08:41:27 +01:00
|
|
|
) {
|
|
|
|
self.context = context
|
2022-10-09 14:07:57 +02:00
|
|
|
self.authContext = authContext
|
2022-12-03 19:25:07 +01:00
|
|
|
self.destination = destination
|
|
|
|
self.initialContent = initialContent
|
2023-03-02 11:06:13 +01:00
|
|
|
self.composeContext = composeContext
|
2022-11-13 15:08:26 +01:00
|
|
|
// end init
|
2022-10-09 14:07:57 +02:00
|
|
|
|
2023-03-02 11:06:13 +01:00
|
|
|
let title: String
|
|
|
|
|
|
|
|
switch composeContext {
|
|
|
|
case .composeStatus:
|
2022-12-03 19:25:07 +01:00
|
|
|
switch destination {
|
2023-03-02 11:06:13 +01:00
|
|
|
case .topLevel:
|
|
|
|
title = L10n.Scene.Compose.Title.newPost
|
|
|
|
case .reply:
|
|
|
|
title = L10n.Scene.Compose.Title.newReply
|
2022-11-13 15:08:26 +01:00
|
|
|
}
|
2023-03-02 11:06:13 +01:00
|
|
|
case .editStatus(_, _):
|
|
|
|
title = L10n.Scene.Compose.Title.editPost
|
|
|
|
}
|
|
|
|
|
|
|
|
self.title = title
|
2021-03-26 12:16:19 +01:00
|
|
|
}
|
2021-03-11 08:41:27 +01:00
|
|
|
}
|