From f69086e6c3b6cfdc77d09c63e7f6f6e84ee4d1f1 Mon Sep 17 00:00:00 2001 From: CMK Date: Tue, 16 Mar 2021 11:23:34 +0800 Subject: [PATCH] chore: move emoji preload to compose scene --- Mastodon/Scene/Compose/ComposeViewModel.swift | 30 +++++++++++++++---- .../Scene/MainTab/MainTabBarController.swift | 12 -------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/Mastodon/Scene/Compose/ComposeViewModel.swift b/Mastodon/Scene/Compose/ComposeViewModel.swift index a357b874..8084ab53 100644 --- a/Mastodon/Scene/Compose/ComposeViewModel.swift +++ b/Mastodon/Scene/Compose/ComposeViewModel.swift @@ -29,6 +29,10 @@ final class ComposeViewModel { let shouldDismiss = CurrentValueSubject(true) let isComposeTootBarButtonItemEnabled = CurrentValueSubject(false) + // custom emojis + let customEmojiViewModel = CurrentValueSubject(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) } } diff --git a/Mastodon/Scene/MainTab/MainTabBarController.swift b/Mastodon/Scene/MainTab/MainTabBarController.swift index 1c8e8816..a556854e 100644 --- a/Mastodon/Scene/MainTab/MainTabBarController.swift +++ b/Mastodon/Scene/MainTab/MainTabBarController.swift @@ -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