chore: make hashtag inject with compose kind
This commit is contained in:
parent
ecd595c6e8
commit
08d105f7b7
|
@ -22,6 +22,7 @@ enum ComposeStatusSection: Equatable, Hashable {
|
|||
extension ComposeStatusSection {
|
||||
enum ComposeKind {
|
||||
case post
|
||||
case hashtag(hashtag: String)
|
||||
case mention(mastodonUserObjectID: NSManagedObjectID)
|
||||
case reply(repliedToStatusObjectID: NSManagedObjectID)
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ extension ComposeViewModel {
|
|||
case .reply(let statusObjectID):
|
||||
snapshot.appendItems([.replyTo(statusObjectID: statusObjectID)], toSection: .repliedTo)
|
||||
snapshot.appendItems([.input(replyToStatusObjectID: statusObjectID, attribute: composeStatusAttribute)], toSection: .repliedTo)
|
||||
case .mention, .post:
|
||||
case .hashtag, .mention, .post:
|
||||
snapshot.appendItems([.input(replyToStatusObjectID: nil, attribute: composeStatusAttribute)], toSection: .status)
|
||||
}
|
||||
diffableDataSource.apply(snapshot, animatingDifferences: false)
|
||||
|
|
|
@ -56,8 +56,9 @@ final class ComposeViewModel {
|
|||
let isPollToolbarButtonEnabled = CurrentValueSubject<Bool, Never>(true)
|
||||
let characterCount = CurrentValueSubject<Int, Never>(0)
|
||||
|
||||
// In some specific scenes(hashtag scene e.g.), we need to display the compose scene with pre-inserted text(insert '#mastodon ' in #mastodon hashtag scene, e.g.), the pre-inserted text should be treated as mannually inputed by users.
|
||||
var preInsertedContent: String? = nil
|
||||
// for hashtag: #<hashag>' '
|
||||
// for mention: @<mention>' '
|
||||
private(set) var preInsertedContent: String?
|
||||
|
||||
// custom emojis
|
||||
var customEmojiViewModelSubscription: AnyCancellable?
|
||||
|
@ -74,27 +75,34 @@ final class ComposeViewModel {
|
|||
|
||||
init(
|
||||
context: AppContext,
|
||||
composeKind: ComposeStatusSection.ComposeKind,
|
||||
preInsertedContent: String? = nil
|
||||
composeKind: ComposeStatusSection.ComposeKind
|
||||
) {
|
||||
self.context = context
|
||||
self.composeKind = composeKind
|
||||
self.preInsertedContent = preInsertedContent
|
||||
switch composeKind {
|
||||
case .post, .mention: self.title = CurrentValueSubject(L10n.Scene.Compose.Title.newPost)
|
||||
case .post, .hashtag, .mention: self.title = CurrentValueSubject(L10n.Scene.Compose.Title.newPost)
|
||||
case .reply: self.title = CurrentValueSubject(L10n.Scene.Compose.Title.newReply)
|
||||
}
|
||||
self.activeAuthentication = CurrentValueSubject(context.authenticationService.activeMastodonAuthentication.value)
|
||||
self.activeAuthenticationBox = CurrentValueSubject(context.authenticationService.activeMastodonAuthenticationBox.value)
|
||||
// end init
|
||||
|
||||
if case let .mention(mastodonUserObjectID) = composeKind {
|
||||
if case let .hashtag(text) = composeKind {
|
||||
let initialComposeContent = "#" + text
|
||||
UITextChecker.learnWord(initialComposeContent)
|
||||
let preInsertedContent = initialComposeContent + " "
|
||||
self.preInsertedContent = preInsertedContent
|
||||
self.composeStatusAttribute.composeContent.value = preInsertedContent
|
||||
} else if case let .mention(mastodonUserObjectID) = composeKind {
|
||||
context.managedObjectContext.performAndWait {
|
||||
let mastodonUser = context.managedObjectContext.object(with: mastodonUserObjectID) as! MastodonUser
|
||||
let initialComposeContent = "@" + mastodonUser.acct
|
||||
UITextChecker.learnWord(initialComposeContent)
|
||||
self.composeStatusAttribute.composeContent.value = initialComposeContent + " "
|
||||
let preInsertedContent = initialComposeContent + " "
|
||||
self.preInsertedContent = preInsertedContent
|
||||
self.composeStatusAttribute.composeContent.value = preInsertedContent
|
||||
}
|
||||
} else {
|
||||
self.preInsertedContent = nil
|
||||
}
|
||||
|
||||
isCustomEmojiComposing
|
||||
|
|
|
@ -167,7 +167,7 @@ extension HashtagTimelineViewController {
|
|||
|
||||
@objc private func composeBarButtonItemPressed(_ sender: UIBarButtonItem) {
|
||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
|
||||
let composeViewModel = ComposeViewModel(context: context, composeKind: .post, preInsertedContent: "#\(viewModel.hashtag)")
|
||||
let composeViewModel = ComposeViewModel(context: context, composeKind: .hashtag(hashtag: viewModel.hashtag))
|
||||
coordinator.present(scene: .compose(viewModel: composeViewModel), from: self, transition: .modal(animated: true, completion: nil))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue