From 9cf4975bfd314d5c19f2efa82de8fb7bf50415f2 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 11 Apr 2024 11:55:56 -0400 Subject: [PATCH] Remove transaction ID from push notifications registration --- .../Sources/PushNotifications/DisabledPushManager.swift | 2 +- .../Sources/PushNotifications/PushManager.swift | 2 +- .../Sources/PushNotifications/PushManagerImpl.swift | 6 ++---- .../Preferences/Notifications/NotificationsPrefsView.swift | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Packages/PushNotifications/Sources/PushNotifications/DisabledPushManager.swift b/Packages/PushNotifications/Sources/PushNotifications/DisabledPushManager.swift index ef7454c5..f55e9eb2 100644 --- a/Packages/PushNotifications/Sources/PushNotifications/DisabledPushManager.swift +++ b/Packages/PushNotifications/Sources/PushNotifications/DisabledPushManager.swift @@ -31,7 +31,7 @@ class DisabledPushManager: _PushManager { nil } - func register(transactionID: UInt64) async throws -> PushProxyRegistration { + func register() async throws -> PushProxyRegistration { throw Disabled() } diff --git a/Packages/PushNotifications/Sources/PushNotifications/PushManager.swift b/Packages/PushNotifications/Sources/PushNotifications/PushManager.swift index f282a81b..ebbc86a9 100644 --- a/Packages/PushNotifications/Sources/PushNotifications/PushManager.swift +++ b/Packages/PushNotifications/Sources/PushNotifications/PushManager.swift @@ -50,7 +50,7 @@ public protocol _PushManager { func updateSubscription(account: UserAccountInfo, alerts: PushSubscription.Alerts, policy: PushSubscription.Policy) func pushSubscription(account: UserAccountInfo) -> PushSubscription? - func register(transactionID: UInt64) async throws -> PushProxyRegistration + func register() async throws -> PushProxyRegistration func unregister() async throws func updateIfNecessary(updateSubscription: @escaping (PushSubscription) async -> Bool) async diff --git a/Packages/PushNotifications/Sources/PushNotifications/PushManagerImpl.swift b/Packages/PushNotifications/Sources/PushNotifications/PushManagerImpl.swift index b0bdc482..04a1afe6 100644 --- a/Packages/PushNotifications/Sources/PushNotifications/PushManagerImpl.swift +++ b/Packages/PushNotifications/Sources/PushNotifications/PushManagerImpl.swift @@ -109,7 +109,7 @@ class PushManagerImpl: _PushManager { subscriptions.first { $0.accountID == account.id } } - func register(transactionID: UInt64) async throws -> PushProxyRegistration { + func register() async throws -> PushProxyRegistration { guard remoteNotificationsRegistrationContinuation == nil else { throw PushRegistrationError.alreadyRegistering } @@ -203,7 +203,7 @@ class PushManagerImpl: _PushManager { var request = URLRequest(url: url.url!) request.httpMethod = "POST" request.setValue("application/json", forHTTPHeaderField: "content-type") - request.httpBody = try! JSONEncoder().encode(PushRegistrationParams(transactionID: "TODO", environment: apnsEnvironment, deviceToken: deviceToken, pushVersion: 1)) + request.httpBody = try! JSONEncoder().encode(PushRegistrationParams(environment: apnsEnvironment, deviceToken: deviceToken, pushVersion: 1)) let (data, resp) = try await URLSession.shared.data(for: request) let status = (resp as! HTTPURLResponse).statusCode guard (200...299).contains(status) else { @@ -286,13 +286,11 @@ enum CreateSubscriptionError: LocalizedError { } private struct PushRegistrationParams: Encodable { - let transactionID: String let environment: String let deviceToken: String let pushVersion: Int enum CodingKeys: String, CodingKey { - case transactionID = "transaction_id" case environment case deviceToken = "device_token" case pushVersion = "push_version" diff --git a/Tusker/Screens/Preferences/Notifications/NotificationsPrefsView.swift b/Tusker/Screens/Preferences/Notifications/NotificationsPrefsView.swift index 288f390c..69f6c4c8 100644 --- a/Tusker/Screens/Preferences/Notifications/NotificationsPrefsView.swift +++ b/Tusker/Screens/Preferences/Notifications/NotificationsPrefsView.swift @@ -84,7 +84,7 @@ struct NotificationsPrefsView: View { private func registerForRemoteNotifications() async -> Bool { do { - pushProxyRegistration = try await PushManager.shared.register(transactionID: 0) + pushProxyRegistration = try await PushManager.shared.register() return true } catch { self.error = .registering(error)