phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.91k forks source link

[Feature] Variable Notification Title #2200

Open lucasbasquerotto opened 6 years ago

lucasbasquerotto commented 6 years ago

I would like to know if there is a way to use diffent titles according to the number of push notifications received in an Android Device using FCM (like New Message for 1 message received and New Messages for more than 1).

This would be especially helpful with topics, because I can't send a customized title per user.

From what I see there is no way. If this is the case, could this became a possible feature request? (even if with a low priority)

I've never changed a plugin code and don't know exactly how they work, but I think in the following line is where the notification title is defined for Android:

https://github.com/phonegap/phonegap-plugin-push/blob/58e87593e749d5c6da2a45906a8c7c9309d6b09a/src/android/com/adobe/phonegap/push/FCMService.java#L669

There you have the number of push notifications received (Integer sizeList = messageList.size();), and could verify if there is exactly 1. In such case, it could use something like (just an example, the name could change) String titleToUse = sizeList.equals(1) ? TITLE_1 : TITLE.

I think here is where the extra bundle is populated:

https://github.com/phonegap/phonegap-plugin-push/blob/58e87593e749d5c6da2a45906a8c7c9309d6b09a/src/android/com/adobe/phonegap/push/FCMService.java#L80

It could add something like extras.putString(TITLE_1, message.getNotification().getTitle1()); (by creating a field title1 in the Notification class). This would be used only if there is 1 notification received (and only if defined, otherwise use the default title).

The data to send in the back-end would be like:

data: {
    title: 'New messages',
    title1: 'New message',
    ...
}

There would be some considerations to do, like in the case of a localized title, and it could be better to add a variable title name, for variable titles according to the number of messages.

So I would like to know if this could be considered.

Thanks in advance.

macdonst commented 6 years ago

@lucasbasquerotto I think what you are looking for is Inbox Stacking. That is the recommended way on Android of doing what you want.

https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#inbox-stacking

I won't be working on this as a feature request as it goes against Android best practices.

lucasbasquerotto commented 6 years ago

@macdonst I may not have been clear enough. Actually, I'm using inbox stack and the summaryText property and they are working fine. When I expand the notification I see something like 3 new messages at the bottom, for example.

The problem is that the notification title is always New message (it's fixed, even when there are more than 1 message). I could be using a fixed title New Messages (plural), but it will be wrong in case of only 1 message.

So what I'm proposing is a dynamic title, based on the number of push notifications stacked (the title that is shown on the notification, even when it is not expanded).

It would be good also to show the summary text (when there is more than 1 stacked) when the notification is not expanded in the body (instead of the last push notification), and only when the notification is expanded I would see the individual notifications, like I see with Whatsapp, Facebook Messenger, Gmail, and so on (at least in my phone, Moto G2). So the title could be New Notifications, in the body You have 3 notifications., and when the notification is expanded I would see the 3 individual notifications in the body and the summary text would be in the bottom.

Although this is what is desired in my case, I don't know the complexity of the implementation, and I am only proposing here about a dynamic title (I don't want to show the summaryText in the title (if that is what it seemed), just a singular or plural title. It would be specially helpful with topics, because the same payload goes to everyone.

macdonst commented 6 years ago

@lucasbasquerotto okay, I believe you want messages grouped. Look at this page:

https://material.io/guidelines/patterns/notifications.html#notifications-behavior

and scroll down to "Summarizing". Is that what you are looking for?