0

I am using node.js for cloud computing the notifications but the problem is that all the notifications are shown separately but I want them to be shown together like Instagram or WhatsApp. For example, A sends 3 messages to B then these three should be grouped together rather then showing three times.

They are shown like this:- enter image description here

But I want them to be like this i.e one notification for all:- enter image description here

My Code:-

async function sendNotification(chatItem)
        {
            let body;
            
            switch (chatItem.type)
            {
                case 0:
                    body = `${chatItem.senderUsername}: ${chatItem.message}`;
                    break;

                case 1:
                    body = `${chatItem.senderUsername}: shared a photo`;
                    break;

                case 2:
                    body = `${chatItem.senderUsername}: sent you a sticker`;
                    break;

                case 3:
                    body = `${chatItem.senderUsername}: sent you a post`;
                    break;

                case 4:
                    body = `${chatItem.senderUsername}: sent you a profile`;
                    break;

                default:
                break;
            }
            const message =
            {
                notification: {
                                title:'Message',
                                body: body,
                                imageUrl: url,
                              },
                token: androidNotificationToken,
                data: { recipient: senderUserId },
            };

            admin.messaging().send(message)
            .then(response =>
            {
                console.log("Successfully sent message", response);
            })
            .catch(error =>
            {
                console.log("Error sending message", error);
            })

        }
lonewolf
  • 61
  • 6
  • You could use a dictionary to group all messages from the same user instead of sending them individually. This [video](https://youtu.be/fyqksNlC8ks?t=1241) explains this more indepth – mgoya Nov 20 '20 at 17:00
  • I believe this has to do with the way your client app handles the messages. I believe you should find this other SO answer useful https://stackoverflow.com/a/39715021/12163274 Let me know if this helps. – Jose V Dec 01 '20 at 13:36

0 Answers0