Notifications: Show badge on account switcher on iOS

This commit is contained in:
Thomas Ricouard 2023-02-23 18:57:28 +01:00
parent 26e09d230b
commit f01a742845

View file

@ -14,6 +14,14 @@ public struct AppAccountsSelectorView: View {
private let accountCreationEnabled: Bool private let accountCreationEnabled: Bool
private let avatarSize: AvatarView.Size private let avatarSize: AvatarView.Size
var showNotificationBadge: Bool {
accountsViewModel
.filter { $0.account?.id != currentAccount.account?.id }
.compactMap{ $0.appAccount.oauthToken }
.map{ preferences.getNotificationsCount(for: $0) }
.reduce(0, +) > 0
}
public init(routerPath: RouterPath, public init(routerPath: RouterPath,
accountCreationEnabled: Bool = true, accountCreationEnabled: Bool = true,
avatarSize: AvatarView.Size = .badge) avatarSize: AvatarView.Size = .badge)
@ -59,7 +67,7 @@ public struct AppAccountsSelectorView: View {
.redacted(reason: .placeholder) .redacted(reason: .placeholder)
} }
}.overlay(alignment: .topTrailing) { }.overlay(alignment: .topTrailing) {
if !currentAccount.followRequests.isEmpty { if !currentAccount.followRequests.isEmpty || showNotificationBadge {
Circle() Circle()
.fill(Color.red) .fill(Color.red)
.frame(width: 9, height: 9) .frame(width: 9, height: 9)