-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Bug 1809444: Add Worker to generate Notifications using Nimbus messaging #28605
Conversation
@@ -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" |
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.
these are unused
cc0d9f3
to
6a945a8
Compare
… messages and create a notification configured using the highest priority new message (if available).
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 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!
import org.mozilla.fenix.onboarding.MARKETING_CHANNEL_ID | ||
import org.mozilla.fenix.utils.IntentUtils | ||
import org.mozilla.fenix.utils.createBaseNotification |
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: might MARKETING_CHANNEL_ID
move to the same place as createBaseNotification
?
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 think it's more closely aligned with the helper class at the moment tbh, but we can look at it in the next issue 👍
nextMessage?.apply { | ||
if (shouldDisplayMessage()) { | ||
val nimbusMessagingController = NimbusMessagingController(messagingStorage) |
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.
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) |
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.
Is this test missing?
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.
yes, good spot!
coVerify { storage.updateMetadata(message.metadata.copy(dismissed = true)) } | ||
} | ||
assertEquals(expectedMessage, controller.updateMessageAsDisplayed(message)) | ||
} |
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.
😻
val action = messagingController.processMessageAction(message) | ||
handleAction(action) | ||
appStore.dispatch(MessageClicked(message)) | ||
with(message) { |
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: is this with
necessary here?
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.
Agree it's probably overkill now
return Result.success() | ||
} | ||
|
||
private fun Message.shouldDisplayMessage() = metadata.displayCount == 0 |
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.
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) |
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.
Note to future self: this is temporary while awaiting EXP-3068.
val notificationManagerCompat = NotificationManagerCompat.from(this) | ||
if (notificationManagerCompat.isNotificationChannelEnabled(MARKETING_CHANNEL_ID)) { |
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.
Triple checking here: has onboarding already run by now? Has the user been asked for permission?
Also: should we be using areNotificationsEnabledSafe
?
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.
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 🙂
…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>
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 inMessage
- tests updated accordingly.Moved the bulk of the
Notification
builder logic into separate file as commonality is shared by allWorker
s.Demo:
Screen.Recording.2023-01-10.at.14.26.25.mov
Pull Request checklist
QA
To download an APK when reviewing a PR (after all CI tasks finished running):
Checks
at the top of the PR page.firefoxci-taskcluster
group on the left to expand all tasks.build-debug
task.View task in Taskcluster
in the newDETAILS
section.GitHub Automation
Used by GitHub Actions.