2022-10-28 13:06:18 +02:00
|
|
|
//
|
|
|
|
// ComposeContentViewModel+MetaTextDelegate.swift
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Created by MainasuK on 2022/10/28.
|
|
|
|
//
|
|
|
|
|
|
|
|
import os.log
|
|
|
|
import UIKit
|
|
|
|
import MetaTextKit
|
|
|
|
import TwitterMeta
|
|
|
|
import MastodonMeta
|
|
|
|
|
|
|
|
// MARK: - MetaTextDelegate
|
|
|
|
extension ComposeContentViewModel: MetaTextDelegate {
|
|
|
|
|
|
|
|
public enum MetaTextViewKind: Int {
|
|
|
|
case none
|
|
|
|
case content
|
|
|
|
case contentWarning
|
|
|
|
}
|
|
|
|
|
|
|
|
public func metaText(
|
|
|
|
_ metaText: MetaText,
|
|
|
|
processEditing textStorage: MetaTextStorage
|
|
|
|
) -> MetaContent? {
|
|
|
|
let kind = MetaTextViewKind(rawValue: metaText.textView.tag) ?? .none
|
|
|
|
|
|
|
|
switch kind {
|
|
|
|
case .none:
|
|
|
|
assertionFailure()
|
|
|
|
return nil
|
|
|
|
|
|
|
|
case .content:
|
|
|
|
let textInput = textStorage.string
|
|
|
|
self.content = textInput
|
|
|
|
|
|
|
|
let content = MastodonContent(
|
|
|
|
content: textInput,
|
2022-11-13 12:42:50 +01:00
|
|
|
emojis: [:] // customEmojiViewModel?.emojis.value.asDictionary ?? [:]
|
2022-10-28 13:06:18 +02:00
|
|
|
)
|
|
|
|
let metaContent = MastodonMetaContent.convert(text: content)
|
|
|
|
return metaContent
|
|
|
|
|
|
|
|
case .contentWarning:
|
|
|
|
let textInput = textStorage.string.replacingOccurrences(of: "\n", with: " ")
|
|
|
|
self.contentWarning = textInput
|
|
|
|
|
|
|
|
let content = MastodonContent(
|
|
|
|
content: textInput,
|
2022-11-13 12:42:50 +01:00
|
|
|
emojis: [:] // customEmojiViewModel?.emojis.value.asDictionary ?? [:]
|
2022-10-28 13:06:18 +02:00
|
|
|
)
|
|
|
|
let metaContent = MastodonMetaContent.convert(text: content)
|
|
|
|
return metaContent
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|