Completely clear duplicated push notifications issue

This commit is contained in:
Thomas Ricouard 2023-01-27 16:51:29 +01:00
parent 7ac8333912
commit 418e9545ba
2 changed files with 10 additions and 5 deletions

View file

@ -92,7 +92,7 @@ struct PushNotificationsView: View {
Button("settings.push.duplicate.button.fix") {
Task {
await subscription.deleteSubscription()
await subscription.updateSubscription(forceCreate: true)
await subscription.updateSubscription()
}
}
} header: {
@ -113,7 +113,7 @@ struct PushNotificationsView: View {
private func updateSubscription() {
Task {
await subscription.updateSubscription(forceCreate: true)
await subscription.updateSubscription()
}
}

View file

@ -64,7 +64,12 @@ public class PushNotificationsService: ObservableObject {
await withTaskGroup(of: Void.self, body: { group in
group.addTask {
await subscription.fetchSubscription()
await subscription.updateSubscription(forceCreate: forceCreate)
if await subscription.subscription != nil && !forceCreate {
await subscription.deleteSubscription()
await subscription.updateSubscription()
} else if forceCreate {
await subscription.updateSubscription()
}
}
})
}
@ -159,8 +164,8 @@ public class PushNotificationSubscriptionSettings: ObservableObject {
}
}
public func updateSubscription(forceCreate: Bool) async {
guard let pushToken = pushToken, subscription != nil || forceCreate else { return }
public func updateSubscription() async {
guard let pushToken = pushToken else { return }
let client = Client(server: account.server, oauthToken: account.token)
do {
var listenerURL = PushNotificationsService.Constants.endpoint