Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

✨ Allow sorting inbox notifications in ascending order #2696

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
49 changes: 47 additions & 2 deletions docs/PAYLOAD.md
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,51 @@ You will get an inbox view so you can display multiple notifications in a single

If you use `%n%` in the `summaryText` of the JSON coming down from FCM it will be replaced by the number of messages that are currently in the queue.

By default, inbox notifications are ordered in descending order (last notification is displayed first). You can use the `inbox-order` parameter to change the order to ascending:

```json
{
"registration_ids": ["my device id"],
"data": {
"title": "My Title",
"message": "My first message",
"style": "inbox",
"inbox-order": "asc",
"summaryText": "There are %n% notifications"
}
}
```

Here is an example using fcm-node that sends the above JSON:

```javascript
const FCM = require('fcm-node');
// Replace these with your own values.
const apiKey = 'replace with API key';
const deviceID = 'my device id';
const fcm = new FCM(apiKey);

const message = {
to: deviceID,
data: {
title: 'My Title',
message: 'My second message',
style: 'inbox',
'inbox-order': 'asc',
summaryText: 'There are %n% notifications'
}
};

fcm.send(message, (err, response) => {
if (err) {
console.log(err);
console.log('Something has gone wrong!');
} else {
console.log('Successfully sent with response: ', response);
}
});
```

## Action Buttons

Your notification can include a maximum of three action buttons. You register the event callback name for each of your actions, then when a user clicks on one of notification's buttons, the event corresponding to that button is fired and the listener you have registered is invoked. For instance, here is a setup with two actions `emailGuests` and `snooze`.
Expand Down Expand Up @@ -2128,12 +2173,12 @@ On iOS, using the FCM app server protocol, if you are trying to send a silent pu
"custom_var_2:" "custom value here" /* Retrieved on app as data.additionalData.custom_var_2 */
},
/* Forces FCM silent push notifications to be triggered in the foreground of your iOS device. */
"content_available": true
"content_available": true
}
```
*Doc modification came in response to @andreszs - Issue [#2449](https://github.com/phonegap/phonegap-plugin-push/issues/2449).

** IMPORTANT: When using the content_available field, Android payload issues may occur. [Read here](../docs/PAYLOAD.md#user-content-use-of-content_available-true) Make sure you separate your Android/iOS server payloads to mitigate any problems that may arise.
** IMPORTANT: When using the content_available field, Android payload issues may occur. [Read here](../docs/PAYLOAD.md#user-content-use-of-content_available-true) Make sure you separate your Android/iOS server payloads to mitigate any problems that may arise.

More information on how to send push notifications using the FCM HTTP protocol and payload details can be found here:

Expand Down
13 changes: 11 additions & 2 deletions src/android/com/adobe/phonegap/push/FCMService.java
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,17 @@ private void setNotificationMessage(int notId, Bundle extras, NotificationCompat
NotificationCompat.InboxStyle notificationInbox = new NotificationCompat.InboxStyle()
.setBigContentTitle(fromHtml(extras.getString(TITLE))).setSummaryText(fromHtml(stacking));

for (int i = messageList.size() - 1; i >= 0; i--) {
notificationInbox.addLine(fromHtml(messageList.get(i)));
String order = extras.getString(INBOX_ORDER, ORDER_DESC);

if (ORDER_ASC.equals(order)) {
// Display last 4 messages.
for (int i = Math.max(0, messageList.size() - 4); i < messageList.size(); i++) {
notificationInbox.addLine(fromHtml(messageList.get(i)));
}
} else {
for (int i = messageList.size() - 1; i >= 0; i--) {
notificationInbox.addLine(fromHtml(messageList.get(i)));
}
}

mBuilder.setStyle(notificationInbox);
Expand Down
3 changes: 3 additions & 0 deletions src/android/com/adobe/phonegap/push/PushConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public interface PushConstants {
public static final String STYLE_INBOX = "inbox";
public static final String STYLE_PICTURE = "picture";
public static final String STYLE_TEXT = "text";
public static final String INBOX_ORDER = "inbox-order";
public static final String ORDER_ASC = "asc";
public static final String ORDER_DESC = "desc";
public static final String BADGE = "badge";
public static final String INITIALIZE = "init";
public static final String SUBSCRIBE = "subscribe";
Expand Down