Skip to content

Commit cde9d37

Browse files
authored
Push notifications: Clean up logic for register/unregister tokens (#16434)
2 parents 4a657b5 + e591de3 commit cde9d37

File tree

12 files changed

+12
-78
lines changed

12 files changed

+12
-78
lines changed

Modules/Sources/Networking/Remote/DevicesRemote.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ public class DevicesRemote: Remote {
1111
/// - device: APNS Device to be registered.
1212
/// - applicationId: App ID.
1313
/// - applicationVersion: App Version.
14-
/// - defaultStoreID: Active Store ID.
1514
/// - completion: Closure to be executed on completion.
1615
///
1716
public func registerDevice(device: APNSDevice,
1817
applicationId: String,
1918
applicationVersion: String,
20-
defaultStoreID: Int64,
2119
completion: @escaping (DotcomDevice?, Error?) -> Void) {
2220
var parameters = [
2321
ParameterKeys.applicationId: applicationId,
@@ -27,7 +25,6 @@ public class DevicesRemote: Remote {
2725
ParameterKeys.deviceModel: device.model,
2826
ParameterKeys.deviceName: device.name,
2927
ParameterKeys.deviceOSVersion: device.iOSVersion,
30-
ParameterKeys.defaultStoreID: ""
3128
]
3229

3330
if let deviceUUID = device.identifierForVendor {
@@ -84,6 +81,5 @@ private extension DevicesRemote {
8481
static let deviceName = "device_name"
8582
static let deviceOSVersion = "os_version"
8683
static let deviceUUID = "device_uuid"
87-
static let defaultStoreID = "selected_blog_id"
8884
}
8985
}

Modules/Sources/Yosemite/Actions/NotificationAction.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public enum NotificationAction: Action {
1212
case registerDevice(device: APNSDevice,
1313
applicationId: String,
1414
applicationVersion: String,
15-
defaultStoreID: Int64,
1615
onCompletion: (DotcomDevice?, Error?) -> Void)
1716

1817
/// Unregisters a device for Push Notifications Delivery.

Modules/Sources/Yosemite/Stores/NotificationStore.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@ public class NotificationStore: Store {
3737
case .registerDevice(let device,
3838
let applicationId,
3939
let applicationVersion,
40-
let defaultStoreID,
4140
let onCompletion):
4241
registerDevice(device: device,
4342
applicationId: applicationId,
4443
applicationVersion: applicationVersion,
45-
defaultStoreID: defaultStoreID,
4644
onCompletion: onCompletion)
4745
case .synchronizeNotifications(let onCompletion):
4846
synchronizeNotifications(onCompletion: onCompletion)
@@ -72,12 +70,10 @@ private extension NotificationStore {
7270
func registerDevice(device: APNSDevice,
7371
applicationId: String,
7472
applicationVersion: String,
75-
defaultStoreID: Int64,
7673
onCompletion: @escaping (DotcomDevice?, Error?) -> Void) {
7774
devicesRemote.registerDevice(device: device,
7875
applicationId: applicationId,
7976
applicationVersion: applicationVersion,
80-
defaultStoreID: defaultStoreID,
8177
completion: onCompletion)
8278
}
8379

Modules/Tests/NetworkingTests/Remote/DevicesRemoteTests.swift

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ final class DevicesRemoteTests: XCTestCase {
2929

3030
remote.registerDevice(device: Parameters.appleDevice,
3131
applicationId: Parameters.applicationId,
32-
applicationVersion: Parameters.applicationVersion,
33-
defaultStoreID: Parameters.defaultStoreID) { (settings, error) in
32+
applicationVersion: Parameters.applicationVersion) { (settings, error) in
3433

3534
XCTAssertNil(error)
3635
XCTAssertNotNil(settings)
@@ -41,24 +40,6 @@ final class DevicesRemoteTests: XCTestCase {
4140
wait(for: [expectation], timeout: Constants.expectationTimeout)
4241
}
4342

44-
/// Verifies that registerDevice sets the `selected_blog_id` parameter to empty string.
45-
///
46-
func test_registerDevice_sets_selected_blog_id_to_empty_string() throws {
47-
// Given
48-
let remote = DevicesRemote(network: network)
49-
50-
// When
51-
remote.registerDevice(device: Parameters.appleDevice,
52-
applicationId: Parameters.applicationId,
53-
applicationVersion: Parameters.applicationVersion,
54-
defaultStoreID: Parameters.defaultStoreID) { (_, _) in }
55-
56-
// Then
57-
let queryParameters = try XCTUnwrap(network.queryParameters)
58-
let expectedParam = "selected_blog_id="
59-
XCTAssertTrue(queryParameters.contains(expectedParam), "Expected to have param: \(expectedParam)")
60-
}
61-
6243
/// Verifies that registerDevice parses a "Failure" Backend Response.
6344
///
6445
func test_registerDevice_parses_general_failure_response() {
@@ -69,8 +50,7 @@ final class DevicesRemoteTests: XCTestCase {
6950

7051
remote.registerDevice(device: Parameters.appleDevice,
7152
applicationId: Parameters.applicationId,
72-
applicationVersion: Parameters.applicationVersion,
73-
defaultStoreID: Parameters.defaultStoreID) { (settings, error) in
53+
applicationVersion: Parameters.applicationVersion) { (settings, error) in
7454

7555
XCTAssertNotNil(error)
7656
XCTAssertNil(settings)
@@ -124,6 +104,5 @@ private enum Parameters {
124104
identifierForVendor: "1234")
125105
static let applicationId = "9"
126106
static let applicationVersion = "99"
127-
static let defaultStoreID: Int64 = 1234
128107
static let dotcomDeviceID = "1234"
129108
}

Modules/Tests/YosemiteTests/Stores/NotificationStoreTests.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,7 @@ class NotificationStoreTests: XCTestCase {
364364
let (device, error): (DotcomDevice?, Error?) = waitFor { promise in
365365
let action = NotificationAction.registerDevice(device: self.sampleAPNSDevice(),
366366
applicationId: self.sampleApplicationID,
367-
applicationVersion: self.sampleApplicationVersion,
368-
defaultStoreID: self.sampleDefaultStoreID) { (device, error) in
367+
applicationVersion: self.sampleApplicationVersion) { (device, error) in
369368
promise((device, error))
370369
}
371370
noteStore.onAction(action)
@@ -389,8 +388,7 @@ class NotificationStoreTests: XCTestCase {
389388
let (device, error): (DotcomDevice?, Error?) = waitFor { promise in
390389
let action = NotificationAction.registerDevice(device: self.sampleAPNSDevice(),
391390
applicationId: self.sampleApplicationID,
392-
applicationVersion: self.sampleApplicationVersion,
393-
defaultStoreID: self.sampleDefaultStoreID) { (device, error) in
391+
applicationVersion: self.sampleApplicationVersion) { (device, error) in
394392
promise((device, error))
395393
}
396394
noteStore.onAction(action)
@@ -490,12 +488,6 @@ private extension NotificationStoreTests {
490488
return "1234"
491489
}
492490

493-
/// Returns a sample Default Store ID
494-
///
495-
var sampleDefaultStoreID: Int64 {
496-
return 1234
497-
}
498-
499491
/// Returns a sample Apple Device
500492
///
501493
func sampleAPNSDevice() -> APNSDevice {

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
-----
66
- [*] Show specific error when a variation is missing at POS checkout via WPCom login [https://github.com/woocommerce/woocommerce-ios/pull/16430]
77
- [Internal] Moved the request for push notification authorization after login [https://github.com/woocommerce/woocommerce-ios/pull/16428]
8+
- [Internal] Cleaned up logic for push notification token registration [https://github.com/woocommerce/woocommerce-ios/pull/16434]
89
- [*] Fixed possible sync issue in POS (https://github.com/woocommerce/woocommerce-ios/pull/16423)
910

1011
23.8

WooCommerce/Classes/AppDelegate.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
112112
}
113113

114114
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
115-
guard let defaultStoreID = ServiceLocator.stores.sessionManager.defaultStoreID else {
116-
return
117-
}
118-
119-
ServiceLocator.pushNotesManager.registerDeviceToken(with: deviceToken, defaultStoreID: defaultStoreID)
115+
ServiceLocator.pushNotesManager.registerDeviceToken(with: deviceToken)
120116
}
121117

122118
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {

WooCommerce/Classes/Notifications/PushNotificationsManager.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ extension PushNotificationsManager {
219219
/// - tokenData: APNS's Token Data
220220
/// - defaultStoreID: Default WooCommerce Store ID
221221
///
222-
func registerDeviceToken(with tokenData: Data, defaultStoreID: Int64) {
222+
func registerDeviceToken(with tokenData: Data) {
223223
let newToken = tokenData.hexString
224224

225225
if let _ = deviceToken, deviceToken != newToken {
@@ -231,7 +231,7 @@ extension PushNotificationsManager {
231231
deviceToken = newToken
232232

233233
// Register in the Dotcom's Infrastructure
234-
registerDotcomDevice(with: newToken, defaultStoreID: defaultStoreID) { (device, error) in
234+
registerDotcomDevice(with: newToken) { (device, error) in
235235
guard let deviceID = device?.deviceID else {
236236
DDLogError("⛔️ Dotcom Push Notifications Registration Failure: \(error.debugDescription)")
237237
return
@@ -556,12 +556,11 @@ private extension PushNotificationsManager {
556556

557557
/// Registers an APNS DeviceToken in the WordPress.com backend.
558558
///
559-
func registerDotcomDevice(with deviceToken: String, defaultStoreID: Int64, onCompletion: @escaping (DotcomDevice?, Error?) -> Void) {
559+
func registerDotcomDevice(with deviceToken: String, onCompletion: @escaping (DotcomDevice?, Error?) -> Void) {
560560
let device = APNSDevice(deviceToken: deviceToken)
561561
let action = NotificationAction.registerDevice(device: device,
562562
applicationId: WooConstants.pushApplicationID,
563563
applicationVersion: Bundle.main.version,
564-
defaultStoreID: defaultStoreID,
565564
onCompletion: onCompletion)
566565
stores.dispatch(action)
567566
}

WooCommerce/Classes/ServiceLocator/PushNotesManager.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ protocol PushNotesManager {
7272
///
7373
/// - Parameters:
7474
/// - tokenData: APNS's Token Data
75-
/// - defaultStoreID: Default WooCommerce Store ID
7675
///
77-
func registerDeviceToken(with tokenData: Data, defaultStoreID: Int64)
76+
func registerDeviceToken(with tokenData: Data)
7877

7978
/// Handles a remote push notification payload when the app is in the background.
8079
/// - Parameter userInfo: Push notification payload.

WooCommerce/Classes/Yosemite/DefaultStoresManager.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ class DefaultStoresManager: StoresManager {
270270
sessionManager.deleteApplicationPassword(locally: true)
271271
ServiceLocator.analytics.refreshUserData()
272272
ZendeskProvider.shared.reset()
273-
ServiceLocator.pushNotesManager.unregisterForRemoteNotifications {}
274273
}
275274

276275
/// Fully deauthenticates the user, if needed.

0 commit comments

Comments
 (0)