Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Bug 1809444: Add Worker to generate Notifications using Nimbus messaging #28605

Merged
merged 3 commits into from
Jan 23, 2023

Conversation

t-p-white
Copy link
Contributor

Part of Notification Epic

Fixes EXP-2993

Added a MessageNotificationWorker to poll Nimbus for new messages and create a notification configured using the highest priority new message (if available).

Updated the messaging.fml.yaml notification polling duration values as discussed with @jhugman and added test-notification value for messages.

Refactored DefaultMessageController handleAction fun - the intent creation logic is now in Message - tests updated accordingly.

Moved the bulk of the Notification builder logic into separate file as commonality is shared by all Workers.

Demo:

Screen.Recording.2023-01-10.at.14.26.25.mov

Pull Request checklist

  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Screenshots: This PR includes screenshots or GIFs of the changes made or an explanation of why it does not
  • Accessibility: The code in this PR follows accessibility best practices or does not include any user facing features. In addition, it includes a screenshot of a successful accessibility scan to ensure no new defects are added to the product.

QA

  • QA Needed

To download an APK when reviewing a PR (after all CI tasks finished running):

  1. Click on Checks at the top of the PR page.
  2. Click on the firefoxci-taskcluster group on the left to expand all tasks.
  3. Click on the build-debug task.
  4. Click on View task in Taskcluster in the new DETAILS section.
  5. The APK links should be on the right side of the screen, named for each CPU architecture.

GitHub Automation

Used by GitHub Actions.

@t-p-white t-p-white added the pr:work-in-progress PRs that are not ready to be reviewed yet and are actively being worked on label Jan 20, 2023
@t-p-white t-p-white requested review from a team as code owners January 20, 2023 14:25
@@ -1143,8 +1153,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
const val OPEN_TO_BROWSER_AND_LOAD = "open_to_browser_and_load"
const val OPEN_TO_SEARCH = "open_to_search"
const val PRIVATE_BROWSING_MODE = "private_browsing_mode"
const val EXTRA_DELETE_PRIVATE_TABS = "notification_delete_and_open"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are unused

@t-p-white
Copy link
Contributor Author

t-p-white commented Jan 20, 2023

Original PR

@t-p-white t-p-white added needs:review PRs that need to be reviewed and removed pr:work-in-progress PRs that are not ready to be reviewed yet and are actively being worked on labels Jan 20, 2023
@t-p-white t-p-white force-pushed the 1809444 branch 4 times, most recently from cc0d9f3 to 6a945a8 Compare January 23, 2023 11:14
… messages and create a notification configured using the highest priority new message (if available).
Copy link
Contributor

@jhugman jhugman left a comment

Choose a reason for hiding this comment

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

This is looking very nice now.

I have left a few nits and questions, but not enough to slow things down with another review cycle. Please address these, then land.

Good job, Tom!

Comment on lines +25 to +27
import org.mozilla.fenix.onboarding.MARKETING_CHANNEL_ID
import org.mozilla.fenix.utils.IntentUtils
import org.mozilla.fenix.utils.createBaseNotification
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: might MARKETING_CHANNEL_ID move to the same place as createBaseNotification?

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 think it's more closely aligned with the helper class at the moment tbh, but we can look at it in the next issue 👍

Comment on lines 49 to 51
nextMessage?.apply {
if (shouldDisplayMessage()) {
val nimbusMessagingController = NimbusMessagingController(messagingStorage)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we remove some of the nesting here? e.g.

val nextMessage = messagingStorage.getNextMessage(
                                         MessageSurfaceId.NOTIFICATION, 
                                          messages
                                ) ?: return@launch
if (!nextMessage.shouldDisplay()) {
  return@launch
}
val nimbusMessagingController = NimbusMessagingController(messagingStorage)
// … etc

fun `GIVEN a URL with a {uuid} WHEN calling createMessageAction THEN record a messageClicked event with a uuid`() {
val message = createMessage("id-1", action = "http://mozilla.org?uuid={uuid}")
val uuid = UUID.randomUUID().toString()
every { storage.getMessageAction(any()) } returns Pair(uuid, message.action)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this test missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, good spot!

coVerify { storage.updateMetadata(message.metadata.copy(dismissed = true)) }
}
assertEquals(expectedMessage, controller.updateMessageAsDisplayed(message))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

😻

val action = messagingController.processMessageAction(message)
handleAction(action)
appStore.dispatch(MessageClicked(message))
with(message) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: is this with necessary here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree it's probably overkill now

return Result.success()
}

private fun Message.shouldDisplayMessage() = metadata.displayCount == 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to future self: this is temporary while awaiting EXP-3069.


// Generate the processed Message action
val processedAction = nimbusMessagingController.processMessageActionToUri(this)
val actionIntent = Intent(Intent.ACTION_VIEW, processedAction)
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to future self: this is temporary while awaiting EXP-3068.

Comment on lines +429 to +430
val notificationManagerCompat = NotificationManagerCompat.from(this)
if (notificationManagerCompat.isNotificationChannelEnabled(MARKETING_CHANNEL_ID)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Triple checking here: has onboarding already run by now? Has the user been asked for permission?

Also: should we be using areNotificationsEnabledSafe?

Copy link
Contributor Author

@t-p-white t-p-white Jan 23, 2023

Choose a reason for hiding this comment

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

Yep 👍 line 336 showNotificationPermissionPromptIfRequired() will ensure the dialog is displayed if needed.

On a fresh install:
Application is loaded, onResume is called before showNotificationPermissionPromptIfRequired dialog is displayed - will fail at isNotificationChannelEnabled check. This will be followed by the permission dialog which once closed/dismissed will trigger onResume again where we will check for persmission.

areNotificationsEnabledSafe check is used as part of isNotificationChannelEnabled 🙂

@t-p-white t-p-white added pr:needs-landing-squashed PRs that are ready to land (squashed) [Will be merged by Mergify] and removed needs:review PRs that need to be reviewed labels Jan 23, 2023
@mergify mergify bot merged commit 37411c0 into mozilla-mobile:main Jan 23, 2023
JohanLorenzo pushed a commit to mozilla-releng/staging-firefox-android that referenced this pull request Jan 25, 2023
…s messaging (mozilla-mobile/fenix#28605)

* For 1809444: Added a MessageNotificationWorker to poll Nimbus for new messages and create a notification configured using the highest priority new message (if available).

* For 1809444: Changes from PR review

Co-authored-by: t-p-white <t-p-white>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr:needs-landing-squashed PRs that are ready to land (squashed) [Will be merged by Mergify]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants