ConnectyCube / connectycube-reactnative-samples

Chat and Video Chat code samples for React Native, ConnectyCube
https://connectycube.com
Apache License 2.0
124 stars 111 forks source link

ConnectyCube Notifications not working properly #206

Closed dozsolti closed 3 years ago

dozsolti commented 3 years ago

Hi,

I've added notifications into my app and by following:

Everything looks to work fine, no crashes no error logs. Unfortunately when I send a notification from the dashboard it doesn't appear on my emulator, but if I send one from firebase it works fine. Local notifications also works as expected. It triggers the onNotification function from index.js but doesn't appear (neither in status bar nor as a little top-popup)

I think it will be an issue in my configurations because I've had to combine 3 or 4 documentations.

android/app/build.gradle image

android/build.gradle image

AndroidManifest.xml image

I've made a NotificationService which is initialized right after the user login is successfully. image image image

Also I've tried to:

Extra infos:

banshiAnton commented 3 years ago

Hi @dozsolti, problems only with notification wich is send from dashboard ? What about api create event ? (TestPush method in your code) And please check this log in Android studio "onMessageReceived" https://github.com/zo0r/react-native-push-notification/blob/1f462d8c669c7eaaa9f0f803b651b768d3855f03/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNReceivedMessageHandler.java#L123

dozsolti commented 3 years ago

Is the same

dozsolti commented 3 years ago

@banshiAnton I've get the notification from Android Studtio: V/RNPushNotification: onMessageReceived: Bundle[{data=Bundle[{message=test 24}]}]

banshiAnton commented 3 years ago

is application in foreground ? please check log in your onNotification method

dozsolti commented 3 years ago

no, the app is closed and as I already said the onNotification is triggered

banshiAnton commented 3 years ago

ok, you can create local notification in this method (onNotification) or try to set meta-data com.dieam.reactnativepushnotification.notification_foreground to true in AndroidManifest.xml (and rebuild)

dozsolti commented 3 years ago

I've tried to set it to true but is the same result

banshiAnton commented 3 years ago

you can create local notification using data from arguments onNotification

dozsolti commented 3 years ago

I have nothing against to receive a notification which is not shown and then showing it manually, if that will be the way. But that will be a workaround. A workaround of something that should work and can work because putting my credentials into the example app it works

banshiAnton commented 3 years ago

ok, please check this log in android studio "sendNotification" https://github.com/zo0r/react-native-push-notification/blob/036b194af7340fea01be1bd2de49dffb15fb6140/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNReceivedMessageHandler.java#L176

maybe error occurs when react-native-push-notification lib builds notification

dozsolti commented 3 years ago

@banshiAnton ok, so if I send a notification (with my TestPush function) it went to onNotification but not to "sendNotification" getting these in logs: image image

banshiAnton commented 3 years ago

if no "sendNotification" log probably both values (config.getNotificationForeground() and !isForeground) are quals false https://github.com/zo0r/react-native-push- notification/blob/master/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNReceivedMessageHandler.java#L179 please can you check it

show or not show notification it depend on react-native-push-notification lib logic, connectycube just send push message with data type, push message wich is sent from firebase console has notification type and it independ of react-native-push-notification lib logic

dozsolti commented 3 years ago

!isForeground will be false when I send it from TestPush because I have to have the app open to press the button that it sends it :))

If I send a notification from the dashboard the "sendNotification" is called: image image

banshiAnton commented 3 years ago

finally!

banshiAnton commented 3 years ago

i think some problems with in this method https://github.com/zo0r/react-native-push-notification/blob/1f462d8c669c7eaaa9f0f803b651b768d3855f03/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java#L201

can you add log here and check it https://github.com/zo0r/react-native-push-notification/blob/1f462d8c669c7eaaa9f0f803b651b768d3855f03/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java#L591

dozsolti commented 3 years ago

I think I found something, I'm getting: D/RNPushNotification: Ignore this message if you sent data-only notification. Cannot send to notification centre because there is no 'message' field in: Bundle[{userInteraction=false, id=2047034221, data=Bundle[{message=Test 27}], foreground=false}]

From: https://github.com/zo0r/react-native-push-notification/blob/1f462d8c669c7eaaa9f0f803b651b768d3855f03/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java#L211

I've sent no data, only: image

banshiAnton commented 3 years ago

i think you can create local notification in onNotification method or rewrite lib logic or use lib version like 3.1.9 (if it possible)

dozsolti commented 3 years ago

I won't rewrite the library's logic I would choose to not downgrade from 7.2.1 to 3.1.9 if it's not necessary

so I will try to create local notification, but for this I would have to call the PushNotification.configure function twice, (on in index.js for background and one in my PushNotification service to subscribe to ConnectyCube) It will be bad idea?

dozsolti commented 3 years ago

I found something strange: If I send a notification from ConnectyCube(dashboard) I've get the message in the data property. image

But if I make from local or firebase it doesn't goes to data image image

No wonder why the library says it doesn't contains a message

banshiAnton commented 3 years ago

Yes, but this is our logic and we can't change it Probably you can create local notification without call PushNotification.configure or create one service (wich use react-native-push-notification) and boot it in index.js

dozsolti commented 3 years ago

I need to call PushNotification.configure to have access to the onNotification callback. I've put this into index.js: image

and this into my NotificationService.js: image

It seems to work so far

banshiAnton commented 3 years ago

No activity for a long time. I think last solution works well

imsaurabhdixit commented 3 years ago

Hi @banshiAnton, I am already using the local notification inside onNotification method but I found a different behavior that this local notification didn't get fire until i send a notification using 'https://fcm.googleapis.com/fcm/send' api. And when i debug my app i found that PushNotification.getChannels returns blank array instead of channel id and when i push notification using 'https://fcm.googleapis.com/fcm/send' api than after i start getting channel id which i need to use in local notification.