2021-03-11 08:41:27 +01:00
|
|
|
//
|
|
|
|
// ComposeStatusSection.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-3-11.
|
|
|
|
//
|
|
|
|
|
2021-03-12 07:18:07 +01:00
|
|
|
import UIKit
|
|
|
|
import Combine
|
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
2021-06-28 13:41:41 +02:00
|
|
|
import MetaTextView
|
|
|
|
import MastodonMeta
|
2021-03-18 08:16:35 +01:00
|
|
|
import AlamofireImage
|
2021-03-11 08:41:27 +01:00
|
|
|
|
|
|
|
enum ComposeStatusSection: Equatable, Hashable {
|
|
|
|
case repliedTo
|
|
|
|
case status
|
2021-03-17 11:09:38 +01:00
|
|
|
case attachment
|
2021-03-23 11:47:21 +01:00
|
|
|
case poll
|
2021-03-11 08:41:27 +01:00
|
|
|
}
|
2021-03-12 07:18:07 +01:00
|
|
|
|
|
|
|
extension ComposeStatusSection {
|
|
|
|
enum ComposeKind {
|
2021-03-15 06:42:46 +01:00
|
|
|
case post
|
2021-04-07 11:10:58 +02:00
|
|
|
case hashtag(hashtag: String)
|
2021-04-02 12:50:08 +02:00
|
|
|
case mention(mastodonUserObjectID: NSManagedObjectID)
|
2021-03-15 06:42:46 +01:00
|
|
|
case reply(repliedToStatusObjectID: NSManagedObjectID)
|
2021-03-12 07:18:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension ComposeStatusSection {
|
2021-06-28 13:41:41 +02:00
|
|
|
|
|
|
|
static func configureStatusContent(
|
|
|
|
cell: ComposeStatusContentTableViewCell,
|
|
|
|
attribute: ComposeStatusItem.ComposeStatusAttribute
|
|
|
|
) {
|
|
|
|
// set avatar
|
|
|
|
attribute.avatarURL
|
|
|
|
.receive(on: DispatchQueue.main)
|
|
|
|
.sink { avatarURL in
|
|
|
|
cell.statusView.configure(with: AvatarConfigurableViewConfiguration(avatarImageURL: avatarURL))
|
|
|
|
}
|
|
|
|
.store(in: &cell.disposeBag)
|
|
|
|
// set display name and username
|
2021-06-29 14:00:58 +02:00
|
|
|
Publishers.CombineLatest3(
|
|
|
|
attribute.displayName,
|
|
|
|
attribute.emojiDict,
|
2021-06-28 13:41:41 +02:00
|
|
|
attribute.username.eraseToAnyPublisher()
|
|
|
|
)
|
|
|
|
.receive(on: DispatchQueue.main)
|
2021-06-29 14:00:58 +02:00
|
|
|
.sink { displayName, emojiDict, username in
|
|
|
|
cell.statusView.nameLabel.configure(content: displayName ?? " ", emojiDict: emojiDict)
|
2021-06-28 13:41:41 +02:00
|
|
|
cell.statusView.usernameLabel.text = username.flatMap { "@" + $0 } ?? " "
|
|
|
|
}
|
|
|
|
.store(in: &cell.disposeBag)
|
|
|
|
}
|
2021-03-25 08:56:17 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-05-18 08:25:32 +02:00
|
|
|
protocol CustomEmojiReplaceableTextInput: AnyObject {
|
2021-03-25 08:56:17 +01:00
|
|
|
var inputView: UIView? { get set }
|
|
|
|
func reloadInputViews()
|
|
|
|
|
|
|
|
// UIKeyInput
|
|
|
|
func insertText(_ text: String)
|
|
|
|
// UIResponder
|
|
|
|
var isFirstResponder: Bool { get }
|
|
|
|
}
|
|
|
|
|
2021-06-07 08:22:03 +02:00
|
|
|
class CustomEmojiReplaceableTextInputReference {
|
2021-05-18 08:25:32 +02:00
|
|
|
weak var value: CustomEmojiReplaceableTextInput?
|
2021-03-25 08:56:17 +01:00
|
|
|
|
2021-05-18 08:25:32 +02:00
|
|
|
init(value: CustomEmojiReplaceableTextInput? = nil) {
|
2021-03-25 08:56:17 +01:00
|
|
|
self.value = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-18 08:25:32 +02:00
|
|
|
extension UITextField: CustomEmojiReplaceableTextInput { }
|
|
|
|
extension UITextView: CustomEmojiReplaceableTextInput { }
|
2021-03-25 08:56:17 +01:00
|
|
|
|
|
|
|
extension ComposeStatusSection {
|
|
|
|
|
|
|
|
static func configureCustomEmojiPicker(
|
|
|
|
viewModel: CustomEmojiPickerInputViewModel?,
|
2021-06-07 08:22:03 +02:00
|
|
|
customEmojiReplaceableTextInput: CustomEmojiReplaceableTextInput,
|
2021-03-25 08:56:17 +01:00
|
|
|
disposeBag: inout Set<AnyCancellable>
|
|
|
|
) {
|
|
|
|
guard let viewModel = viewModel else { return }
|
|
|
|
viewModel.isCustomEmojiComposing
|
|
|
|
.receive(on: DispatchQueue.main)
|
|
|
|
.sink { [weak viewModel] isCustomEmojiComposing in
|
|
|
|
guard let viewModel = viewModel else { return }
|
2021-06-07 08:22:03 +02:00
|
|
|
customEmojiReplaceableTextInput.inputView = isCustomEmojiComposing ? viewModel.customEmojiPickerInputView : nil
|
|
|
|
customEmojiReplaceableTextInput.reloadInputViews()
|
|
|
|
viewModel.append(customEmojiReplaceableTextInput: customEmojiReplaceableTextInput)
|
2021-03-25 08:56:17 +01:00
|
|
|
}
|
|
|
|
.store(in: &disposeBag)
|
|
|
|
}
|
|
|
|
|
2021-03-12 07:18:07 +01:00
|
|
|
}
|