chore: move emoji preload to compose scene

This commit is contained in:
CMK 2021-03-16 11:23:34 +08:00
parent 7705e54e67
commit f69086e6c3
2 changed files with 25 additions and 17 deletions

View File

@ -29,6 +29,10 @@ final class ComposeViewModel {
let shouldDismiss = CurrentValueSubject<Bool, Never>(true)
let isComposeTootBarButtonItemEnabled = CurrentValueSubject<Bool, Never>(false)
// custom emojis
let customEmojiViewModel = CurrentValueSubject<EmojiService.CustomEmojiViewModel?, Never>(nil)
init(
context: AppContext,
composeKind: ComposeStatusSection.ComposeKind
@ -47,24 +51,26 @@ final class ComposeViewModel {
.assign(to: \.value, on: activeAuthentication)
.store(in: &disposeBag)
// bind avatar and names
activeAuthentication
.sink { [weak self] mastodonAuthentication in
guard let self = self else { return }
let mastodonUser = mastodonAuthentication?.user
let username = mastodonUser?.username ?? " "
self.composeTootAttribute.avatarURL.value = mastodonUser?.avatarImageURL()
self.composeTootAttribute.displayName.value = {
self.composeStatusAttribute.avatarURL.value = mastodonUser?.avatarImageURL()
self.composeStatusAttribute.displayName.value = {
guard let displayName = mastodonUser?.displayName, !displayName.isEmpty else {
return username
}
return displayName
}()
self.composeTootAttribute.username.value = username
self.composeStatusAttribute.username.value = username
}
.store(in: &disposeBag)
composeTootAttribute.composeContent
// bind compose bar button item UI state
composeStatusAttribute.composeContent
.receive(on: DispatchQueue.main)
.map { content in
let content = content?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
@ -73,7 +79,8 @@ final class ComposeViewModel {
.assign(to: \.value, on: isComposeTootBarButtonItemEnabled)
.store(in: &disposeBag)
composeTootAttribute.composeContent
// bind modal dismiss state
composeStatusAttribute.composeContent
.receive(on: DispatchQueue.main)
.map { content in
let content = content ?? ""
@ -81,6 +88,19 @@ final class ComposeViewModel {
}
.assign(to: \.value, on: shouldDismiss)
.store(in: &disposeBag)
// bind custom emojis
context.authenticationService.activeMastodonAuthenticationBox
.receive(on: DispatchQueue.main)
.sink { [weak self] activeMastodonAuthenticationBox in
guard let self = self else { return }
guard let activeMastodonAuthenticationBox = activeMastodonAuthenticationBox else { return }
let domain = activeMastodonAuthenticationBox.domain
// trigger dequeue to preload emojis
_ = self.context.emojiService.dequeueCustomEmojiViewModel(for: domain)
}
.store(in: &disposeBag)
}
}

View File

@ -123,18 +123,6 @@ extension MainTabBarController {
}
}
.store(in: &disposeBag)
context.authenticationService.activeMastodonAuthenticationBox
.receive(on: DispatchQueue.main)
.sink { [weak self] activeMastodonAuthenticationBox in
guard let self = self else { return }
guard let activeMastodonAuthenticationBox = activeMastodonAuthenticationBox else { return }
let domain = activeMastodonAuthenticationBox.domain
// trigger dequeue to preload emojis
_ = self.context.emojiService.dequeueCustomEmojiViewModel(for: domain)
}
.store(in: &disposeBag)
#if DEBUG
// selectedIndex = 1