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") { Button("settings.push.duplicate.button.fix") {
Task { Task {
await subscription.deleteSubscription() await subscription.deleteSubscription()
await subscription.updateSubscription(forceCreate: true) await subscription.updateSubscription()
} }
} }
} header: { } header: {
@ -113,7 +113,7 @@ struct PushNotificationsView: View {
private func updateSubscription() { private func updateSubscription() {
Task { 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 await withTaskGroup(of: Void.self, body: { group in
group.addTask { group.addTask {
await subscription.fetchSubscription() 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 { public func updateSubscription() async {
guard let pushToken = pushToken, subscription != nil || forceCreate else { return } guard let pushToken = pushToken else { return }
let client = Client(server: account.server, oauthToken: account.token) let client = Client(server: account.server, oauthToken: account.token)
do { do {
var listenerURL = PushNotificationsService.Constants.endpoint var listenerURL = PushNotificationsService.Constants.endpoint