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

notifications: Open to unreads from summary notification. #5472

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,26 @@ private fun updateNotification(
}.build()
messagingStyle.addMessage(fcmMessage.content, fcmMessage.timeMs, sender)


// See these sections in the Android docs:
// https://developer.android.com/guide/components/activities/tasks-and-back-stack#TaskLaunchModes
// https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_CLEAR_TOP
//
// * From the doc on `PendingIntent.getActivity` at
// https://developer.android.com/reference/android/app/PendingIntent#getActivity(android.content.Context,%20int,%20android.content.Intent,%20int)
// > Note that the activity will be started outside of the context of an
// > existing activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK
// > launch flag in the Intent.
//
// * The flag FLAG_ACTIVITY_CLEAR_TOP is mentioned as being what the
// notification manager does; so use that. It has no effect as long
// as we only have one activity; but if we add more, it will destroy
// all the activities on top of the target one.
//
// * These flags get created up here so that we can use them for both
// the notification and the summary notification.
val intentFlags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP

val notification = NotificationCompat.Builder(context, CHANNEL_ID).apply {
setGroup(groupKey)

Expand Down Expand Up @@ -323,23 +343,7 @@ private fun updateNotification(
setContentIntent(
PendingIntent.getActivity(context, 0,
Intent(Intent.ACTION_VIEW, intentUrl, context, MainActivity::class.java)
.setFlags(
// See these sections in the Android docs:
// https://developer.android.com/guide/components/activities/tasks-and-back-stack#TaskLaunchModes
// https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_CLEAR_TOP
//
// * From the doc on `PendingIntent.getActivity` at
// https://developer.android.com/reference/android/app/PendingIntent#getActivity(android.content.Context,%20int,%20android.content.Intent,%20int)
// > Note that the activity will be started outside of the context of an
// > existing activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK
// > launch flag in the Intent.
//
// * The flag FLAG_ACTIVITY_CLEAR_TOP is mentioned as being what the
// notification manager does; so use that. It has no effect as long
// as we only have one activity; but if we add more, it will destroy
// all the activities on top of the target one.
Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
)
.setFlags(intentFlags)
.putExtra(EXTRA_NOTIFICATION_DATA, bundleOf(*fcmMessage.dataForOpen())),
Copy link
Member

Choose a reason for hiding this comment

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

Here's the line in the existing code where we supply the data that the JS side of the app relies on in order to know where it should navigate to when opening the notification.

Copy link
Author

Choose a reason for hiding this comment

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

Depending on the outcome of the below, I take it we would want a dataForSummaryOpen that only includes the realm_uri and user_id?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, that sounds good.

PendingIntent.FLAG_IMMUTABLE))
setAutoCancel(true)
Expand All @@ -361,7 +365,11 @@ private fun updateNotification(
// (See example in the linked doc.)
)

// TODO Does this do something useful? There isn't a way to open these summary notifs.
setContentIntent(
PendingIntent.getActivity(context, 0,
Intent(context, MainActivity::class.java)
.setFlags(intentFlags),
PendingIntent.FLAG_IMMUTABLE))
setAutoCancel(true)
}.build()

Expand Down