Prevent Push Notifications from showing

Hello everyone)

Please help with the following problem:

I’m making a chat application. To notify users about new messages, I use Expo.Notifications module. But how can I stop showing new push notifications for the user who has already opened the chat (already talking with another user)?

That is, the user who opened the chat does not need to see notifications that he has a new message, because he immediately sees the message.

I checked the source code of the Expo.Notifications module, but I did not understand how to prevent notifications to appear by some condition. There is a function called .addListener(), which argument is the event handler for the notification that recieved, but the problem is that this handler fires after the notification was alreay shown. So the user sees new notification every time.

I have a feeling that I do not understand some very simple concept… It would be great if someone will help)

My suggestion:

  • When the chat is openned: Stop registering to receive Push notification.
  • When the chat is closed: Start registering to receive Push notification again.
2 Likes

Thanks, that sounds like a solution. I didn’t thought about it. But may be exist some more elegant way? I wish someone from team working on SDK will reply to clarify this =)

Did you managed to solve this scenario?

1 Like

@bamne123 are you seeing this on iOS or Android? IIRC this is already the default behavior on iOS.

Android.