Update how the app decides whether to accept a push notification#15222
Update how the app decides whether to accept a push notification#15222
Conversation
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
|
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## trunk #15222 +/- ##
=========================================
Coverage 38.77% 38.77%
- Complexity 10611 10613 +2
=========================================
Files 2201 2201
Lines 125148 125157 +9
Branches 17354 17358 +4
=========================================
+ Hits 48530 48535 +5
- Misses 71698 71700 +2
- Partials 4920 4922 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hey @irfano the code changes look good, however, I think we can do this in a cleaner way once we merge the changes from the PR I'll open tomorrow early morning (I'm wrapping up testing changes): #15238. |
…system - Bypass user ID and `remoteNoteId` validation checks when `WOO_PUSH_NOTIFICATIONS_SYSTEM` feature flag is enabled. - Skip WPCOM notifications when the app is registered with Woo Core to avoid duplicates.
…ComPushNotificationStore
…tatus in NotificationMessageHandlerTest
823bd27 to
8a42fa9
Compare
|
I've rebased onto your branch. Let's merge yours first since this is smaller. I agree that using |
… issue/WOOMOB-1957-update-how-decide-whether-accept-pn
| val notification = notificationModel.toAppModel(resourceProvider) | ||
| if (notification.remoteNoteId == 0L) { | ||
| val isRegisteredForWooPush = runBlocking { | ||
| registrationStatus(notification.remoteSiteId) == PushNotificationRegistrationStatus.Status.WOO_REGISTERED |
There was a problem hiding this comment.
I think this check should also include the case were user is registered in both systems, right?
| registrationStatus(notification.remoteSiteId) == PushNotificationRegistrationStatus.Status.WOO_REGISTERED | |
| val isRegisteredForWooPush = runBlocking { | |
| val registrationStatus = registrationStatus(notification.remoteSiteId) | |
| registrationStatus == PushNotificationRegistrationStatus.Status.REGISTERED_IN_BOTH | |
| || registrationStatus == PushNotificationRegistrationStatus.Status.WOO_REGISTERED | |
| } |
The most likely case were we get duplicates is when the user is registered in both systems (even though PN should be turned off in WP.com system)
There was a problem hiding this comment.
Please don’t follow commits for the review, I’ve synced with the base branch many times since this PR has been open for a while.
| val notification = notificationModel.toAppModel(resourceProvider) | ||
| if (notification.remoteNoteId == 0L) { | ||
| val isRegisteredForWooPush = runBlocking { | ||
| registrationStatus(notification.remoteSiteId) == PushNotificationRegistrationStatus.Status.REGISTERED_BOTH |
There was a problem hiding this comment.
I think we should still include PushNotificationRegistrationStatus.Status.REGISTERED_WOO_ONLY in this check too.
While it might be a corner case I can see how we can end in a situation were locally, the app thinks the user is only registered in WOO system only, however their site might still be registered in both PN systems in the backend side. For example, if user is registered in WP.com system and fails to unregister device on log out and then logs in again and registers successfully in Woo system but fails to turn off notifications in WP.com.
That's just one case but I think there could be others. To stay on the safe side I'd check either values REGISTERED_BOTH || REGISTERED_WOO_ONLY
There was a problem hiding this comment.
I'm not sure what happened exactly, but when I added this comment to the PR this morning I would've sworn that the PushNotificationRegistrationStatus.Status.REGISTERED_WOO_ONLY was not present in the code. Look like it is now. So all good 👍🏼
There was a problem hiding this comment.
I actually included PushNotificationRegistrationStatus.Status.REGISTERED_WOO_ONLY and PushNotificationRegistrationStatus.Status.REGISTERED_BOTH after your feedback, but I think I messed it up while resolving conflicts.
I re-added it today in commit 891dff474a77593f0da8181b34a65cd48905144a. That's why I commented "don't follow my commits" 😅
Anyway, thanks for the review.
JorgeMucientes
left a comment
There was a problem hiding this comment.
LGTM! Nice work @irfano
| if (!accountStore.hasAccessToken()) { | ||
| wooLog.e(NOTIFICATIONS, "User is not logged in!") | ||
| return | ||
| } |
There was a problem hiding this comment.
Out of scope for this PR but we probably need to update this as this condition will be false for all users loggin in with site credentials.
Can you create a nwe Linear task and tackle that @irfano 🙏🏼
Closes WOOMOB-1957
Description
This PR adds deduplication logic to
NotificationMessageHandlerto prevent duplicate push notifications. WhenWOO_PUSH_NOTIFICATIONS_SYSTEMfeature flag is enabled, we check if the incoming notification is from WPCOM (note_id > 0) and if the device is already registered with Woo Core (hasPushToken()). If both conditions are true, we skip the WPCOM notification since the same event will also arrive via Woo Core.Test Steps
Images/gif
RELEASE-NOTES.txtif necessary. Use the "[Internal]" label for non-user-facing changes.