Skip to content

Commit 6a8838e

Browse files
committed
Updates based on CR suggestions.
1 parent 8225f27 commit 6a8838e

File tree

6 files changed

+19
-26
lines changed

6 files changed

+19
-26
lines changed

WooCommerce/Classes/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ extension AppDelegate {
421421

422422
extension AppDelegate: UNUserNotificationCenterDelegate {
423423
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async {
424-
await ServiceLocator.pushNotesManager.handleUserResponseToNotification(response: response)
424+
await ServiceLocator.pushNotesManager.handleUserResponseToNotification(response)
425425
}
426426

427427
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification) async -> UNNotificationPresentationOptions {

WooCommerce/Classes/Notifications/PushNotificationsManager.swift

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ final class PushNotificationsManager: PushNotesManager {
4747

4848
/// An observable that emits values when a local notification is received.
4949
///
50-
var localNotificationResponses: AnyPublisher<UNNotificationResponse, Never> {
50+
var localNotificationUserResponses: AnyPublisher<UNNotificationResponse, Never> {
5151
localNotificationResponsesSubject.eraseToAnyPublisher()
5252
}
5353

@@ -268,27 +268,25 @@ extension PushNotificationsManager {
268268
}
269269

270270
@MainActor
271-
func handleUserResponseToNotification(response: UNNotificationResponse) async {
271+
func handleUserResponseToNotification(_ response: UNNotificationResponse) async {
272272
// Remote notification response is handled separately.
273273
if let notification = PushNotification.from(userInfo: response.notification.request.content.userInfo) {
274274
handleRemoteNotificationInAllAppStates(response.notification.request.content.userInfo)
275-
return await handleInactiveRemoteNotification(notification: notification)
275+
await handleInactiveRemoteNotification(notification: notification)
276276
} else {
277277
localNotificationResponsesSubject.send(response)
278278
}
279279
}
280280

281-
/// Handles a Notification while in Background Mode
282-
///
283-
/// - Parameters:
284-
/// - userInfo: The Notification's Payload
285-
/// - completionHandler: A callback, to be executed on completion
286-
///
287-
/// - Returns: True when handled. False otherwise
281+
/// Handles a remote notification while the app is in the background.
288282
///
283+
/// - Parameter userInfo: The notification's payload.
284+
/// - Returns: Whether there is any data fetched in the background.
289285
@MainActor
290286
func handleRemoteNotificationInTheBackground(userInfo: [AnyHashable: Any]) async -> UIBackgroundFetchResult {
291-
guard applicationState == .background, let _ = userInfo[APNSKey.identifier] else {
287+
guard applicationState == .background, // Proceeds only if the app is in background.
288+
let _ = userInfo[APNSKey.identifier] // Ensures that we are only processing a remote notification.
289+
else {
292290
return .noData
293291
}
294292

@@ -449,14 +447,9 @@ private extension PushNotificationsManager {
449447
_ = handleSupportNotification(userInfo)
450448
}
451449

452-
/// Handles a Remote Notification while in Inactive Mode
453-
///
454-
/// - Parameters:
455-
/// - userInfo: The Notification's Payload
456-
/// - completionHandler: A callback, to be executed on completion
457-
///
458-
/// - Returns: True when handled. False otherwise
450+
/// Handles a remote notification while the app is inactive.
459451
///
452+
/// - Parameter notification: Push notification content from a remote notification.
460453
func handleInactiveRemoteNotification(notification: PushNotification) async {
461454
guard applicationState == .inactive else {
462455
return

WooCommerce/Classes/ServiceLocator/PushNotesManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protocol PushNotesManager {
2222

2323
/// An observable that emits values when a local notification response is received.
2424
///
25-
var localNotificationResponses: AnyPublisher<UNNotificationResponse, Never> { get }
25+
var localNotificationUserResponses: AnyPublisher<UNNotificationResponse, Never> { get }
2626

2727
/// Resets the Badge Count.
2828
///
@@ -73,7 +73,7 @@ protocol PushNotesManager {
7373

7474
/// Handles user's response to a local or remote notification.
7575
/// - Parameter response: The user's response to a notification.
76-
func handleUserResponseToNotification(response: UNNotificationResponse) async
76+
func handleUserResponseToNotification(_ response: UNNotificationResponse) async
7777

7878
/// Handles a local or remote notification when the app is in the foreground.
7979
///

WooCommerce/Classes/ViewRelated/AppCoordinator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ final class AppCoordinator {
6666
self.isLoggedIn = isLoggedIn
6767
}
6868

69-
localNotificationResponsesSubscription = ServiceLocator.pushNotesManager.localNotificationResponses.sink { [weak self] response in
69+
localNotificationResponsesSubscription = ServiceLocator.pushNotesManager.localNotificationUserResponses.sink { [weak self] response in
7070
self?.handleLocalNotificationResponse(response)
7171
}
7272
}

WooCommerce/WooCommerceTests/Mocks/MockPushNotificationsManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class MockPushNotificationsManager: PushNotesManager {
2424

2525
private let inactiveNotificationsSubject = PassthroughSubject<PushNotification, Never>()
2626

27-
var localNotificationResponses: AnyPublisher<UNNotificationResponse, Never> {
27+
var localNotificationUserResponses: AnyPublisher<UNNotificationResponse, Never> {
2828
localNotificationResponsesSubject.eraseToAnyPublisher()
2929
}
3030

@@ -66,7 +66,7 @@ final class MockPushNotificationsManager: PushNotesManager {
6666
.noData
6767
}
6868

69-
func handleUserResponseToNotification(response: UNNotificationResponse) async {
69+
func handleUserResponseToNotification(_ response: UNNotificationResponse) async {
7070

7171
}
7272

WooCommerce/WooCommerceTests/Notifications/PushNotificationsManagerTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ final class PushNotificationsManagerTests: XCTestCase {
313313

314314
// When
315315
application.applicationState = .inactive
316-
await manager.handleUserResponseToNotification(response: response)
316+
await manager.handleUserResponseToNotification(response)
317317

318318
// Then
319319
XCTAssertEqual(application.presentDetailsNoteIDs.first, 1234)
@@ -457,7 +457,7 @@ final class PushNotificationsManagerTests: XCTestCase {
457457
let response = try XCTUnwrap(MockNotificationResponse(notificationUserInfo: userinfo))
458458

459459
// When
460-
_ = await manager.handleUserResponseToNotification(response: response)
460+
_ = await manager.handleUserResponseToNotification(response)
461461

462462
// Then
463463
XCTAssertEqual(emittedNotifications.count, 1)

0 commit comments

Comments
 (0)