mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-01-27 21:09:17 +01:00
More accurate notifications badge
This commit is contained in:
parent
105b7717a9
commit
c4daa73932
@ -49,6 +49,9 @@ struct NotificationsTab: View {
|
|||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
routerPath.client = client
|
routerPath.client = client
|
||||||
|
if isSecondaryColumn {
|
||||||
|
clearNotifications()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.withSafariRouter()
|
.withSafariRouter()
|
||||||
.environmentObject(routerPath)
|
.environmentObject(routerPath)
|
||||||
@ -74,12 +77,7 @@ struct NotificationsTab: View {
|
|||||||
.onChange(of: scenePhase, perform: { scenePhase in
|
.onChange(of: scenePhase, perform: { scenePhase in
|
||||||
switch scenePhase {
|
switch scenePhase {
|
||||||
case .active:
|
case .active:
|
||||||
if isSecondaryColumn {
|
clearNotifications()
|
||||||
if let token = appAccount.currentAccount.oauthToken {
|
|
||||||
userPreferences.setNotification(count: 0, token: token)
|
|
||||||
}
|
|
||||||
watcher.unreadNotificationsCount = 0
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -88,4 +86,13 @@ struct NotificationsTab: View {
|
|||||||
routerPath.path = []
|
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) {
|
public func setNotification(count: Int, token: OauthToken) {
|
||||||
Self.sharedDefault?.set(count, forKey: "push_notifications_count_\(token.createdAt)")
|
Self.sharedDefault?.set(count, forKey: "push_notifications_count_\(token.createdAt)")
|
||||||
|
objectWillChange.send()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getNotificationsCount(for token: OauthToken) -> Int {
|
public func getNotificationsCount(for token: OauthToken) -> Int {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user