More accurate notifications badge

This commit is contained in:
Thomas Ricouard 2023-02-22 12:14:57 +01:00
parent 105b7717a9
commit c4daa73932
2 changed files with 14 additions and 6 deletions

View file

@ -49,6 +49,9 @@ struct NotificationsTab: View {
}
.onAppear {
routerPath.client = client
if isSecondaryColumn {
clearNotifications()
}
}
.withSafariRouter()
.environmentObject(routerPath)
@ -74,12 +77,7 @@ struct NotificationsTab: View {
.onChange(of: scenePhase, perform: { scenePhase in
switch scenePhase {
case .active:
if isSecondaryColumn {
if let token = appAccount.currentAccount.oauthToken {
userPreferences.setNotification(count: 0, token: token)
}
watcher.unreadNotificationsCount = 0
}
clearNotifications()
default:
break
}
@ -88,4 +86,13 @@ struct NotificationsTab: View {
routerPath.path = []
}
}
private func clearNotifications() {
if isSecondaryColumn {
if let token = appAccount.currentAccount.oauthToken {
userPreferences.setNotification(count: 0, token: token)
}
watcher.unreadNotificationsCount = 0
}
}
}

View file

@ -95,6 +95,7 @@ public class UserPreferences: ObservableObject {
public func setNotification(count: Int, token: OauthToken) {
Self.sharedDefault?.set(count, forKey: "push_notifications_count_\(token.createdAt)")
objectWillChange.send()
}
public func getNotificationsCount(for token: OauthToken) -> Int {