-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jetpack Focus: Disable Notifications For WordPress app when Jetpack notifications enabled - Part 1 #19531
Conversation
…bling notifications on WordPress
WordPress/WordPressNotificationServiceExtension/Sources/NotificationService.swift
Outdated
Show resolved
Hide resolved
Here's the draft. You can take a look at the code or the video if you find it interesting. |
You can test the changes in WordPress from this Pull Request by:
|
You can test the changes in Jetpack from this Pull Request by:
|
…ification filtering logic
Opening PR. I tried to move most of the logic into one class so it could be tested and also be ready to be more easily removed once the migration is complete. This is also open for testing. Have in mind that filtered notifications appear with "Filtered" message for now and won't appear once the entitlement is added. I still think it's good to test it to find problems and potential uncovered edge cases. |
I created a separate task for local notifications. It could be implemented in separate PR and then merged into this branch. |
Thanks for this, @staskus! The test cases and video look good. I'll review today. |
One thing I noticed is that push notifications don't work on the installable builds. This rings a bell but caught me out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving a partial review here, I tested but haven't dived into the code:
✅ Case 1
✅ Case 2 - the feature flag was already turned on, is that what you see?
✅ Case 3 - shouldn't this be called "Jetpack + Feature Flag"?
✅ Case 4
✅ Case 5
✅ Case 6
✅ Case 7
Judging from the test, this is looking like a promising solution to disabling WP notifications when users migrate to JP (and enable its notifications). Nice work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@staskus This LGTM! All test cases pass for me. I have just left a couple of comments thanks
private var notificationsEnabled: Bool = false | ||
private let allowDisablingWPNotifications: Bool | ||
private let isWordPress: Bool | ||
private let userDefaults = UserDefaults(suiteName: WPAppGroupName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should add a comment here that this class and solution uses App Groups which allows JetPack app to set the state of wordPressNotificationsEnabled since both WordPress and JetPack are using the same AppGroup name? While testing + reviewing the solution it took me awhile to understand what was going on until I saw WPAppGroupName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Adding it to the description. 👍
/// A temporary setting to allow controlling WordPress notifications when they are disabled after Jetpack installation | ||
/// Disable WordPress notifications when they are enabled on Jetpack | ||
func disableWordPressNotificationsIfNeeded() { | ||
let notificationFilteringService = NotificationFilteringService() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit - perhaps we don't need to assign the local variable here anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to keep it as it is for now.
I think it's more natural readability to have
notificationFilteringService.disableWordPressNotificationsIfNeeded()
rather than NotificationFilteringService().disableWordPressNotificationsIfNeeded()
although of course it's subjective and there're no clear guidelines regarding that.
Given this PR still has "WIP" in the title on the Friday before the upcoming 21.2 code freeze on Monday, I'll move it to the 21.3 milestone. Feel free to push back to 21.2 if this gets finished and reviewed in the meantime 😄 |
This reverts commit 323fdb1.
Updated the PR by including remoteKey, identical to Android, following the example of another feature flags PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the changes with 'filtered' / mock notification and as discussed with @staskus this doesn't need re-testing.
Merging the changes with the feature flag disabled. It does not affect production right now. Local notification and entitlement changes will be done in other PRs. |
} | ||
|
||
init(notificationSettingsLoader: NotificationSettingsLoader = UNUserNotificationCenter.current(), | ||
allowDisablingWPNotifications: Bool = FeatureFlag.allowDisablingWPNotifications.enabled, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @staskus 👋
I noticed you've added a remote feature flag. Just wanted to note that directly using FeatureFlag.enabled
does not return the remote value, instead, it returns the flag's default value.
We're aware that it's a bit confusing and we'll try to make it more intuitive in the next iteration.
For now, in order to retrieve the remote value, you'll have to do this:
allowDisablingWPNotifications: Bool = FeatureFlag.allowDisablingWPNotifications.enabled, | |
allowDisablingWPNotifications: Bool = RemoteFeatureFlagStore().value(for: FeatureFlag.allowDisablingWPNotifications), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for letting me know! I'll make a change. I thought setting a remoteKey
is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify, remote feature flags cannot be overridden in the Debug menu, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ability has just been added through #19645 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🫡 thanks!
Description
A part of solution for disabling notifications on WordPress app during Jetpack Focus.
It is missing enable [Notification Filtering Entitlement](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_usernotifications_filtering and Local Notifications](#19560). They will be added on the other PRs.
All the changes are under the feature flag and won't affect production.
Solution
Solution relies on Notification Filtering Entitlement , that allows to decide not to show notification at the moment of the arrival.
WPNotificationsEnabledKey
keyWPNotificationsEnabledKey
when Jetpack notifications are enabledWPNotificationsEnabledKey
inNotificationService
and skip showing notification if it's falseNotification Settings
(similar to Android), that allow to reenable notification (see video)Testing instructions
Case 1: WordPress + Receive Notifications
Case 2: WordPress + Feature Flag
Case 3: Jetpack + Feature Flag
Case 4: WordPress + Jetpack + Jetpack Enable Notifications + Receive Notifications
Case 5: WordPress Reenable Notifications
Case 6: WordPress Disable Feature Flag
Case 7: WordPress + Jetpack + Jetpack No Notifications + Receive Notifications
Regression Notes
Disabling
WordPress
notifications without indenting toMoved all the logic to
NotificationFilteringService
and tested the casesNotificationFilteringServiceTests
to test all the underlying logic that determines when we should allow filtering or filter notifications.PR submission checklist:
RELEASE-NOTES.txt
if necessary.Images & Videos
Testing.notifications.small.mov