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

@ -124,18 +124,6 @@ extension MainTabBarController {
} }
.store(in: &disposeBag) .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 #if DEBUG
// selectedIndex = 1 // selectedIndex = 1
#endif #endif