diff --git a/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift b/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift index 441b8ca29..84b7f1cba 100644 --- a/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift +++ b/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift @@ -70,17 +70,18 @@ extension SidebarViewModel { secondaryCollectionView: UICollectionView ) { let tabCellRegistration = UICollectionView.CellRegistration { [weak self] cell, indexPath, item in - guard let self = self else { return } - - let imageURL: URL? = { - switch item { + guard let self else { return } + + let imageURL: URL? + switch item { case .me: - let user = self.authContext?.mastodonAuthenticationBox.authentication.user(in: self.context.managedObjectContext) - return user?.avatarImageURL() - default: - return nil - } - }() + let account = self.authContext?.mastodonAuthenticationBox.authentication.account() + imageURL = account?.avatarImageURL() + case .home, .search, .compose, .notifications: + // no custom avatar for other tabs + imageURL = nil + } + cell.item = SidebarListContentView.Item( isActive: false, accessoryImage: item == .me ? self.chevronImage : nil, @@ -104,39 +105,40 @@ extension SidebarViewModel { .store(in: &cell.disposeBag) switch item { - case .notifications: - Publishers.CombineLatest( - self.context.notificationService.unreadNotificationCountDidUpdate, - self.$currentTab - ) - .receive(on: DispatchQueue.main) - .sink { [weak cell] authentication, currentTab in - guard let cell = cell else { return } - - let hasUnreadPushNotification: Bool = { - guard let accessToken = self.authContext?.mastodonAuthenticationBox.userAuthorization.accessToken else { return false } - let count = UserDefaults.shared.getNotificationCountWithAccessToken(accessToken: accessToken) - return count > 0 - }() - - let image: UIImage - if hasUnreadPushNotification { - let imageConfiguration = UIImage.SymbolConfiguration(paletteColors: [.red, SystemTheme.tabBarItemNormalIconColor]) - image = UIImage(systemName: "bell.badge", withConfiguration: imageConfiguration)! - } else { - image = MainTabBarController.Tab.notifications.image + case .notifications: + Publishers.CombineLatest( + self.context.notificationService.unreadNotificationCountDidUpdate, + self.$currentTab + ) + .receive(on: DispatchQueue.main) + .sink { [weak cell] authentication, currentTab in + guard let cell = cell else { return } + + let hasUnreadPushNotification: Bool = { + guard let accessToken = self.authContext?.mastodonAuthenticationBox.userAuthorization.accessToken else { return false } + let count = UserDefaults.shared.getNotificationCountWithAccessToken(accessToken: accessToken) + return count > 0 + }() + + let image: UIImage + if hasUnreadPushNotification { + let imageConfiguration = UIImage.SymbolConfiguration(paletteColors: [.red, SystemTheme.tabBarItemNormalIconColor]) + image = UIImage(systemName: "bell.badge", withConfiguration: imageConfiguration)! + } else { + image = MainTabBarController.Tab.notifications.image + } + cell.item?.image = image + cell.item?.activeImage = image.withTintColor(Asset.Colors.Brand.blurple.color, renderingMode: .alwaysOriginal) + cell.setNeedsUpdateConfiguration() } - cell.item?.image = image - cell.item?.activeImage = image.withTintColor(Asset.Colors.Brand.blurple.color, renderingMode: .alwaysOriginal) - cell.setNeedsUpdateConfiguration() - } - .store(in: &cell.disposeBag) - case .me: - guard let user = self.authContext?.mastodonAuthenticationBox.authentication.user(in: self.context.managedObjectContext) else { return } - let currentUserDisplayName = user.displayNameWithFallback - cell.accessibilityHint = L10n.Scene.AccountList.tabBarHint(currentUserDisplayName) - default: - break + .store(in: &cell.disposeBag) + case .me: + guard let account = self.authContext?.mastodonAuthenticationBox.authentication.account() else { return } + + let currentUserDisplayName = account.displayNameWithFallback + cell.accessibilityHint = L10n.Scene.AccountList.tabBarHint(currentUserDisplayName) + case .compose, .home, .search: + break } }