mirror of
https://github.com/mastodon/mastodon-ios
synced 2025-04-11 22:58:02 +02:00
Don't use user but account on Sidebar on iPad (IOS-192)
This commit is contained in:
parent
a2c03bd6d1
commit
c152c7b3c7
@ -70,17 +70,18 @@ extension SidebarViewModel {
|
|||||||
secondaryCollectionView: UICollectionView
|
secondaryCollectionView: UICollectionView
|
||||||
) {
|
) {
|
||||||
let tabCellRegistration = UICollectionView.CellRegistration<SidebarListCollectionViewCell, MainTabBarController.Tab> { [weak self] cell, indexPath, item in
|
let tabCellRegistration = UICollectionView.CellRegistration<SidebarListCollectionViewCell, MainTabBarController.Tab> { [weak self] cell, indexPath, item in
|
||||||
guard let self = self else { return }
|
guard let self else { return }
|
||||||
|
|
||||||
let imageURL: URL? = {
|
let imageURL: URL?
|
||||||
switch item {
|
switch item {
|
||||||
case .me:
|
case .me:
|
||||||
let user = self.authContext?.mastodonAuthenticationBox.authentication.user(in: self.context.managedObjectContext)
|
let account = self.authContext?.mastodonAuthenticationBox.authentication.account()
|
||||||
return user?.avatarImageURL()
|
imageURL = account?.avatarImageURL()
|
||||||
default:
|
case .home, .search, .compose, .notifications:
|
||||||
return nil
|
// no custom avatar for other tabs
|
||||||
}
|
imageURL = nil
|
||||||
}()
|
}
|
||||||
|
|
||||||
cell.item = SidebarListContentView.Item(
|
cell.item = SidebarListContentView.Item(
|
||||||
isActive: false,
|
isActive: false,
|
||||||
accessoryImage: item == .me ? self.chevronImage : nil,
|
accessoryImage: item == .me ? self.chevronImage : nil,
|
||||||
@ -104,39 +105,40 @@ extension SidebarViewModel {
|
|||||||
.store(in: &cell.disposeBag)
|
.store(in: &cell.disposeBag)
|
||||||
|
|
||||||
switch item {
|
switch item {
|
||||||
case .notifications:
|
case .notifications:
|
||||||
Publishers.CombineLatest(
|
Publishers.CombineLatest(
|
||||||
self.context.notificationService.unreadNotificationCountDidUpdate,
|
self.context.notificationService.unreadNotificationCountDidUpdate,
|
||||||
self.$currentTab
|
self.$currentTab
|
||||||
)
|
)
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.sink { [weak cell] authentication, currentTab in
|
.sink { [weak cell] authentication, currentTab in
|
||||||
guard let cell = cell else { return }
|
guard let cell = cell else { return }
|
||||||
|
|
||||||
let hasUnreadPushNotification: Bool = {
|
let hasUnreadPushNotification: Bool = {
|
||||||
guard let accessToken = self.authContext?.mastodonAuthenticationBox.userAuthorization.accessToken else { return false }
|
guard let accessToken = self.authContext?.mastodonAuthenticationBox.userAuthorization.accessToken else { return false }
|
||||||
let count = UserDefaults.shared.getNotificationCountWithAccessToken(accessToken: accessToken)
|
let count = UserDefaults.shared.getNotificationCountWithAccessToken(accessToken: accessToken)
|
||||||
return count > 0
|
return count > 0
|
||||||
}()
|
}()
|
||||||
|
|
||||||
let image: UIImage
|
let image: UIImage
|
||||||
if hasUnreadPushNotification {
|
if hasUnreadPushNotification {
|
||||||
let imageConfiguration = UIImage.SymbolConfiguration(paletteColors: [.red, SystemTheme.tabBarItemNormalIconColor])
|
let imageConfiguration = UIImage.SymbolConfiguration(paletteColors: [.red, SystemTheme.tabBarItemNormalIconColor])
|
||||||
image = UIImage(systemName: "bell.badge", withConfiguration: imageConfiguration)!
|
image = UIImage(systemName: "bell.badge", withConfiguration: imageConfiguration)!
|
||||||
} else {
|
} else {
|
||||||
image = MainTabBarController.Tab.notifications.image
|
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
|
.store(in: &cell.disposeBag)
|
||||||
cell.item?.activeImage = image.withTintColor(Asset.Colors.Brand.blurple.color, renderingMode: .alwaysOriginal)
|
case .me:
|
||||||
cell.setNeedsUpdateConfiguration()
|
guard let account = self.authContext?.mastodonAuthenticationBox.authentication.account() else { return }
|
||||||
}
|
|
||||||
.store(in: &cell.disposeBag)
|
let currentUserDisplayName = account.displayNameWithFallback
|
||||||
case .me:
|
cell.accessibilityHint = L10n.Scene.AccountList.tabBarHint(currentUserDisplayName)
|
||||||
guard let user = self.authContext?.mastodonAuthenticationBox.authentication.user(in: self.context.managedObjectContext) else { return }
|
case .compose, .home, .search:
|
||||||
let currentUserDisplayName = user.displayNameWithFallback
|
break
|
||||||
cell.accessibilityHint = L10n.Scene.AccountList.tabBarHint(currentUserDisplayName)
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user