mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-26 10:11:00 +00:00
More accurate notifications badge
This commit is contained in:
parent
105b7717a9
commit
c4daa73932
2 changed files with 14 additions and 6 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue