Prevent Push Notifications from showing


#1

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)


#2

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.

#3

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 =)


#4

Did you managed to solve this scenario?


#5

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


#6

Android.