react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

How to group remote push notification with same title and body?

Open archana-iron opened this issue 7 years ago • 2 comments

I am using FCM for push notification for my react native application. My app having live chat functionality. If someone sends a message to that person and at the same time users app is in background, then he will receive a new chat message notification.

Now I am getting a new notification when received a new message from anyone. It looks like this.

https://nimb.ws/ZI1w8k

I don't want a new notification every time, is this possible inside firebase to set a count with notification which having same title and description. Like for new notification, I have title:: You have a new message On every new message, I want a count and single notification, that You have 3 messages etc.

I am using React Native Firebase:5.2.3 . Please suggest If anyone having a solution?

archana-iron avatar Mar 27 '19 09:03 archana-iron

You can group notification by creating a master notification which will contain all local notifications

eg:

//create a master notification which will contain all the notification const groupNotificationId = "test"; const masterGroup = new firebase.notifications.Notification().android .setChannelId(message.data.channelId) .setNotificationId(groupNotificationId);

masterGroup.android .setGroup(groupNotificationId) .android.setGroupSummary(true) .android.setColor("#4D49FF") .android.setGroupAlertBehaviour( firebase.notifications.Android.GroupAlert.Children );

//now create a normal local notification const local = "localID" const newNotification = new firebase.notifications.Notification().android .setChannelId(message.data.channelId) .setNotificationId(local) .setTitle(message.data.authorName) .setBody(message.data.body) .android.setBigText(message.data.body) .setSound("default") .setData(message.Data) .android.setAutoCancel(true) .android.setGroup(groupNotificationId) .setData(message.data) .android.setColor("#4D49FF") .android.setGroupAlertBehaviour( firebase.notifications.Android.GroupAlert.Children ) .android.setPriority(firebase.notifications.Android.Priority.High);

// Build a channel const channelId = new firebase.notifications.Android.Channel( message.data.channelId, "channelName", firebase.notifications.Android.Importance.Max );

// Create the channel firebase.notifications().android.createChannel(channelId);

//Displaying notification firebase.notifications().displayNotification(masterGroup); firebase.notifications().displayNotification(newNotification);

sapdey avatar Mar 28 '19 20:03 sapdey

Please let us know if you're still having issues. I'll add this as a TODO for v6 docs.

Ehesp avatar Apr 20 '19 06:04 Ehesp