Skip to content
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

Merged
merged 17 commits into from
Nov 14, 2022

Conversation

staskus
Copy link
Contributor

@staskus staskus commented Oct 27, 2022

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.

  1. Add WPNotificationsEnabledKey key
  2. Disable WPNotificationsEnabledKey when Jetpack notifications are enabled
  3. Check for WPNotificationsEnabledKey in NotificationService and skip showing notification if it's false
  4. Additionally creating a switch inside Notification Settings (similar to Android), that allow to reenable notification (see video)

Testing instructions

Case 1: WordPress + Receive Notifications

  1. Install and log in to the WordPress app
  2. Enable notifications
  3. Confirm that push notifications are received

Case 2: WordPress + Feature Flag

  1. Install and log in to the WordPress app
  2. Enable "Disable WordPress app notifications when Jetpack is installed" (App Settings -> Debug) feature flag
  3. Go to Notifications
  4. Go to App Notification Settings
  5. Confirm that "Allow Notifications" switch is visible

Case 3: Jetpack + Feature Flag

  1. Repeat Case 2 for Jetpack app
  2. Confirm that "Allow Notifications" switch is not visible

Case 4: WordPress + Jetpack + Jetpack Enable Notifications + Receive Notifications

  1. Install and log in to the WordPress app, enable feature flag, enable notifications
  2. Install and log in to the Jetpack app, enable feature flag, enable notifications
  3. Receive push notifications
  4. Jetpack notifications should appear, WordPress notifications should be filtered

Case 5: WordPress Reenable Notifications

  1. Continue Case 4
  2. Go to WordPress
  3. Notifications
  4. Notifications Settings
  5. Enable "Allow Notifications" Switch
  6. Receive push notifications
  7. Both Jetpack and WordPress notifications should appear

Case 6: WordPress Disable Feature Flag

  1. Continue Case 4
  2. Disable "Disable WordPress app notifications when Jetpack is installed" (App Settings -> Debug) feature flag
  3. Receive push notifications
  4. Both Jetpack and WordPress notifications should appear

Case 7: WordPress + Jetpack + Jetpack No Notifications + Receive Notifications

  1. Install and log in to the WordPress app, enable feature flag, enable notifications
  2. Install and log in to the Jetpack app, enable feature flag, don't enable notifications
  3. Receive push notifications
  4. WordPress notifications should appear, Jetpack notifications shouldn't appear

Regression Notes

  1. Potential unintended areas of impact

Disabling WordPress notifications without indenting to

  1. What I did to test those areas of impact (or what existing automated tests I relied on)

Moved all the logic to NotificationFilteringService and tested the cases

  1. What automated tests I added (or what prevented me from doing so)

NotificationFilteringServiceTests to test all the underlying logic that determines when we should allow filtering or filter notifications.

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Images & Videos

Testing.notifications.small.mov

@staskus staskus added this to the 21.2 milestone Oct 27, 2022
@staskus
Copy link
Contributor Author

staskus commented Oct 27, 2022

@guarani

Here's the draft. You can take a look at the code or the video if you find it interesting.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Oct 27, 2022

You can test the changes in WordPress from this Pull Request by:
  • Clicking here or scanning the QR code below to access App Center
  • Then installing the build number pr19531-52b80d8 on your iPhone

If you need access to App Center, please ask a maintainer to add you.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Oct 27, 2022

You can test the changes in Jetpack from this Pull Request by:
  • Clicking here or scanning the QR code below to access App Center
  • Then installing the build number pr19531-52b80d8 on your iPhone

If you need access to App Center, please ask a maintainer to add you.

@staskus staskus requested review from guarani and sla8c November 4, 2022 14:56
@staskus staskus marked this pull request as ready for review November 4, 2022 14:56
@staskus
Copy link
Contributor Author

staskus commented Nov 4, 2022

@sla8c, @guarani

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.

@staskus staskus changed the title [Draft] Jetpack Focus: Disable Notifications For WordPress app when Jetpack notifications enabled [WIP] Jetpack Focus: Disable Notifications For WordPress app when Jetpack notifications enabled Nov 4, 2022
@staskus
Copy link
Contributor Author

staskus commented Nov 4, 2022

I created a separate task for local notifications. It could be implemented in separate PR and then merged into this branch.

@guarani
Copy link
Contributor

guarani commented Nov 4, 2022

Thanks for this, @staskus! The test cases and video look good. I'll review today.

@guarani
Copy link
Contributor

guarani commented Nov 5, 2022

One thing I noticed is that push notifications don't work on the installable builds. This rings a bell but caught me out.
Notifications work when built from Xcode 👍

Copy link
Contributor

@guarani guarani left a 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!

Copy link
Contributor

@sla8c sla8c left a 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)
Copy link
Contributor

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

Copy link
Contributor Author

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()
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@mokagio
Copy link
Contributor

mokagio commented Nov 11, 2022

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 😄

@mokagio mokagio modified the milestones: 21.2, 21.3 Nov 11, 2022
@staskus
Copy link
Contributor Author

staskus commented Nov 12, 2022

Updated the PR by including remoteKey, identical to Android, following the example of another feature flags PR.

@staskus staskus changed the title [WIP] Jetpack Focus: Disable Notifications For WordPress app when Jetpack notifications enabled Jetpack Focus: Disable Notifications For WordPress app when Jetpack notifications enabled - Part 1 Nov 14, 2022
@staskus staskus requested a review from sla8c November 14, 2022 11:12
Copy link
Contributor

@sla8c sla8c left a 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.

@staskus
Copy link
Contributor Author

staskus commented Nov 14, 2022

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,
Copy link
Contributor

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:

Suggested change
allowDisablingWPNotifications: Bool = FeatureFlag.allowDisablingWPNotifications.enabled,
allowDisablingWPNotifications: Bool = RemoteFeatureFlagStore().value(for: FeatureFlag.allowDisablingWPNotifications),

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hassaanelgarem

To clarify, remote feature flags cannot be overridden in the Debug menu, right?

Copy link
Contributor

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 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🫡 thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants